后台登录框和验证码高度设置为40px

api的Ems,Sms,Validate多语言
pull/450/head
aa820t 2023-07-30 01:17:41 +08:00
parent 3831955b9b
commit 170850efef
7 changed files with 74 additions and 40 deletions

View File

@ -73,6 +73,7 @@
#login-form .form-control { #login-form .form-control {
font-size: 13px; font-size: 13px;
height: 40px;
} }
</style> </style>
@ -117,7 +118,7 @@
<div class="input-group-addon"><span class="glyphicon glyphicon-option-horizontal" aria-hidden="true"></span></div> <div class="input-group-addon"><span class="glyphicon glyphicon-option-horizontal" aria-hidden="true"></span></div>
<input type="text" name="captcha" class="form-control" placeholder="{:__('Captcha')}" data-rule="{:__('Captcha')}:required;length({$Think.config.captcha.length})" autocomplete="off"/> <input type="text" name="captcha" class="form-control" placeholder="{:__('Captcha')}" data-rule="{:__('Captcha')}:required;length({$Think.config.captcha.length})" autocomplete="off"/>
<span class="input-group-addon" style="padding:0;border:none;cursor:pointer;"> <span class="input-group-addon" style="padding:0;border:none;cursor:pointer;">
<img src="{:rtrim('__PUBLIC__', '/')}/index.php?s=/captcha" width="100" height="30" onclick="this.src = '{:rtrim('__PUBLIC__', '/')}/index.php?s=/captcha&r=' + Math.random();"/> <img src="{:rtrim('__PUBLIC__', '/')}/index.php?s=/captcha" width="100" height="40" onclick="this.src = '{:rtrim('__PUBLIC__', '/')}/index.php?s=/captcha&r=' + Math.random();"/>
</span> </span>
</div> </div>
{/if} {/if}

View File

@ -25,7 +25,7 @@ class Ems extends Api
* *
* @ApiMethod (POST) * @ApiMethod (POST)
* @param string $email 邮箱 * @param string $email 邮箱
* @param string $event 事件名称 * @param string $event 事件名称,register,changeemail,resetpwd
*/ */
public function send() public function send()
{ {
@ -37,32 +37,32 @@ class Ems extends Api
//发送前验证码 //发送前验证码
if (config('fastadmin.user_api_captcha')) { if (config('fastadmin.user_api_captcha')) {
if (!\think\Validate::is($captcha, 'captcha')) { if (!\think\Validate::is($captcha, 'captcha')) {
$this->error("验证码不正确"); $this->error(__('Verification code is incorrect'));
} }
} }
$last = Emslib::get($email, $event); $last = Emslib::get($email, $event);
if ($last && time() - $last['createtime'] < 60) { if ($last && time() - $last['createtime'] < 60) {
$this->error(__('发送频繁')); $this->error(__('Send frequently'));
} }
if ($event) { if ($event) {
$userinfo = User::getByEmail($email); $userinfo = User::getByEmail($email);
if ($event == 'register' && $userinfo) { if ($event == 'register' && $userinfo) {
//已被注册 //已被注册
$this->error(__('已被注册')); $this->error(__('Already registered'));
} elseif (in_array($event, ['changeemail']) && $userinfo) { } elseif (in_array($event, ['changeemail']) && $userinfo) {
//被占用 //被占用
$this->error(__('已被占用')); $this->error(__('Already occupied'));
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
//未注册 //未注册
$this->error(__('未注册')); $this->error(__('Not registered'));
} }
} }
$ret = Emslib::send($email, null, $event); $ret = Emslib::send($email, null, $event);
if ($ret) { if ($ret) {
$this->success(__('发送成功')); $this->success(__('Send successful'));
} else { } else {
$this->error(__('发送失败')); $this->error(__('Send failed'));
} }
} }
@ -71,7 +71,7 @@ class Ems extends Api
* *
* @ApiMethod (POST) * @ApiMethod (POST)
* @param string $email 邮箱 * @param string $email 邮箱
* @param string $event 事件名称 * @param string $event 事件名称,register,changeemail,resetpwd
* @param string $captcha 验证码 * @param string $captcha 验证码
*/ */
public function check() public function check()
@ -85,20 +85,20 @@ class Ems extends Api
$userinfo = User::getByEmail($email); $userinfo = User::getByEmail($email);
if ($event == 'register' && $userinfo) { if ($event == 'register' && $userinfo) {
//已被注册 //已被注册
$this->error(__('已被注册')); $this->error(__('Already registered'));
} elseif (in_array($event, ['changeemail']) && $userinfo) { } elseif (in_array($event, ['changeemail']) && $userinfo) {
//被占用 //被占用
$this->error(__('已被占用')); $this->error(__('Already occupied'));
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
//未注册 //未注册
$this->error(__('未注册')); $this->error(__('Not registered'));
} }
} }
$ret = Emslib::check($email, $captcha, $event); $ret = Emslib::check($email, $captcha, $event);
if ($ret) { if ($ret) {
$this->success(__('成功')); $this->success(__('Successful'));
} else { } else {
$this->error(__('验证码不正确')); $this->error(__('Verification code is incorrect'));
} }
} }
} }

