I am building a custom login process which follow these steps:
- Request user email (submits to custom controller)
- Check if user has an account
- If they have an account, show a form requesting their password. Or if they don't have an account then send them to the registration form.
The forms exist as front end templates.
I can accomplish all these steps but when the user is redirected I need to make the email address that they entered available to the template.
My custom controller calls a service to check if the user exists which is all fine. And I can redirect the user to the appropriate URL. But I can't figure out how to retain the email address they entered.
Currently I've just done it by appending the email as a query string but this is undesirable for a couple of reasons.
The controller currently looks like this although I feel this is totally the wrong way to be doing things.
public function actionEmailCheck() {
$this->requirePostRequest();
$email = Craft::$app->request->post('loginName');
$result = MyModule::$instance->order->checkEmail($email);
if($result) {
$redirect = '/login/password?email='.$email;
} else {
$redirect = '/register?email='.$email;
}
$this->redirect($redirect);
}
I feel like I should be able to set some template variables and load the appropriate template but that doesn't seem to work.
I also tried this
if($result) {
$this->renderTemplate('/login/password', array('email'=>$email));
} else {
$this->renderTemplate('/register', array('email'=>$email));
}
But while the template was displayed, I couldn't access the value for 'email'.
So how should I approach this?