Skip to content

Instantly share code, notes, and snippets.

@unisys12
Created February 11, 2014 18:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unisys12/8941453 to your computer and use it in GitHub Desktop.
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]
<?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