Welcome Guest, Not a member yet? Register   Sign In
Ajax login not working for community auth
#1

hi,
My ajax login form in the examples controller does not work when i try to log in. Anytime i attempt logging in i get a 404 page saying The page you requested was not found.
Am using wamp on a 64-bit machine and i have installed the latest version of community auth as well as CI 3.1.2.
Thanks
Reply
#2

It is possible that your ajax HTTP request is not be detected by CodeIgniter as a legitimate ajax request. If you look at the ajax_attempt_login method in the examples controller, you will see that it is checking for ajax only:


PHP Code:
if( $this->input->is_ajax_request() ) 

Try replacing that with:


PHP Code:
if( == 

If that works, your browser is just not including the header that CI uses to determine if an ajax request is happening. Remember, Community Auth examples are just examples, not code to build your entire app from.
Reply
#3

(01-10-2017, 01:55 PM)skunkbad Wrote: It is possible that your ajax HTTP request is not be detected by CodeIgniter as a legitimate ajax request. If you look at the ajax_attempt_login method in the examples controller, you will see that it is checking for ajax only:


PHP Code:
if( $this->input->is_ajax_request() ) 

Try replacing that with:


PHP Code:
if( == 

If that works, your browser is just not including the header that CI uses to determine if an ajax request is happening. Remember, Community Auth examples are just examples, not code to build your entire app from.

i did what you suggested and it still doesn't work. Only that this time the form does not submit and when i open the console to see whats happening there i see this;Failed to load resource: the server responded with a status of 404 (Not Found)..
I understand that community auth examples are just examples and i have not or do not intend to use it in my entire project. Its just that the examples are some sort of guidelines on how to go about certain scenarios such is in the case of the ajax example. That being said can you please suggest another way of handling ajax login using community auth. Perhaps i should use a javascript file or form to submit to my php method??? Your help will be much appreciated. Thanks
Reply
#4

The problem isn't Community Auth, so it's impossible for me to suggest how to make it work. If this is a new install with no extra code, then perhaps you need to check that all installation steps were done, and that you've configured CodeIgniter correctly. Everytime something like this comes up, I try to help, and in the end the person with the problem was just making a mistake. I don't mind looking at your configuration, but I think you should first attempt to do a little debugging. Verify the install is complete and no steps were skipped. If something wasn't clear or you aren't sure about one of the installation steps, let me know.
Reply
#5

(01-10-2017, 03:50 PM)skunkbad Wrote: The problem isn't Community Auth, so it's impossible for me to suggest how to make it work. If this is a new install with no extra code, then perhaps you need to check that all installation steps were done, and that you've configured CodeIgniter correctly. Everytime something like this comes up, I try to help, and in the end the person with the problem was just making a mistake. I don't mind looking at your configuration, but I think you should first attempt to do a little debugging. Verify the install is complete and no steps were skipped. If something wasn't clear or you aren't sure about one of the installation steps, let me know.

Thanks a lot for the insight and i don't think the problem is from Community Auth. I don't seem to see any errors with my installation either so i would like to try another way of achieving the ajax login. Am looking at handling form validation on the client side using js, submitting via ajax and getting the json response and displaying if any error or if without errors , then i log the user in. Your insight will be very much appreciated.
Reply
#6

(01-11-2017, 09:33 AM)koficypher Wrote:
(01-10-2017, 03:50 PM)skunkbad Wrote: The problem isn't Community Auth, so it's impossible for me to suggest how to make it work. If this is a new install with no extra code, then perhaps you need to check that all installation steps were done, and that you've configured CodeIgniter correctly. Everytime something like this comes up, I try to help, and in the end the person with the problem was just making a mistake. I don't mind looking at your configuration, but I think you should first attempt to do a little debugging. Verify the install is complete and no steps were skipped. If something wasn't clear or you aren't sure about one of the installation steps, let me know.

Thanks a lot for the insight and i don't think the problem is from Community Auth. I don't seem to see any errors with my installation either so i would like to try another way of achieving the ajax login. Am looking at handling form validation on the client side using js, submitting via ajax and getting the json response and displaying if any error or if without errors , then i log the user in. Your insight will be very much appreciated.

1) You should never rely on client side validation, especially for a login. It's too easy to bypass.

2) The ajax login example is already doing everything you have said you want to do. Perhaps you can zip up your website, add in a database dump, and let me figure out how you went wrong. You'd have to make it available as a download, but I'm willing to check it out if you can make it happen.
Reply
#7

(01-11-2017, 09:56 AM)skunkbad Wrote:
(01-11-2017, 09:33 AM)koficypher Wrote:
(01-10-2017, 03:50 PM)skunkbad Wrote: The problem isn't Community Auth, so it's impossible for me to suggest how to make it work. If this is a new install with no extra code, then perhaps you need to check that all installation steps were done, and that you've configured CodeIgniter correctly. Everytime something like this comes up, I try to help, and in the end the person with the problem was just making a mistake. I don't mind looking at your configuration, but I think you should first attempt to do a little debugging. Verify the install is complete and no steps were skipped. If something wasn't clear or you aren't sure about one of the installation steps, let me know.

Thanks a lot for the insight and i don't think the problem is from Community Auth. I don't seem to see any errors with my installation either so i would like to try another way of achieving the ajax login. Am looking at handling form validation on the client side using js, submitting via ajax and getting the json response and displaying if any error or if without errors , then i log the user in. Your insight will be very much appreciated.

1) You should never rely on client side validation, especially for a login. It's too easy to bypass.

2) The ajax login example is already doing everything you have said you want to do. Perhaps you can zip up your website, add in a database dump, and let me figure out how you went wrong. You'd have to make it available as a download, but I'm willing to check it out if you can make it happen.
Thanks for the advice. Ill stick to that. I have also sent you a link to download my site privately. Thanks for your help.
Reply
#8

OK, so in order to make it work properly, here is what I did:

1) Changed the auth level of the user "skunkbot" to 9 in the database.

2) In routes.php, changed login route to:


Code:
  $route[LOGIN_PAGE] = 'examples/login';



3) Your .htaccess was different than what I'd normally use, so I just used mine:


Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]


Works for me.
Reply
#9

(This post was last modified: 01-27-2017, 07:19 AM by koficypher.)

(01-12-2017, 01:33 PM)skunkbad Wrote: OK, so in order to make it work properly, here is what I did:

1) Changed the auth level of the user "skunkbot" to 9 in the database.

2) In routes.php, changed login route to:


Code:
  $route[LOGIN_PAGE] = 'examples/login';



3) Your .htaccess was different than what I'd normally use, so I just used mine:


Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]


Works for me.

Ohk so before i say anything i'd like to say than you for taking time to go through my code. But i still have the same issue only that this time i found something. anytime i open up my console to see whats happening when i press the submit button, i see that this;
NB: I moved to a cloud editor to test the issue and i have a directory in the container like this;

-test
--application
--assests
--system

Code:
jquery-1.12.0.min.js:4 POST http://mycontainer-*****************.codeanyapp.com/examples/ajax_attempt_login 404 (Not Found)  

From that you could see that the post request omitted the directory test. And also your .htaccess doesn't allow me to override index.php.
Any idea what could possibly be the issue here?
Reply
#10

Do remember that if you need to have a login URL that is not the default URL, then you need to add it to the list of allowable URLs. This is a Community Auth config setting.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB