Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. use Phalcon\Mvc\Controller;
  4.  
  5. class SigninController extends Controller
  6. {
  7.  
  8.     public function indexAction()
  9.     {
  10.  
  11.     }
  12.  
  13.     private function _registerSession($user)
  14.     {
  15.         $this->session->set(
  16.             "auth",
  17.             [
  18.                 "id"   => $user->id,
  19.                 "name" => $user->name,
  20.             ]
  21.         );
  22.     }
  23.  
  24.     public function loginAction()
  25.     {
  26.         if ($this->request->isPost()) {
  27.             // Get the data from the user
  28.             $email    = $this->request->getPost("email");
  29.             $password = $this->request->getPost("password");
  30.            
  31.  
  32.  
  33.             // Find the user in the database
  34.             $user = Users::findFirst(
  35.                 [
  36.                     "email = :email: AND password = :password:",
  37.                     "bind" => [
  38.                         "email"    => $email,
  39.                         "password" => $password,
  40.                     ]
  41.                 ]
  42.             );
  43.            
  44.  
  45.             if ($user !== false) {
  46.                 $this->_registerSession($user);
  47.  
  48.                 $this->flash->success(
  49.                     "Welcome " . $user->name
  50.                 );
  51.  
  52.             }
  53.             else
  54.             {
  55.                 $this->flash->error(
  56.                     "Wrong email/password"
  57.                 );
  58.                 // Forward to the login form again
  59.                 return $this->dispatcher->forward(
  60.                     [
  61.                         "controller" => "signin",
  62.                         "action"     => "index",
  63.                     ]
  64.                 );
  65.                
  66.             }
  67.         }
  68.  
  69.        
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement