示例#1
0
 public function validateOTP()
 {
     if (!$this->hasErrors('otp')) {
         $this->otpModel = OTP::find()->where(['otp' => $this->otp])->one();
         if ($this->otpModel == null) {
             $this->addError("otp", "Invalid OTP");
             return;
         }
         if (!$this->isOtpValid()) {
             $this->addError("otp", "OTP Expired");
         }
     }
 }
示例#2
0
 public static function findUserByOTP($username, $otp)
 {
     $user = User::find()->where(['username' => $username])->one();
     if ($user == null) {
         return null;
     }
     $otpModel = OTP::find()->where(['otp' => $otp])->one();
     if ($otpModel == null) {
         throw new UnauthorizedHttpException("Invalid OTP");
     }
     $createdTime = \DateTime::createFromFormat('Y-m-d H:i:s', $otpModel->created_on);
     $created = $createdTime->getTimestamp();
     $now = time();
     if ($now > $created + 30) {
         throw new UnauthorizedHttpException("OTP Expired");
     }
     return new static($user->toArray());
 }