cakePHP, Ajax, Login Form

Login works, but I'm trying to redirect the view to a welcome page

Page 1 of 1

3 Replies - 8151 Views - Last Post: 11 November 2009 - 05:29 AM Rate Topic: -----

#1 young.steveo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 37
  • Joined: 14-May 09

cakePHP, Ajax, Login Form

Post icon  Posted 08 September 2009 - 07:16 PM

I have a form that I am suppressing with jQuery and doing an AJAX call to a controller 'UsersController' with a 'login' action that is working automagically using the built in Auth component.

The homepage has a copy of the form inside a div, and the the 'users/login.ctp' view has a copy of the form. When the user submits the form, jQuery removes the homepage form from the div. The form is submitted via ajax to the UsersController, and if the user has failed to authenticate, he is served the 'users/login.ctp' view inside the same div using ajax. This all works.

If the user DOES authenticate, he is also served the login.ctp. Instead, I want to change the view to something that says "welcome, etc. etc. etc."

I've bashed my brains into the cookbook documentation and google to no avail. I feel like this is something super easy to do, but I'm barking up the wrong trees.

Is This A Good Question/Topic? 0
  • +

Replies To: cakePHP, Ajax, Login Form

#2 paperclipmuffin  Icon User is offline

  • Disassembling...
  • member icon

Reputation: 13
  • View blog
  • Posts: 944
  • Joined: 16-April 09

Re: cakePHP, Ajax, Login Form

Posted 09 September 2009 - 01:30 AM

I would suggest something more like

<?php
if(auth == true){
	http_redirect("welcome.ctp");
}
if(auth == false){
	http_redirect("users/login.ctp");
}
?>




Hope that works out for you! :)
Was This Post Helpful? 0
  • +
  • -

#3 young.steveo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 37
  • Joined: 14-May 09

Re: cakePHP, Ajax, Login Form

Posted 13 September 2009 - 10:12 AM

LOL! Okay... Thanks for the reply. I tried doing exactly that at one point in my quest to make this work, and it did not seem to do the trick.

It did not SEEM to do the trick, but it actually WAS working! I didn't realize that my ajax script was properly sending a request and getting the response that I wanted, but it was not written to DISPLAY the response!

The div with the original form is faded out, the request is sent and received, and the original form was fading back in instead of the response. Since the "invalid-login" response form was styled identically to the original form, well... you get the idea.

Sometimes we're dumb.
Was This Post Helpful? 0
  • +
  • -

#4 pctotalsantafe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-November 09

Re: cakePHP, Ajax, Login Form

Posted 11 November 2009 - 05:29 AM

Is exactly what i want to do. You could copy and paste example code to see how you do it please?
Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1