增加用户名登录

This commit is contained in:
WispX
2020-02-29 23:06:16 +08:00
parent e7fa6fac11
commit e3880f50e7
4 changed files with 14 additions and 9 deletions
+1 -3
View File
@@ -51,10 +51,8 @@ class Users extends Model
return sprintf("%.2f", $this->hasMany('Images', 'user_id', 'id')->sum('size'));
}
public static function login($account, $password)
public static function login($account, $password, $field = 'email')
{
$field = 'email';
if (!$account) {
throw new Exception('请输入账号');
}
+2 -2
View File
@@ -14,11 +14,11 @@ use think\facade\Session;
class Auth extends Base
{
public function login($account = null, $password = null)
public function login($type = null, $account = null, $password = null)
{
if ($this->request->isPost()) {
try {
Users::login($account, $password);
Users::login($account, $password, $type);
} catch (Exception $e) {
Session::flash('error', $e->getMessage());
return $this->fetch();
+1 -1
View File
@@ -197,7 +197,7 @@ class User extends Base
$id = $this->request->post('id');
$name = $this->request->post('name');
$validate = Validate::make(['name|名' => 'require|max:25|chsDash']);
$validate = Validate::make(['name|名' => 'require|max:60|chsDash']);
if (!$validate->check(['name' => $name])) {
throw new \Exception($validate->getError());
}
+10 -3
View File
@@ -16,9 +16,16 @@
<div class="panel-body-box">
<form action="{:url('auth/login')}" method="post">
{include file="common:alert"}
<div class="mt-3">
<label class="mdui-textfield-label">登录方式</label>
<select class="mdui-select" mdui-select name="type">
<option value="email" {if input('post.type') === 'email'} selected{/if}>邮箱</option>
<option value="username" {if input('post.type') === 'username'} selected{/if}>用户名</option>
</select>
</div>
<div class="mdui-textfield mdui-textfield-floating-label">
<label class="mdui-textfield-label">邮箱</label>
<input class="mdui-textfield-input" type="email" name="account" value="{:input('post.account')}"/>
<label class="mdui-textfield-label">账号</label>
<input class="mdui-textfield-input" type="text" name="account" value="{:input('post.account')}"/>
</div>
<div class="mdui-textfield mdui-textfield-floating-label">
<label class="mdui-textfield-label">密码</label>
@@ -43,4 +50,4 @@
{block name="js"}
<script src="/static/bootstrap/4.3.1/js/bootstrap.min.js"></script>
{/block}
{/block}