Created
February 11, 2014 18:51
-
-
Save unisys12/8941453 to your computer and use it in GitHub Desktop.
Phalcon Authentication Issue [Note] This was actually an issue with me having my column length, in my users table, too short. Instead of 60 chars max, I had it at 50 chars max. DOH![/NOTE]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SessionController extends \Phalcon\Mvc\Controller | |
{ | |
public function indexAction() | |
{ | |
// Will display users profile... once logged in | |
} | |
/** | |
* Log in a current user and start session | |
*/ | |
public function startSessionAction() | |
{ | |
if($this->request->isPost()){ | |
$data = $this->request; | |
$username = $data->getPost('username'); | |
$password = $data->getPost('password'); | |
$user = Users::findFirstByUsername($username); | |
if($user){ | |
if($this->security->checkHash($password, $user->password)){ | |
$this->registerSession($user); | |
$this->persistent->name = $user->name; | |
$this->flashSession->success('Welcome ' . $this->persistent->name); | |
return $this->response->redirect('user/index'); | |
} | |
}else{ | |
$this->flashSession->error("The username you provided is not in our system."); | |
return $this->response->redirect('user/login'); | |
} | |
$this->flashSession->error("Password does match our records for " . $user->username . " ."); | |
} | |
return $this->response->redirect('user/login'); | |
} | |
// Destroy Session | |
public function destroySessionAction() | |
{ | |
$this->session->destroy(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment