123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- namespace app\api\controller;
-
- use app\api\logic\LoginLogic;
- use app\api\validate\WechatLoginValidate;
- use app\common\basics\Api;
- use app\common\enum\NoticeEnum;
- use app\common\server\JsonServer;
- use app\common\server\ConfigServer;
- use app\api\validate\RegisterValidate;
- use app\api\validate\LoginValidate;
- use think\exception\ValidateException;
- use app\api\validate\OaLoginValidate;
-
- class Account extends Api
- {
-
- public $like_not_need_login = ['silentLogin', 'authLogin', 'register', 'login','mnplogin', 'codeurl', 'oalogin', 'oplogin','logout','smslogin', 'uinAppLogin', 'silentLogin', 'authLogin', 'scanCode', 'scanLogin'];
-
-
-
- public function register()
- {
- $post = $this->request->post();
- $post['check_code'] = ConfigServer::get('register', 'captcha', 0);
- $post['message_key'] = NoticeEnum::REGISTER_NOTICE;
- try{
- validate(RegisterValidate::class)->check($post);
- }catch(ValidateException $e) {
- return JsonServer::error($e->getError());
- }
-
- $result = LoginLogic::register($post);
- if($result !== false) {
- return JsonServer::success('注册成功', $result);
- }
- return JsonServer::error('注册失败:'.LoginLogic::getError());
- }
-
-
-
-
-
- public function silentLogin()
- {
- $post = $this->request->post();
- if (empty($post['code'])) {
- return JsonServer::error('参数缺失');
- }
- $data = LoginLogic::silentLogin($post);
- if(false === $data) {
- $error = LoginLogic::getError() ?? '登录失败';
- return JsonServer::error($error);
- }
- return JsonServer::success('', $data);
- }
-
-
-
- public function authLogin()
- {
- $post = $this->request->post();
- if (empty($post['code']) || empty($post['nickname'])) {
- return JsonServer::error('参数缺失');
- }
-
- $data = LoginLogic::authLogin($post);
- if(false === $data) {
- $error = LoginLogic::getError() ?? '登录失败';
- return JsonServer::error($error);
- }
- return JsonServer::success('', $data);
- }
-
-
-
- public function login()
- {
- $post = $this->request->post();
- (new LoginValidate)->goCheck('mpLogin', $post);
- $data = LoginLogic::mpLogin($post);
- return JsonServer::success('登录成功',$data);
- }
-
-
-
- public function codeUrl()
- {
- $url = $this->request->get('url');
- return JsonServer::success('获取成功', ['url' => LoginLogic::codeUrl($url)]);
- }
-
-
-
- public function oaLogin()
- {
- $post = $this->request->post();
- (new OaLoginValidate())->check($post);
- $data = LoginLogic::oaLogin($post);
- return JsonServer::success('登录成功', $data);
- }
-
-
-
- public function uinAppLogin()
- {
- $post = $this->request->post();
- $data = LoginLogic::uinAppLogin($post);
- if(is_string($data )){
- return JsonServer::error($data);
- }
- $data = [
- 'code' => 1,
- 'show' => 0,
- 'msg' => '登录成功',
- 'data' => $data
- ];
- return json($data);
- }
-
-
-
- public function smsLogin()
- {
- $post = $this->request->post();
- (new LoginValidate())->goCheck('smsLogin');
- $data = LoginLogic::login($post);
- return JsonServer::success('登录成功', $data);
- }
-
-
-
- public function logout()
- {
- LoginLogic::logout($this->user_id, $this->client);
-
- return JsonServer::success();
- }
-
-
-
-
- public function scanCode()
- {
- $result = LoginLogic::scanCode();
- if (false === $result) {
- return JsonServer::error(LoginLogic::getError() ?? '未知错误');
- }
- return JsonServer::success('', ['url' => $result]);
- }
-
-
-
-
- public function scanLogin()
- {
- $params = $this->request->post();
- $result = LoginLogic::scanLogin($params);
- if (false === $result) {
- return JsonServer::error(LoginLogic::getError() ?? '未知错误');
- }
- return JsonServer::success('', $result);
- }
-
-
-
- public function updateUser()
- {
- $post = $this->request->post();
- if (!isset($post['avatar']) || empty($post['avatar'])) {
- JsonServer::error('参数缺失');
- }
- if (!isset($post['nickname']) || empty($post['nickname'])) {
- JsonServer::error('参数缺失');
- }
-
- LoginLogic::updateUser($post,$this->user_id);
- return JsonServer::success('操作成功');
- }
-
-
-
- public function mnpAuthLogin()
- {
- $params = (new WechatLoginValidate())->goCheck("wechatAuth");
- $params['user_id'] = $this->user_id;
- $result = (new LoginLogic())->mnpAuthLogin($params);
- if ($result === false) {
- return JsonServer::error(LoginLogic::getError());
- }
- return JsonServer::success('绑定成功', [], 1, 1);
-
- }
-
-
-
- public function oaAuthLogin()
- {
- $params = (new WechatLoginValidate())->goCheck("wechatAuth");
- $params['user_id'] = $this->user_id;
- $result = (new LoginLogic())->oaAuthLogin($params);
- if ($result === false) {
- return JsonServer::error(LoginLogic::getError());
- }
-
- return JsonServer::success('绑定成功', [], 1, 1);
- }
-
-
- }
|