Advertisement
Guest User

Untitled

a guest
May 7th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5.  
  6. class Admin
  7. {
  8.     public $msg;
  9.  
  10.     private $db;
  11.     private $helper;
  12.     private $table;
  13.  
  14.     public function __construct()
  15.     {
  16.         $this->db     = new Database();
  17.         $this->helper = new Helper();
  18.         $this->table  = 'admins';
  19.     }
  20.  
  21.     public function adminLogin($data)
  22.     {
  23.         $adminData = array(
  24.             'username' => $this->helper->validation($data['username']),
  25.             'password' => $this->helper->validation($data['password']),
  26.         );
  27.  
  28.         if (in_array(NULL, $adminData))
  29.         {
  30.             $msg = 'Prašome užpildyti visus laukelius';
  31.  
  32.             Session::set('msg', $msg);
  33.         }
  34.         else
  35.         {
  36.             $condition = array(
  37.                 'select'      => 'id, username, password',
  38.                 'where'       => 'username = "' . $adminData['username'] . '" AND password = "' . $adminData['password'] . '"',
  39.                 'return_type' => 'single',
  40.             );
  41.  
  42.             $admin = $this->db->select($this->table, $condition);
  43.  
  44.             if ($admin)
  45.             {
  46.                 Session::set('adminLogin', true);
  47.                 Session::set('adminId', $admin['id']);
  48.             }
  49.             else
  50.             {
  51.                 $msg = 'Nepavyko prisijungti. Prašome bandyti vėl.';
  52.  
  53.                 Session::set('msg', $msg);
  54.             }
  55.         }
  56.  
  57.         header('Refresh: 0');
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement