Advertisement
Guest User

Untitled

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