I'm using yii2-user for user registration. I want to check whether the user is registered on not before logging in from social account(s). I'm triggering event before creating his account and handling it in the main.php
globally.
If user is already registered, I want to display some message and not let him continue with registration/login process thereafter.
In short I want the user to get redirected to home page, displaying the message from the event handler if the specified condition is matched.
'modules' => [
'user' => [
'class' => 'dektrium\user\Module',
'enableRegistration' => true,
'controllerMap' => [
'security' => [
'class' => \dektrium\user\controllers\SecurityController::className(),
'on ' . \dektrium\user\controllers\SecurityController::EVENT_BEFORE_CREATE_ACCOUNT => function ($e) {
$email = $e->client->email;
$user_model = \dektrium\user\models\User::findOne(['email' => $email]);
if($user_model == Null)
{
return; //then just return and continue next steps
}
Yii::$app->session->setFlash('info', "You cannot directly login with this account. Please login with the credentials sent to your email ($email) first and then connect your Account from Settings.");
//---------- NOW REDIRECT TO HOME PAGE--------
}
],
],
],
],
What's the best way to redirect user to home page and stopping execution of current controller?