コード例 #1
0
ファイル: Phone.php プロジェクト: qnck/qingnianchuangke
 /**
  * send verification code
  * @author Kydz 2015-06-14
  * @return string code
  */
 public function sendVCode()
 {
     // chk if there is unused vcode
     $now = new DateTime();
     $now->modify('-1 mins');
     $chk = VerificationCode::where('verifiable_id', '=', $this->_mobile)->where('verifiable_type', '=', 'Phone')->where('created_at', '>', $now->format('Y-m-d H:i:s'))->count();
     if ($chk > 0) {
         throw new Exception("您的操作太频繁了, 请稍后再试", 1);
     }
     $code = new VerificationCode();
     $code->generateCode();
     $expire = new DateTime();
     $expire->modify('+5 mins');
     $code->expire_at = $expire->format('Y-m-d H:i:s');
     $code->v_reuse = 0;
     $code->verifiable_id = $this->_mobile;
     $code->verifiable_type = 'Phone';
     $txt = '您的验证码是' . $code->v_code . ',该验证码5分钟内有效。校园创业、购物、交友、找工作就上';
     $this->sendText($txt, TxtMessage::SEND_FAST);
     $code->save();
     return $code->v_code;
 }
コード例 #2
0
 /**
  * resend confirmation email 
  * @param string $email
  * @return int
  */
 public function resend($email)
 {
     if (empty($email)) {
         return array(false, self::ERROR_INVALID_EMAIL_OR_PSWD);
     }
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return array(false, self::ERROR_INVALID_EMAIL_OR_PSWD);
     }
     $user = new User($this->db, $this->logger);
     if (!$user->getByEmail($email)) {
         return array(false, self::ERROR_DOES_NOT_EXIST);
     }
     if ($user->status != User::STATUS_UNVERIFIED) {
         return self::ERROR_ALREADY_VERIFIED;
     }
     $vcode = new VerificationCode($this->db, $this->logger);
     if (!$vcode->getByUserId($user->id)) {
         return array(false, self::ERROR_DOES_NOT_EXIST);
     }
     // update the code and send it
     $vcode->code = bin2hex(openssl_random_pseudo_bytes(32));
     if ($vcode->save()) {
         return array(false, self::ERROR_INTERNAL_ERROR);
     }
     $this->sendVerificationEmail($user->id, $email, $vcode->code, $email);
     return array(true, $vcode->code);
 }