/** * 用户注册 * @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; }
/** * 修改用户邮箱 * @param User $user * @param string $email * @param string $password * @param string $code * @throws \Exception */ public function edit_email($user, $email, $password, $code) { lib()->load('UserCheck'); $email = strtolower(trim($email)); $code = strtolower(trim($code)); if ($user->getPassword() !== UserCheck::CreatePassword($password, $user->getSalt())) { $this->throwMsg(-10); } $email_check = UserCheck::CheckEmail($email); if ($email_check !== true) { throw new \Exception($email_check); } $meta = $user->getMeta()->get(['edit_email_add', 'edit_email_time', 'edit_email_code'], ''); if ($meta['edit_email_add'] !== $email) { $this->throwMsg(-13); } if ($meta['edit_email_code'] !== $code) { $this->throwMsg(-12); } if (time() - strtotime($meta['edit_email_time']) > hook()->apply('UserControl_edit_email_time', 3 * 24 * 60 * 60)) { $this->throwMsg(-11); } $user->getMeta()->delete(['edit_email_add', 'edit_email_time', 'edit_email_code']); $user->set(['email' => $email]); }
/** * 邮箱存在性检测 * @param $email */ public function email_check($email = NULL) { lib()->load('UserCheck'); $this->rt_msg['status'] = UserCheck::CheckEmail($email) === true; }