新增修改密码功能和重置密码功能
This commit is contained in:
@@ -13,6 +13,7 @@ use app\admin\model\YzAdminConfig;
|
||||
|
||||
class Login
|
||||
{
|
||||
// 登录页面
|
||||
public function index()
|
||||
{
|
||||
# 获取配置
|
||||
@@ -23,6 +24,8 @@ class Login
|
||||
]);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
// 登录
|
||||
public function login()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
@@ -69,12 +72,16 @@ class Login
|
||||
$this->returnCode(0, [], '登陆成功');
|
||||
}
|
||||
}
|
||||
|
||||
// 退出
|
||||
public function logout()
|
||||
{
|
||||
Cookie::delete('admin_id');
|
||||
Cookie::delete('admin_name');
|
||||
$this->returnCode(0, [], '退出成功');
|
||||
}
|
||||
|
||||
// 返回代码
|
||||
protected function returnCode($code, $data = [], $msg = '')
|
||||
{
|
||||
header('Content-type:application/json');
|
||||
@@ -101,4 +108,46 @@ class Login
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// 密码重置页面
|
||||
public function resetpwdindex()
|
||||
{
|
||||
return View::fetch('resetpwd');
|
||||
}
|
||||
|
||||
//管理员密码重置
|
||||
public function resetpwd()
|
||||
{
|
||||
$account = trim(input('post.account'));
|
||||
if (empty($account)) {
|
||||
$this->returnCode(1, '账号不能为空');
|
||||
}
|
||||
|
||||
$user = Db::table('yz_admin_user')->where('account', $account)->find();
|
||||
|
||||
if (!$user) {
|
||||
$this->returnCode(1, '未找到该用户名');
|
||||
}
|
||||
|
||||
// 使用md5进行密码加密处理
|
||||
$password = md5('123456');
|
||||
|
||||
try {
|
||||
$res = Db::table('yz_admin_user')
|
||||
->where('account', $account)
|
||||
->update(['password' => $password]);
|
||||
|
||||
if ($res === false) {
|
||||
$this->returnCode(1, '数据库更新失败');
|
||||
}
|
||||
|
||||
if ($res === 0) {
|
||||
$this->returnCode(1, '密码未发生变化');
|
||||
}
|
||||
|
||||
$this->returnCode(0, [], '密码重置成功');
|
||||
} catch (\Exception $e) {
|
||||
$this->returnCode(1, '系统错误:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user