Account.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. require_once('MyBaseController.php');
  4. class Account extends MyBaseController {
  5. public function login()
  6. {
  7. if($this->session->userinfo){
  8. $this->redirect('/Home/index');
  9. }else{
  10. $this->load->view('login');
  11. }
  12. }
  13. public function logout()
  14. {
  15. $this->load->library('session');
  16. $this->session->userinfo = null;
  17. $this->redirect('login', 0, '退出成功');
  18. }
  19. public function checkLogin(){
  20. $accountName = $this->input->post('Username');
  21. $password = $this->input->post('Password');
  22. if(!$accountName || !$password){
  23. $this->error('账号密码不能为空');
  24. }
  25. $url = $this->config->item('api_url2')."api/v1/User/yhCheckLogin";
  26. $ret = curl_post($url,[
  27. 'accountName' => $accountName,
  28. 'password' => aes_encrypt($password)
  29. ]);
  30. $ret = json_decode($ret,true);
  31. if(!$ret){
  32. $this->error('登录失败');
  33. }
  34. if($ret['code'] != 0){
  35. $this->error($ret['message']);
  36. }
  37. $userinfo = [
  38. 'userId' => $ret['data']['userId'],
  39. 'realName' => $ret['data']['user']['realName'],
  40. 'token' => $ret['data']['token'],
  41. 'orgId' => isset($ret['data']['orgList'])?$ret['data']['orgList'][0]['orgId']:0,
  42. 'orgName' => isset($ret['data']['orgList'])?$ret['data']['orgList'][0]['name']:'',
  43. 'user' => $ret['data']['user'],
  44. 'roleList' => $ret['data']['roleList'],
  45. 'deptList' => $ret['data']['deptList'],
  46. 'orgList' => $ret['data']['orgList'],
  47. 'rules' => $ret['data']['rules']
  48. ];
  49. $this->session->userinfo = $userinfo;
  50. $this->success('登录成功');
  51. }
  52. }