mirror of https://gitee.com/karson/fastadmin.git
parent
6b01a13288
commit
8751d5f9bd
|
|
@ -90,7 +90,7 @@ class User extends Api
|
|||
//如果已经有账号则直接登录
|
||||
$ret = $this->auth->direct($user->id);
|
||||
} else {
|
||||
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
||||
$ret = $this->auth->register('', Random::alnum(16), '', $mobile, []);
|
||||
$this->auth->getUser()->save(['verification' => ['email' => 0, 'mobile' => 1]]);
|
||||
}
|
||||
if ($ret) {
|
||||
|
|
@ -132,6 +132,9 @@ class User extends Api
|
|||
if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
if (Validate::regex($username, '/^1\d{10}$/')) {
|
||||
$this->error(__('Username can not be mobile'));
|
||||
}
|
||||
$ret = Sms::check($mobile, $code, 'register');
|
||||
if (!$ret) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ return [
|
|||
'Username can not be empty' => '用户名不能为空',
|
||||
'Username must be 3 to 30 characters' => '用户名必须3-30个字符',
|
||||
'Username must be 6 to 30 characters' => '用户名必须6-30个字符',
|
||||
'Username can not be mobile' => '用户名不能使用手机号',
|
||||
'Password can not be empty' => '密码不能为空',
|
||||
'Password must be 6 to 30 characters' => '密码必须6-30个字符',
|
||||
'Mobile is incorrect' => '手机格式不正确',
|
||||
|
|
|
|||
|
|
@ -134,22 +134,28 @@ class Auth
|
|||
* @param array $extend 扩展参数
|
||||
* @return boolean
|
||||
*/
|
||||
public function register($username, $password, $email = '', $mobile = '', $extend = [])
|
||||
public function register($username = '', $password = '', $email = '', $mobile = '', $extend = [])
|
||||
{
|
||||
//账号注册时需要开启事务,避免出现垃圾数据
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 检测用户名、邮箱、手机号是否存在
|
||||
if ($username && User::checkExists('username', $username)) {
|
||||
$username = $username ?: Random::username();
|
||||
$password = $password ?: Random::alnum(16);
|
||||
$nickname = $extend['nickname'] ?? '用户' . mb_substr($mobile ?: strtoupper(Random::alnum(4)), -4);
|
||||
|
||||
// 检测用户名
|
||||
if (User::checkExists('username', $username)) {
|
||||
$this->setError('Username already exist');
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
// 检测邮箱
|
||||
if ($email && User::checkExists('email', $email)) {
|
||||
$this->setError('Email already exist');
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
// 检测手机号
|
||||
if ($mobile && User::checkExists('mobile', $mobile)) {
|
||||
$this->setError('Mobile already exist');
|
||||
Db::rollback();
|
||||
|
|
@ -169,7 +175,7 @@ class Auth
|
|||
'avatar' => '',
|
||||
];
|
||||
$params = array_merge($data, [
|
||||
'nickname' => preg_match("/^1[3-9]{1}\d{9}$/", $username) ? substr_replace($username, '****', 3, 4) : $username,
|
||||
'nickname' => $nickname,
|
||||
'salt' => Random::alnum(),
|
||||
'jointime' => $time,
|
||||
'joinip' => $ip,
|
||||
|
|
|
|||
|
|
@ -96,6 +96,9 @@ class User extends Frontend
|
|||
'email' => 'Email is incorrect',
|
||||
'mobile' => 'Mobile is incorrect',
|
||||
];
|
||||
if (Validate::regex($username, '/^1\d{10}$/')) {
|
||||
$this->error(__('Username can not be mobile'));
|
||||
}
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ return [
|
|||
'Username can not be empty' => '用户名不能为空',
|
||||
'Username must be 3 to 30 characters' => '用户名必须3-30个字符',
|
||||
'Username must be 6 to 30 characters' => '用户名必须6-30个字符',
|
||||
'Username can not be mobile' => '用户名不能使用手机号',
|
||||
'Account must be 3 to 50 characters' => '账户必须3-50个字符',
|
||||
'Password can not be empty' => '密码不能为空',
|
||||
'Password must be 6 to 30 characters' => '密码必须6-30个字符',
|
||||
|
|
|
|||
Loading…
Reference in New Issue