mirror of https://gitee.com/karson/fastadmin.git
parent
4e48b3a736
commit
211a54b4c3
|
|
@ -133,21 +133,23 @@ class Auth
|
|||
*/
|
||||
public function register($username, $password, $email = '', $mobile = '', $extend = [])
|
||||
{
|
||||
// 检测用户名、昵称、邮箱、手机号是否存在
|
||||
if (User::getByUsername($username)) {
|
||||
//账号注册时需要开启事务,避免出现垃圾数据
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 检测用户名、邮箱、手机号是否存在
|
||||
if ($username && User::checkExists('username', $username)) {
|
||||
$this->setError('Username already exist');
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
if (User::getByNickname($username)) {
|
||||
$this->setError('Nickname already exist');
|
||||
return false;
|
||||
}
|
||||
if ($email && User::getByEmail($email)) {
|
||||
if ($email && User::checkExists('email', $email)) {
|
||||
$this->setError('Email already exist');
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
if ($mobile && User::getByMobile($mobile)) {
|
||||
if ($mobile && User::checkExists('mobile', $mobile)) {
|
||||
$this->setError('Mobile already exist');
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -176,9 +178,6 @@ class Auth
|
|||
$params['password'] = $this->getEncryptPassword($password, $params['salt']);
|
||||
$params = array_merge($params, $extend);
|
||||
|
||||
//账号注册时需要开启事务,避免出现垃圾数据
|
||||
Db::startTrans();
|
||||
try {
|
||||
$user = User::create($params, true);
|
||||
|
||||
$this->_user = User::get($user->id);
|
||||
|
|
|
|||
|
|
@ -82,6 +82,16 @@ class User extends Model
|
|||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定字段的值是否存在
|
||||
* @param string $field 字段名
|
||||
* @param string $value 字段值
|
||||
*/
|
||||
public static function checkExists($field, $value)
|
||||
{
|
||||
return self::lock(true)->where($field, $value)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 变更会员余额
|
||||
* @param int $money 余额
|
||||
|
|
|
|||
|
|
@ -224,9 +224,9 @@ class User extends Frontend
|
|||
//如果已经有账号则直接登录
|
||||
$ret = $this->auth->direct($user->id);
|
||||
} else {
|
||||
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
||||
//如果是手机号首次注册则直接设定为已验证
|
||||
$this->auth->getUser()->save(['verification' => ['email' => 0, 'mobile' => 1]]);
|
||||
$username = \fast\Random::username();
|
||||
$nickname = '用户' . substr($mobile, -4);
|
||||
$ret = $this->auth->register($username, Random::alnum(), '', $mobile, ['nickname' => $nickname, 'verification' => ['mobile' => 1]]);
|
||||
}
|
||||
if ($ret) {
|
||||
Sms::flush($mobile, 'mobilelogin');
|
||||
|
|
@ -321,6 +321,9 @@ class User extends Frontend
|
|||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件管理
|
||||
*/
|
||||
public function attachment()
|
||||
{
|
||||
//设置过滤方法
|
||||
|
|
@ -388,6 +391,9 @@ class User extends Frontend
|
|||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户协议
|
||||
*/
|
||||
public function agreement()
|
||||
{
|
||||
$this->view->assign('title', __('User agreement'));
|
||||
|
|
|
|||
|
|
@ -89,6 +89,15 @@ class Random
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机用户名
|
||||
* @return string
|
||||
*/
|
||||
public static function username(): string
|
||||
{
|
||||
return 'user_'.bin2hex(random_bytes(8)) . substr(uniqid(), -8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全球唯一标识
|
||||
* @return string
|
||||
|
|
|
|||
Loading…
Reference in New Issue