View File

@ -20,7 +20,7 @@ class Sms extends Api
* *
* @ApiMethod (POST) * @ApiMethod (POST)
* @param string $mobile 手机号 * @param string $mobile 手机号
* @param string $event 事件名称 * @param string $event 事件名称,register,mobilelogin,changemobile,resetpwd
*/ */
public function send() public function send()
{ {
@ -32,31 +32,31 @@ class Sms extends Api
//发送前验证码 //发送前验证码
if (config('fastadmin.user_api_captcha')) { if (config('fastadmin.user_api_captcha')) {
if (!\think\Validate::is($captcha, 'captcha')) { if (!\think\Validate::is($captcha, 'captcha')) {
$this->error("验证码不正确"); $this->error(__('Verification code is incorrect'));
} }
} }
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) { if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('手机号不正确')); $this->error(__('Mobile is incorrect'));
} }
$last = Smslib::get($mobile, $event); $last = Smslib::get($mobile, $event);
if ($last && time() - $last['createtime'] < 60) { if ($last && time() - $last['createtime'] < 60) {
$this->error(__('发送频繁')); $this->error(__('Send frequently'));
} }
$ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count(); $ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
if ($ipSendTotal >= 5) { if ($ipSendTotal >= 5) {
$this->error(__('发送频繁')); $this->error(__('Send frequently'));
} }
if ($event) { if ($event) {
$userinfo = User::getByMobile($mobile); $userinfo = User::getByMobile($mobile);
if ($event == 'register' && $userinfo) { if ($event == 'register' && $userinfo) {
//已被注册 //已被注册
$this->error(__('已被注册')); $this->error(__('Already registered'));
} elseif (in_array($event, ['changemobile']) && $userinfo) { } elseif (in_array($event, ['changemobile']) && $userinfo) {
//被占用 //被占用
$this->error(__('已被占用')); $this->error(__('Already occupied'));
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
//未注册 //未注册
$this->error(__('未注册')); $this->error(__('Not registered'));
} }
} }
if (!Hook::get('sms_send')) { if (!Hook::get('sms_send')) {
@ -64,9 +64,9 @@ class Sms extends Api
} }
$ret = Smslib::send($mobile, null, $event); $ret = Smslib::send($mobile, null, $event);
if ($ret) { if ($ret) {
$this->success(__('发送成功')); $this->success(__('Send successful'));
} else { } else {
$this->error(__('发送失败,请检查短信配置是否正确')); $this->error(__('Send failed, please check the SMS config is correct'));
} }
} }
@ -75,7 +75,7 @@ class Sms extends Api
* *
* @ApiMethod (POST) * @ApiMethod (POST)
* @param string $mobile 手机号 * @param string $mobile 手机号
* @param string $event 事件名称 * @param string $event 事件名称,register,mobilelogin,changemobile,resetpwd
* @param string $captcha 验证码 * @param string $captcha 验证码
*/ */
public function check() public function check()
@ -86,26 +86,26 @@ class Sms extends Api
$captcha = $this->request->post("captcha"); $captcha = $this->request->post("captcha");
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) { if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('手机号不正确')); $this->error(__('Mobile is incorrect'));
} }
if ($event) { if ($event) {
$userinfo = User::getByMobile($mobile); $userinfo = User::getByMobile($mobile);
if ($event == 'register' && $userinfo) { if ($event == 'register' && $userinfo) {
//已被注册 //已被注册
$this->error(__('已被注册')); $this->error(__('Already registered'));
} elseif (in_array($event, ['changemobile']) && $userinfo) { } elseif (in_array($event, ['changemobile']) && $userinfo) {
//被占用 //被占用
$this->error(__('已被占用')); $this->error(__('Already occupied'));
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) { } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
//未注册 //未注册
$this->error(__('未注册')); $this->error(__('Not registered'));
} }
} }
$ret = Smslib::check($mobile, $captcha, $event); $ret = Smslib::check($mobile, $captcha, $event);
if ($ret) { if ($ret) {
$this->success(__('成功')); $this->success(__('Successful'));
} else { } else {
$this->error(__('验证码不正确')); $this->error(__('Verification code is incorrect'));
} }
} }
} }

View File

