Example #1
0
 public function index($parameter)
 {
     // authenticate user if form data POSTed
     if (isset($_POST['username'])) {
         if (Fari_User::authenticate($_POST['username'], $_POST['password'], $_POST['token'], 'realname')) {
             // JSON response for our client
             if ($_SERVER['HTTP_USER_AGENT'] == $this->clientIdentifier) {
                 echo json_encode(array('status' => 'success'));
             } else {
                 $user = Fari_User::getCredentials();
                 Fari_Message::notify("Welcome back {$user}!");
                 $this->redirect('/shoutbox/');
                 die;
             }
         } else {
             // JSON response for our client
             if ($_SERVER['HTTP_USER_AGENT'] == $this->clientIdentifier) {
                 echo json_encode(array('status' => 'fail'));
             } else {
                 Fari_Message::fail("Failed to authenticate!");
                 $this->view->system = Fari_Message::get();
             }
         }
     }
     // create token & display login form
     $this->view->token = Fari_Token::create();
     if ($_SERVER['HTTP_USER_AGENT'] != $this->clientIdentifier) {
         $this->view->display('login');
     }
 }
Example #2
0
 public function login()
 {
     if (Fari_User::isAuthenticated('realname')) {
         $this->redirect('/');
     }
     // authenticate user if form data POSTed
     if (isset($_POST['username'])) {
         if (Fari_User::authenticate($_POST['username'], $_POST['password'], $_POST['token'], 'realname')) {
             Fari_Message::success('Welcome back \'' . Fari_User::getCredentials() . '\'');
             $this->redirect('/');
             die;
         }
         Fari_Message::fail('Incorrect authentication details');
     }
     // create token & display login form
     $this->view->token = Fari_Token::create();
     // pickup messages for us
     $this->view->messages = Fari_Message::get();
     $this->view->display('/themes/' . BLOG_THEME . '/login');
 }