You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\H5;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
use JWT;
|
|
|
|
class LoginController
|
|
{
|
|
public function login(){
|
|
//Cache::forget('all_system_configs');
|
|
$systemStatus = \Yz::systemStatusCheck();
|
|
if(!$systemStatus['status']){
|
|
return \Yz::echoError1($systemStatus['msg']);
|
|
}
|
|
|
|
$info = request('info');
|
|
if(empty($info['tel']) or empty($info['password'])){
|
|
return \Yz::echoError1('请输入手机号或密码');
|
|
}
|
|
$member = DB::table('members')->where(['tel'=>$info['tel'],'status'=>1,'is_del'=>0])->first();
|
|
if(empty($member)){
|
|
return \Yz::echoError1('账号不可用');
|
|
}
|
|
if (!password_verify($info['password'],$member->password)) {
|
|
return \Yz::echoError1('账号或密码错误');
|
|
}
|
|
$jwt= new JWT();
|
|
$accessTimeout = $jwt -> GetGetSecretTimeOut();
|
|
$refreshTimeout = $jwt -> GetRefreshTokenTimeOut();
|
|
$access_token = $jwt->BuildJWT('system','access',$member->id,'',$accessTimeout);
|
|
$refresh_token = $jwt->BuildJWT('system','refresh',$member->id,'',$refreshTimeout);
|
|
return \Yz::Return(true,'登录成功',[
|
|
'access_token'=>$access_token,
|
|
'refresh_token'=>$refresh_token,
|
|
]);
|
|
}
|
|
public function ResetPassword()
|
|
{
|
|
$systemStatus = \Yz::systemStatusCheck();
|
|
if(!$systemStatus['status']){
|
|
return \Yz::echoError1($systemStatus['msg']);
|
|
}
|
|
$info = request('info');
|
|
if(empty($info['tel']) or empty($info['password']) or empty($info['code'])){
|
|
return \Yz::echoError1('请填写手机号、密码、验证码');
|
|
}
|
|
$member = DB::table('members')->where(['tel'=>$info['tel'],'status'=>1,'is_del'=>0])->first();
|
|
if(empty($member)){
|
|
return \Yz::echoError1('未找到有效用户');
|
|
}
|
|
// $code = DB::table('codes')->where(['tel'=>$info['tel'],'code'=>$info['code'],'type'=>1,'is_del'=>0])->first();
|
|
// if(empty($code)){
|
|
// return \Yz::echoError1('验证码错误');
|
|
// }
|
|
$password = password_hash($info['password'], PASSWORD_DEFAULT);
|
|
$u= DB::table('members')->where(['id'=>$member->id])->update(['password'=>$password]);
|
|
// DB::table('codes')->where(['id'=>$code->id])->update(['is_del'=>1]);
|
|
if($u){
|
|
return \Yz::Return(true,'密码重置成功');
|
|
}else{
|
|
return \Yz::echoError1('密码重置失败');
|
|
}
|
|
|
|
|
|
}
|
|
}
|