public function signinAction()
 {
     if (self::$token->user) {
         $this->_redirect(BASE_URL . "/admin");
     }
     $err = null;
     $this->view->layout()->disableLayout();
     if ($this->_request->isPost()) {
         $params = array_merge(array("username" => null, "password" => null, "remember" => null), My_Util::santinize(array_map("trim", $this->_request->getParams())));
         if (!$params["username"] || !$params["password"]) {
             $err[] = "Username/Password is empty.";
         }
         if (!$err) {
             $arrUser = My_Model_User::getbyusername($params);
             if ($arrUser) {
                 $hash = md5($params["password"] . $arrUser["salt"]);
                 if ($hash == $arrUser["password"]) {
                     self::$token->user = $arrUser;
                     if ($params["remember"]) {
                         setcookie("UN", $arrUser["username"], time() + 86400 * 30, "/");
                         setcookie("UP", $arrUser["password"], time() + 86400 * 30, "/");
                     }
                     $this->_redirect(BASE_URL . "/admin");
                 } else {
                     $err[] = "Username/Password not match.";
                 }
             } else {
                 $err[] = "User not found.";
             }
         }
     }
     $this->view->err = $err;
 }
Example #2
0
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #3
0
 protected function login_from_cookie()
 {
     if (isset($_COOKIE["UN"]) && isset($_COOKIE["UP"]) && $_COOKIE["UN"] && $_COOKIE["UP"]) {
         $arrUser = My_Model_User::getbyusername(array("username" => $_COOKIE["UN"]));
         if ($arrUser) {
             if ($arrUser["password"] != $_COOKIE["UP"]) {
                 self::$token->user = null;
                 $this->_redirect(BASE_URL . "/signin.html");
             } else {
                 self::$token->user = $arrUser;
             }
         } else {
             setcookie("UN", null);
             setcookie("UP", null);
         }
     }
 }