Login.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\controller;
  10. use mall\response\Response;
  11. use think\captcha\facade\Captcha;
  12. use think\facade\Request;
  13. use think\facade\View;
  14. use think\facade\Session;
  15. use app\admin\service\SystemUsers as SystemUsersService;
  16. use app\admin\validate\SystemUsers as SystemUsersValidate;
  17. use think\exception\ValidateException;
  18. use app\common\models\Setting as SettingModel;
  19. class Login extends Base {
  20. /**
  21. * 登录页
  22. * @return string|\think\response\Redirect
  23. */
  24. public function index(){
  25. if (Session::has("system_user_id")) {
  26. return redirect(createUrl('platform.index/index'));
  27. } else{
  28. $copy = SettingModel::getArrayData("copyright");
  29. return View::fetch("",["data"=>$copy["copyright"]??[]]);
  30. }
  31. }
  32. /**
  33. * 登录
  34. * @return \think\response\Json
  35. */
  36. public function post(){
  37. try{
  38. $post = Request::param();
  39. validate(SystemUsersValidate::class)->scene('login')->check($post);
  40. SystemUsersService::login($post);
  41. return Response::returnArray("登录成功,正在为您跳转中…", 1, createUrl("platform.index/index"));
  42. }catch (ValidateException $e){
  43. return Response::returnArray($e->getError(), 0);
  44. } catch (\Exception $ex){
  45. return Response::returnArray($ex->getMessage(), 0);
  46. }
  47. }
  48. /**
  49. * 验证码
  50. * @return \think\Response
  51. */
  52. public function verify(){
  53. return Captcha::create();
  54. }
  55. /**
  56. * 退出登录
  57. * @return \think\response\Redirect
  58. */
  59. public function logout() {
  60. return redirect(SystemUsersService::logout());
  61. }
  62. }