Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Phalcon\Mvc\Controller;
- class AuthController extends Controller
- {
- public function index()
- {
- echo '<h1>Hello!</h1>';
- }
- public function login()
- {
- if ($this->auth($this->request->getJsonRawBody()->username,
- $this->request->getJsonRawBody()->password))
- {
- $this->response->redirect('/');
- $this->response->sendHeaders();
- }
- echo "logging in";
- echo $this->request->get("year");
- echo "--";
- print_r($_POST);
- }
- public function logout()
- {
- $this->session->destroy();
- $this->response->redirect('/');
- $this->response->sendHeaders();
- }
- private function auth($username, $password)
- {
- //$this->session=new Session();
- $result = false;
- if($this->checkUserPassword($username,$password)){
- $this->session->start();
- $this->session->set('username', $username);
- $this->session->set('auth', true);
- $result = true;
- }
- return $result;
- }
- private function checkUserPassword($username, $password){
- $result = false;
- $sysUsers = SysUsers::findFirst(
- [
- "username" => $username,
- ]
- );
- if($sysUsers){
- $hashpassword = hash('sha512',$password);
- $result = $sysUsers->password == $hashpassword;
- }
- return $result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement