/**
  * Activate
  *
  * <b>Request Type </b>: GET<br/>
  * <b>Request Endpoint </b>: http://{server-domain}/api/old-site/activate?code=abcd1234abcd1234<br/>
  *
  **/
 public function actionActivate()
 {
     $code = $this->getQuery('code');
     if (empty($code)) {
         $this->_activateFail(0);
         //此链接无效,请联系管理员
     }
     $validation = Validation::findOne(['code' => $code]);
     if (empty($validation)) {
         $this->_activateFail(0);
         //此链接无效,请联系管理员
     }
     if (empty($validation->expire) || MongodbUtil::isExpired($validation->expire)) {
         $this->_activateFail(1);
         //'此链接已过期,请联系管理员'
     }
     $userId = $validation->userId;
     if (User::updateAll(['isActivated' => User::ACTIVATED], ['_id' => $userId])) {
         $validation->delete();
         $this->redirect('/old/activate?type=0&link=' . urlencode('/site/login'));
         Yii::$app->end();
     }
     $this->_activateFail(1);
     //'此链接已过期,请联系管理员'
 }
示例#2
0
 /**
  * Validate code when activate user
  * @param $code, String.
  * @return String, error code or userId
  *
  * @author Sara Zhang
  */
 public static function validateCode($code, $isDeleted = true)
 {
     if (empty($code)) {
         return self::LINK_INVALID;
     }
     $validation = Validation::findOne(['code' => $code]);
     if (empty($validation)) {
         return self::LINK_INVALID;
     }
     if (empty($validation->expire) || MongodbUtil::isExpired($validation->expire)) {
         return self::LINK_EXPIRED;
     }
     $userId = $validation->userId;
     if ($validation->toValidateAccount) {
         $user = User::findOne(['_id' => $userId]);
         $attributes = ['status' => Account::STATUS_ACTIVATED, 'trialStartAt' => new \MongoDate(), 'trialEndAt' => new \MongoDate(strtotime("+30 day"))];
         Account::updateAll($attributes, ['_id' => $user->accountId]);
     }
     if ($isDeleted) {
         $validation->delete();
     }
     return $userId;
 }