Example #1
0
 public function closeSession()
 {
     $_SESSION["user"] = new CocoasUser();
     foreach ($_COOKIE as $key => $value) {
         SETCOOKIE($key, $value, TIME() - 10000);
     }
 }
 public function admin_login()
 {
     $this->layout = 'admin_login';
     $remember_me = false;
     $this->set('title_for_layout', 'Admin Login');
     $userSession = $this->Session->read('Auth.User');
     if (!empty($this->request->data)) {
         $this->Staff->set($this->request->data);
         if ($this->Staff->validates()) {
             if ($this->checkEmailValidation($this->request->data['Staff']['email'])) {
                 $email = strtolower($this->data['Staff']['email']);
                 $userPassword = md5($this->data['Staff']['password']);
                 $userInfo = $this->Staff->find('first', array('fields' => array('Staff.*'), 'conditions' => array("Staff.email" => $email, "Staff.password" => $userPassword)));
                 //debug($userinfo); exit;
                 if (!empty($userInfo['Staff']['email']) && !empty($userInfo['Staff']['password']) && $userInfo['Staff']['password'] == $userPassword) {
                     if (!empty($this->request->data['Staff']['remember_me'])) {
                         $password = base64_encode($this->data['Staff']['password']);
                         $hour = TIME() + 60 * 60 * 24 * 30;
                         SETCOOKIE("EMAIL_COOKIE", $email, $hour);
                         SETCOOKIE("PASSWORD_COOKIE", $password, $hour);
                     } else {
                         SETCOOKIE("EMAIL_COOKIE", "", time() - 3600);
                         SETCOOKIE("PASSWORD_COOKIE", "", time() - 3600);
                     }
                     $this->Session->write('SESSION_ADMIN', $userInfo['Staff']);
                     $this->Session->write('Auth.User', $userInfo['Staff']);
                     $this->redirect(array('controller' => 'dashboards'));
                 } else {
                     $this->Session->setFlash('Email/Password is not correct.', 'default', array('class' => 'flashError', 'admin' => 1));
                 }
             } else {
                 $this->Session->setFlash('Please enter a valid email address.', 'default', array('class' => 'flashError', 'admin' => 1));
             }
         }
     } elseif (!empty($_COOKIE['EMAIL_COOKIE'])) {
         $this->request->data['Staff']['email'] = @$_COOKIE['EMAIL_COOKIE'];
         $this->request->data['Staff']['password'] = base64_decode(@$_COOKIE['PASSWORD_COOKIE']);
         $remember_me = true;
     }
     $this->set('remember_me', $remember_me);
 }