Login.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @2021-7-10
  4. **/
  5. namespace app\Admin\controller;
  6. use think\admin\helper\TokenHelper;
  7. use think\Db;
  8. class Login
  9. {
  10. /**
  11. * @method post
  12. * @param username 账户名
  13. * @param password 密码
  14. *
  15. */
  16. public function index(){
  17. $post=request()->post();
  18. $username = isset($post['username'])&&$post['username']!="" ? trim($post['username']) :"";
  19. if($username==""){
  20. return error_show(1004,"参数username 不能为空");
  21. }
  22. $password = isset($post['password'])&&$post['password']!="" ? trim($post['password']):"";
  23. if($password==""){
  24. return error_show(1004,"参数password 不能为空");
  25. }
  26. $account = Db::name("admin")->where(["is_del"=>0,"username"=>$username])->find();
  27. if(empty($account)){
  28. return error_show(1005,"账户未找到");
  29. }
  30. if($account['status']==0){
  31. return error_show(1005,"账户已禁用");
  32. }
  33. $pass = sha1($password.$account['salt']);
  34. if($pass!=$account['password']){
  35. return error_show(1006,"账户密码错误");
  36. }
  37. $token = makeToken($account);
  38. $userinfo = Db::name("account_info")->alias("a")->join("fc_rela_account b","b.account_info=a.id")->where(["b.accountid"=>$account['id']])->field("a.*")->find();
  39. $userinfo['token'] = $token;
  40. write_log("账户{$account['username']}登录系统","","login","",0);
  41. return app_show(0,"登录成功",$userinfo);
  42. }
  43. /**
  44. * @param Token
  45. * 退出登录
  46. */
  47. public function logout(){
  48. $post=request()->post();
  49. $token = isset($post['token'])&&$post['token']!="" ? trim($post['token']) :"";
  50. if($token==""){
  51. return error_show(101,"参数token 不能为空");
  52. }
  53. $verify = verifyToken($token);
  54. if($verify['code']!=0){
  55. return error_show($verify['code'],$verify['msg']);
  56. }
  57. $info = Db::name("admin_token")->where(["token"=>$token])->update(['token'=>""]);
  58. if($info){
  59. return app_show(0,"退出成功");
  60. }else{
  61. return error_show(1004,"退出失败");
  62. }
  63. }
  64. public function LastVersion(){
  65. $version = Db::name("version")->order("addtime desc")->find();
  66. return app_show(0,"获取成功",$version);
  67. }
  68. }