Ejemplo n.º 1
0
 /**
  * 用户注册
  * @param $email     string 邮箱
  * @param $password  string   hash密码
  * @param $name      string 用户名
  * @param $captcha   string 验证码
  * @return int    错误代码或者用户成功注册ID
  */
 public function Register($email, $password, $name, $captcha)
 {
     $email = strtolower(trim($email));
     $password = strtolower(trim($password));
     $name = strtolower(trim($name));
     $captcha = trim($captcha);
     if (($code = hook()->apply("UserRegister_Register_before", 0, $email, $password, $name, $captcha)) < 0) {
         return $code;
     }
     if (!$this->Captcha($captcha)) {
         return -1;
     }
     if (!UserCheck::CheckPassword($password)) {
         return -2;
     }
     if (UserCheck::CheckName($name) !== true) {
         return -4;
     }
     if (UserCheck::CheckEmail($email) !== true) {
         return -5;
     }
     $ip = new Ip();
     $register_array = ['user_name' => $name, 'user_email' => $email, 'user_aliases' => $name, 'user_password' => '', 'user_salt' => salt(64), 'user_registered_time' => date("Y-m-d H:i:s"), 'user_registered_ip' => $ip->ip2bin($ip->realip()), 'user_cookie_salt' => salt(64), 'user_avatar' => UserCheck::DefaultAvatar(), 'user_status' => 0];
     $register_array['user_password'] = UserCheck::CreatePassword($password, $register_array['user_salt']);
     $reg_code = db()->insert("users", $register_array);
     if ($reg_code <= 0) {
         Log::write(_("User register insert sql error."), Log::SQL);
         return -3;
     }
     try {
         //关于注册成功的提醒
         hook()->apply("UserRegister_Register_success", $reg_code, $register_array);
         if (hook()->apply("UserRegister_Register_success_send_mail", true)) {
             //判断是否注册过程中需要发送注册邮件
             $u = new User($reg_code);
             $this->SendActivationMail($u);
         }
     } catch (\Exception $ex) {
         Log::write(_("User register success exception notice"), Log::NOTICE);
     }
     return $reg_code;
 }
Ejemplo n.º 2
0
 /**
  * 设置最后登录信息
  * @param User $user
  * @throws \Exception
  */
 public static function setLastLoginInfo($user)
 {
     cookie()->set("LoginFlag", date("Y-m-d"));
     $user->set(array('last_login_ip' => Ip::getInstance()->realip(), 'last_login_time' => date("Y-m-d H:i:s")));
 }
Ejemplo n.º 3
0
 /**
  * 构造方法,使用评论的信息和对应的用户类
  * @param array $set_info
  * @param int   $user_id
  */
 function __construct($set_info, $user_id)
 {
     $this->ip_c = Ip::getInstance();
     $this->user = User::getUser($user_id);
     if (is_array($set_info) && isset($set_info['comment_id'])) {
         static $names = [];
         if (count($names) === 0) {
             $ref = new \ReflectionClass($this);
             foreach ($ref->getProperties() as $ro) {
                 $names[] = $ro->getName();
             }
             $names = array_flip($names);
             unset($names['ip_c'], $names['user'], $names['sub_node']);
         }
         if (isset($set_info['comment_ip'])) {
             $set_info['comment_ip'] = $this->ip_c->bin2ip($set_info['comment_ip']);
         }
         foreach ($set_info as $k => $v) {
             if (isset($names[$k])) {
                 $this->{$k} = $v;
             }
         }
         self::$comment_stack[$this->getCommentId()] = $this;
     } else {
         Log::write(_("Comment class construct error"), Log::ALERT);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param $list array
  * @throws \Exception
  */
 public function set($list)
 {
     $data = [];
     $update = [];
     foreach ($list as $name => $value) {
         $name = trim($name);
         if ($name !== 'id' && in_array($name, self::$column_list)) {
             $data[$name] = $value;
             $update["user_" . $name] = $value;
             if (substr($name, -3) === '_ip') {
                 $update["user_" . $name] = Ip::getInstance()->ip2bin($value);
             }
         }
     }
     lib()->load('UserCheck');
     if (isset($update['user_aliases']) && empty($update['user_aliases'])) {
         throw new \Exception(_("Aliases can't set empty."));
     }
     if (isset($update['user_email']) && !UserCheck::CheckEmailChar($update['user_email'])) {
         throw new \Exception(_("Email verify check Error"));
     }
     if (isset($update['user_name']) && !UserCheck::CheckUsernameChar($update['user_name'])) {
         throw new \Exception(_("Username verify check Error"));
     }
     if (isset($update['user_password']) && !UserCheck::CheckPasswordChar($update['user_password'])) {
         throw new \Exception(_("Password verify check Error"));
     }
     if (isset($update['user_url']) && $update['user_url'] != "" && !filter_var($update['user_url'], FILTER_VALIDATE_URL)) {
         throw new \Exception(_("Url check error"));
     }
     if (count($update) > 0) {
         if (db()->update("users", $update, ['id' => $this->id]) === false) {
             throw new \Exception(_("Can't update User info.") . debug("SQL msg:" . implode(",", db()->error()['write'])));
         }
         foreach ($data as $n => $v) {
             $this->{$n} = $v;
         }
     }
 }