Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.