示例#1
0
 /**
  * @param User   $user
  * @param string $code
  * @throws \Exception
  * @return int 返回用户状态码
  */
 public static function UserActivation($user, $code)
 {
     if ($user->is_active()) {
         throw new \Exception(_("User is already activation"));
     }
     $meta = $user->getMeta()->get(["activation_code", "activation_time"], '');
     if (empty($meta['activation_time']) || empty($meta['activation_code'])) {
         throw new \Exception(_("Activation code is invalid"));
     }
     if (time() - strtotime($meta['activation_time']) > hook()->apply('UserRegister_UserActivation_time', 3 * 24 * 60 * 60)) {
         throw new \Exception(_("Activation code is time out"));
     }
     if ($meta['activation_code'] != $code) {
         throw new \Exception(_("Activation code is error"));
     } else {
         $user->set(['status' => 1]);
     }
     return $user->getStatus();
 }