-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from katmastt/main
email verification implementation
- Loading branch information
Showing
9 changed files
with
475 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace app\components; | ||
|
||
use app\models\EmailVerificationRequest; | ||
use webvimark\modules\UserManagement\models\User; | ||
use Yii; | ||
use yii\base\ActionFilter; | ||
|
||
class EmailVerifiedFilter extends ActionFilter { | ||
|
||
public function beforeAction($action) { | ||
// 1. Get current user | ||
$currentUser = User::getCurrentUser(); | ||
|
||
// 2. Check whether the user is authenticated. If the current user is a guest, then move on | ||
if (!$currentUser) return parent::beforeAction($action); | ||
// 3. Check if the user has already a pending email verification request | ||
$email_request=EmailVerificationRequest::find()->where(['user_id'=>$currentUser->id, 'status'=>0])->andwhere(['>', 'expiry', date('c')])->orderBy('created_at DESC')->one(); | ||
// if the user has no valid pending email verification request && his email is not set or confirmed | ||
// redirect him to enter his email | ||
if (empty($email_request) && (trim($currentUser->email)=="" || !$currentUser->email_confirmed)) { | ||
return $this->owner->redirect(['personal/email-verification'])->send(); | ||
// if the user has a valid (not expired) pending request | ||
// inform him that a verification email has been sent to his address | ||
} elseif (!empty($email_request)) { | ||
return $this->owner->redirect(['personal/email-verification-sent','email'=>$email_request->email, 'resend'=>0])->send(); | ||
} | ||
return parent::beforeAction($action); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.