@ -32,7 +32,7 @@ class Validate extends Api
$id = (int)$this->request->post('id'); $id = (int)$this->request->post('id');
$count = User::where('email', '=', $email)->where('id', '<>', $id)->count(); $count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
if ($count > 0) { if ($count > 0) {
$this->error(__('邮箱已经被占用')); $this->error(__('Email already occupied'));
} }
$this->success(); $this->success();
} }
@ -50,7 +50,7 @@ class Validate extends Api
$id = (int)$this->request->post('id'); $id = (int)$this->request->post('id');
$count = User::where('username', '=', $username)->where('id', '<>', $id)->count(); $count = User::where('username', '=', $username)->where('id', '<>', $id)->count();
if ($count > 0) { if ($count > 0) {
$this->error(__('用户名已经被占用')); $this->error(__('Username already occupied'));
} }
$this->success(); $this->success();
} }
@ -68,7 +68,7 @@ class Validate extends Api
$id = (int)$this->request->post('id'); $id = (int)$this->request->post('id');
$count = User::where('nickname', '=', $nickname)->where('id', '<>', $id)->count(); $count = User::where('nickname', '=', $nickname)->where('id', '<>', $id)->count();
if ($count > 0) { if ($count > 0) {
$this->error(__('昵称已经被占用')); $this->error(__('Nickname already occupied'));
} }
$this->success(); $this->success();
} }
@ -86,7 +86,7 @@ class Validate extends Api
$id = (int)$this->request->post('id'); $id = (int)$this->request->post('id');
$count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count(); $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
if ($count > 0) { if ($count > 0) {
$this->error(__('该手机号已经占用')); $this->error(__('Mobile already occupied'));
} }
$this->success(); $this->success();
} }
@ -102,7 +102,7 @@ class Validate extends Api
$mobile = $this->request->post('mobile'); $mobile = $this->request->post('mobile');
$count = User::where('mobile', '=', $mobile)->count(); $count = User::where('mobile', '=', $mobile)->count();
if (!$count) { if (!$count) {
$this->error(__('手机号不存在')); $this->error(__('Mobile not exists'));
} }
$this->success(); $this->success();
} }
@ -118,7 +118,7 @@ class Validate extends Api
$email = $this->request->post('email'); $email = $this->request->post('email');
$count = User::where('email', '=', $email)->count(); $count = User::where('email', '=', $email)->count();
if (!$count) { if (!$count) {
$this->error(__('邮箱不存在')); $this->error(__('Email not exists'));
} }
$this->success(); $this->success();
} }
@ -137,7 +137,7 @@ class Validate extends Api
$captcha = $this->request->post('captcha'); $captcha = $this->request->post('captcha');
$event = $this->request->post('event'); $event = $this->request->post('event');
if (!\app\common\library\Sms::check($mobile, $captcha, $event)) { if (!\app\common\library\Sms::check($mobile, $captcha, $event)) {
$this->error(__('验证码不正确')); $this->error(__('Verification code is incorrect'));
} }
$this->success(); $this->success();
} }
@ -156,7 +156,7 @@ class Validate extends Api
$captcha = $this->request->post('captcha'); $captcha = $this->request->post('captcha');
$event = $this->request->post('event'); $event = $this->request->post('event');
if (!\app\common\library\Ems::check($email, $captcha, $event)) { if (!\app\common\library\Ems::check($email, $captcha, $event)) {
$this->error(__('验证码不正确')); $this->error(__('Verification code is incorrect'));
} }
$this->success(); $this->success();
} }

View File

@ -0,0 +1,11 @@
<?php
return [
'Verification code is incorrect' => '验证码不正确',
'Send frequently' => '发送频繁',
'Already registered' => '已被注册',
'Already occupied' => '已被占用',
'Not registered' => '未注册',
'Send successful' => '发送成功',
'Send failed' => '发送失败',
'Successful' => '成功',
];

View File

@ -0,0 +1,12 @@
<?php
return [
'Verification code is incorrect' => '验证码不正确',
'Mobile is incorrect' => '手机号不正确',
'Send frequently' => '发送频繁',
'Already registered' => '已被注册',
'Already occupied' => '已被占用',
'Not registered' => '未注册',
'Send successful' => '发送成功',
'Send failed, please check the SMS config is correct' => '发送失败,请检查短信配置是否正确',
'Successful' => '成功',
];

View File

@ -0,0 +1,10 @@
<?php
return [
'Email already occupied' => '邮箱已经被占用',
'Username already occupied' => '用户名已经被占用',
'Nickname already occupied' => '昵称已经被占用',
'Mobile already occupied' => '该手机号已经占用',
'Mobile not exists' => '手机号不存在',
'Email not exists' => '邮箱不存在',
'Verification code is incorrect' => '验证码不正确',
];