Login.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use think\Session;
  5. use think\Db;
  6. use think\Request;
  7. class Login extends Controller
  8. {
  9. public function index()
  10. {
  11. return $this->fetch();
  12. }
  13. public function video()
  14. {
  15. return $this->fetch();
  16. }
  17. public function dologin()
  18. {
  19. $res=array();
  20. if ($this->request->isAjax()&&$this->request->isPost()) {
  21. $data = $_POST;
  22. $company=Db::name('company')->where('account',$data['username'])->find();
  23. if($company){
  24. if($company['password']==md5($data['password'])){
  25. session('uid',$company);//保存账号信息
  26. $res=array("status"=>1,"msg"=>'success');
  27. }else{
  28. $res=array("status"=>0,"msg"=>'密码错误');
  29. }
  30. }else{
  31. $res=array("status"=>0,"msg"=>'该账号不存在');
  32. }
  33. }else{
  34. $res=array("status"=>0,"msg"=>'非法请求');
  35. }
  36. echo json_encode($res);
  37. }
  38. public function logout()
  39. {
  40. session(null);
  41. $this->redirect('Login/index');
  42. }
  43. }