Skip to content

Instantly share code, notes, and snippets.

@oktavianto
Created December 13, 2017 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oktavianto/f3d1597e13aba117e42c55807b4dadc2 to your computer and use it in GitHub Desktop.
Save oktavianto/f3d1597e13aba117e42c55807b4dadc2 to your computer and use it in GitHub Desktop.
LoginController.php
<?php
class LoginController extends \Phalcon\Mvc\Controller
{
private function _registerSession(User $user)
{
$this->session->set('auth', array(
'loggedin' => true,
'id' => $user->id,
'username' => $user->username
));
}
public function indexAction()
{
if ($this->request->isPost()) {
$login = $this->request->getPost('login');
$password = $this->request->getPost('password');
$user = Users::findFirstByLogin($login);
if ($user) {
if ($this->security->checkHash($password, $user->password)) {
$this->_registerSession($user);
$this->response->redirect('dashboard');
}
} else {
$this->response->redirect('login');
$this->security->hash(rand());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment