36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\services\auth;
|
|
|
|
use app\model\user\Users;
|
|
|
|
class LoginService{
|
|
|
|
public function authLogin($request){
|
|
$params = $request->post();
|
|
$map = [];
|
|
foreach($params as $field => $value){
|
|
if(in_array($field, ['username', 'email', 'mobile']) && $field != 'password'){
|
|
$map[$field] = $value;
|
|
}
|
|
}
|
|
$user = Users::where($map)->field(['uid','username', 'password', 'email', 'avatar', 'department_id', 'status'])->findOrEmpty();
|
|
if (!$user->isEmpty()) {
|
|
if(password_verify(base64_decode($params['password']), $user->password)){
|
|
throw new \think\Exception('密码不正确!', 100002);
|
|
}elseif($user->status != 1){
|
|
throw new \think\Exception('当前用户不可用', 100003);
|
|
}else{
|
|
return $user->append(['token']);
|
|
}
|
|
}else{
|
|
throw new \think\Exception('当前用户不存在', 100001);
|
|
}
|
|
}
|
|
} |