Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2.  
  3. use Phalcon\Mvc\Controller;
  4.  
  5.  
  6. class AuthController extends Controller
  7. {
  8.  
  9.  
  10.     public function index()
  11.     {
  12.         echo '<h1>Hello!</h1>';
  13.     }
  14.  
  15.     public function login()
  16.     {
  17.  
  18.         if ($this->auth($this->request->getJsonRawBody()->username,
  19.                         $this->request->getJsonRawBody()->password))
  20.         {
  21.             $this->response->redirect('/');
  22.             $this->response->sendHeaders();
  23.         }
  24.         echo "logging in";
  25.         echo $this->request->get("year");
  26.         echo "--";
  27.         print_r($_POST);
  28.     }
  29.  
  30.  
  31.     public function logout()
  32.     {
  33.         $this->session->destroy();
  34.         $this->response->redirect('/');
  35.         $this->response->sendHeaders();
  36.     }
  37.  
  38.     private function auth($username, $password)
  39.     {
  40.         //$this->session=new Session();
  41.         $result = false;
  42.         if($this->checkUserPassword($username,$password)){
  43.             $this->session->start();
  44.             $this->session->set('username', $username);
  45.             $this->session->set('auth', true);
  46.             $result = true;
  47.         }
  48.         return $result;
  49.     }
  50.  
  51.     private function checkUserPassword($username, $password){
  52.         $result = false;
  53.         $sysUsers = SysUsers::findFirst(
  54.             [
  55.                 "username" => $username,
  56.             ]
  57.         );
  58.         if($sysUsers){
  59.             $hashpassword = hash('sha512',$password);
  60.             $result = $sysUsers->password == $hashpassword;
  61.         }
  62.         return $result;
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement