Accessing login controller via single page
Permalink
First off, concrete5 rocks. Great job and thanks for developing it!
Question: I have my own custom login form embedded within a page that I would like to use. The issue I'm having is that i'm finding it impossible to call the do_login function within the login.php controller upon submit.
method 1) If i place this the page gets redirected to the login/do_login path for validation and this is NOT what I want. I would like to display error messages etc.. back to the same form I'm submitting from.
method 2) This doesn't execute.
I've placed a print statement(123 test etc..) within the do_login function as a test to ensure it is getting ran but it isn't. If I use the first method above the statement prints, but it prints on the default login page. Again, I don't want to be redirected to that page for validation. The statement does not return to my custom page if I use method #2. I thought method #2 would be able to call do_login as long as the page had access to the controller?? So really, I want to bypass the actual login form. I don't need it. I just need to access the controller functions. I never want to see it.
Also, I have placed/copied the login.php file(s) into the appropriate directories (single_pages, controller) for my theme. I have no issue manipulating the controller or the layout so I believe they are in the correct location. I'm betting this is something simple i'm overlooking due to being new with c5.
i hope this makes sense. its late. I need a bowl of cereal and a nap.
Question: I have my own custom login form embedded within a page that I would like to use. The issue I'm having is that i'm finding it impossible to call the do_login function within the login.php controller upon submit.
method 1) If i place this
action="<?php echo $this->url('/login', 'do_login')?>
method 2) This
action="<?php echo $this->action('do_login')?>"
I've placed a print statement(123 test etc..) within the do_login function as a test to ensure it is getting ran but it isn't. If I use the first method above the statement prints, but it prints on the default login page. Again, I don't want to be redirected to that page for validation. The statement does not return to my custom page if I use method #2. I thought method #2 would be able to call do_login as long as the page had access to the controller?? So really, I want to bypass the actual login form. I don't need it. I just need to access the controller functions. I never want to see it.
Also, I have placed/copied the login.php file(s) into the appropriate directories (single_pages, controller) for my theme. I have no issue manipulating the controller or the layout so I believe they are in the correct location. I'm betting this is something simple i'm overlooking due to being new with c5.
i hope this makes sense. its late. I need a bowl of cereal and a nap.
You're right on target about how example #2 should work. Is there no do_login() method in your custom page's controller? Is there perhaps a mixup in where your controller file is located – in the wrong spot of the controllers/ directory? Is it named incorrectly ?
if you need to call the functions in the controller, you can do;
Loader::controller('/login');
$nlc = new LoginController();
$nlc->set('_POST',$postArrayFakedPassedOn);
$nlc->do_login();
see if that does anything. Otherwise you'll have to modify do_login to accept an array like
do_login($arr = ""){
if(is_array($arr)) $_POST = $arr;
then the function should continue like it was actually posted to.
Loader::controller('/login');
$nlc = new LoginController();
$nlc->set('_POST',$postArrayFakedPassedOn);
$nlc->do_login();
see if that does anything. Otherwise you'll have to modify do_login to accept an array like
do_login($arr = ""){
if(is_array($arr)) $_POST = $arr;
then the function should continue like it was actually posted to.
Hey gents, thanks for the help. I've managed to get access to the do_login function now via ScottC's example. I'm able to echo out the form data as:
within the function so it appears that I'm getting the data as well.
However another issue has arose and that is the fact I'm getting this error message:
"Fatal error: Call to a member function add() on a non-object ...."
The line the error is referencing is this:
Apparently it is not digging the add function for some reason. Any help would be greatly appreciated.
echo $this->post('uName');
However another issue has arose and that is the fact I'm getting this error message:
"Fatal error: Call to a member function add() on a non-object ...."
The line the error is referencing is this:
$this->error->add($e);
Apparently it is not digging the add function for some reason. Any help would be greatly appreciated.
Ok, I believe I've got this figured out.
Within on_start() of the LoginController class
was not getting set.
So I added this line of code
on my calling page and the error is gone.
So this is what I have incase someone else is looking to do the same thing:
I've copied the following files:
/concrete/controllers/login.php
/concrete/single_pages/login.php
to
/controllers/login.php
/single_pages/login.php
Within the calling page where I have my embedded sign in form:
And within the form:
so it submits to itself.
Hope this helps someone else.
Thanks again guys!
Within on_start() of the LoginController class
$this->error = Loader::helper('validation/error');
was not getting set.
So I added this line of code
$nlc->error = Loader::helper('validation/error');
on my calling page and the error is gone.
So this is what I have incase someone else is looking to do the same thing:
I've copied the following files:
/concrete/controllers/login.php
/concrete/single_pages/login.php
to
/controllers/login.php
/single_pages/login.php
Within the calling page where I have my embedded sign in form:
if(isset($_POST['uName'])){ $nlc = new LoginController(); $nlc->error = Loader::helper('validation/error'); $nlc->do_login();
And within the form:
action="<?php echo $this->action('')?>
so it submits to itself.
Hope this helps someone else.
Thanks again guys!