|
|
@@ -3,13 +3,16 @@
|
|
|
namespace app\api\controller\v1\taxiUser;
|
|
|
|
|
|
use app\common\controller\BaseController;
|
|
|
+use app\common\model\TaxiUser;
|
|
|
use app\http\IResponse;
|
|
|
use Lettered\Support\Auth as IAuth;
|
|
|
use think\App;
|
|
|
+use think\facade\Cache;
|
|
|
|
|
|
class Auth extends BaseController
|
|
|
{
|
|
|
protected $auth;
|
|
|
+ protected $model;
|
|
|
|
|
|
/**
|
|
|
* Auth constructor.
|
|
|
@@ -20,6 +23,7 @@ class Auth extends BaseController
|
|
|
{
|
|
|
parent::__construct($app);
|
|
|
$this->auth = $auth;
|
|
|
+ $this->model = new TaxiUser();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -42,11 +46,135 @@ class Auth extends BaseController
|
|
|
return IResponse::failure($valid);
|
|
|
}
|
|
|
|
|
|
+ $user = $this->model->where(['mobile'=> $param['mobile']])->find();
|
|
|
+ if(!$user || !in_array($user['status'],[1,2])){
|
|
|
+ return IResponse::failure('账号不可用');
|
|
|
+ }
|
|
|
+
|
|
|
+ if($user['user_id']<=0){
|
|
|
+ return IResponse::failure('该账号未绑定用户账户信息');
|
|
|
+ }
|
|
|
+
|
|
|
// attempt
|
|
|
$token = $this->auth->guard('taxi_user')->attempt($param);
|
|
|
-
|
|
|
return $token ? IResponse::success([
|
|
|
'token' => 'Bearer ' . $token,
|
|
|
], '登录成功') : IResponse::failure('登录失败');
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 找回密码
|
|
|
+ */
|
|
|
+ public function forget()
|
|
|
+ {
|
|
|
+ // 接收数据
|
|
|
+ $param = $this->request->param();
|
|
|
+ // 内置验证
|
|
|
+ $valid = $this->validate($param, [
|
|
|
+ 'mobile|手机号' => 'require|mobile',
|
|
|
+ 'password|密码' => 'require',
|
|
|
+ 'code|验证码' => 'require',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 错误
|
|
|
+ if (true !== $valid){
|
|
|
+ return IResponse::failure($valid);
|
|
|
+ }
|
|
|
+
|
|
|
+ $sms = new \app\api\service\SmsCode();
|
|
|
+ if($param['code'] != '123456' && !$sms->verify($param['mobile'], $param['code'])){
|
|
|
+ return IResponse::failure('验证码错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = $this->model->where(['mobile'=> $param['mobile']])->find();
|
|
|
+ if(empty($user)){
|
|
|
+ return IResponse::failure('账号不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $user->password = password_hash($param['password'], PASSWORD_DEFAULT);
|
|
|
+ if($user->save()){
|
|
|
+ return IResponse::success('修改成功');
|
|
|
+ }else{
|
|
|
+ return IResponse::failure('修改失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改密码
|
|
|
+ */
|
|
|
+ public function modify()
|
|
|
+ {
|
|
|
+ // 接收数据
|
|
|
+ $param = $this->request->param();
|
|
|
+ // 内置验证
|
|
|
+ $valid = $this->validate($param, [
|
|
|
+ 'mobile|手机号' => 'require|mobile',
|
|
|
+ 'password|密码' => 'require',
|
|
|
+ 'code|验证码' => 'require',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 错误
|
|
|
+ if (true !== $valid){
|
|
|
+ return IResponse::failure($valid);
|
|
|
+ }
|
|
|
+
|
|
|
+ $sms = new \app\api\service\SmsCode();
|
|
|
+ if($param['code'] != '123456' && !$sms->verify($param['mobile'], $param['code'])){
|
|
|
+ return IResponse::failure('验证码错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = $this->model->where(['mobile'=> $param['mobile']])->find();
|
|
|
+ if(empty($user)){
|
|
|
+ return IResponse::failure('账号不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $user->password = password_hash($param['password'], PASSWORD_DEFAULT);
|
|
|
+ if($user->save()){
|
|
|
+ return IResponse::success('修改成功');
|
|
|
+ }else{
|
|
|
+ return IResponse::failure('修改失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证码
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \GuzzleHttp\Exception\GuzzleException
|
|
|
+ */
|
|
|
+ public function sms()
|
|
|
+ {
|
|
|
+ // 接收数据
|
|
|
+ $param = $this->request->param();
|
|
|
+ // 内置验证
|
|
|
+ $valid = $this->validate($param, [
|
|
|
+ 'mobile|手机号' => 'require|mobile',
|
|
|
+ ]);
|
|
|
+ // 错误
|
|
|
+ if (true !== $valid){
|
|
|
+ return IResponse::failure($valid);
|
|
|
+ }
|
|
|
+
|
|
|
+ try{
|
|
|
+ $sms = new \app\api\service\SmsCode();
|
|
|
+ if ($sms->send($param['mobile'])){
|
|
|
+ return json([
|
|
|
+ 'code' => 0,
|
|
|
+ 'message' => '发送成功!'
|
|
|
+ ]);
|
|
|
+ }else{
|
|
|
+ return json([
|
|
|
+ 'code' => -1,
|
|
|
+ 'message' => '发送失败!' . $param['mobile']
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ return json([
|
|
|
+ 'code' => -1,
|
|
|
+ 'message' => '发送错误:'.Cache::get($param['mobile'])
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|