2013-10-05 12:55:03 +02:00
|
|
|
<?php
|
2013-10-05 21:24:20 +02:00
|
|
|
class AuthController
|
2013-10-05 12:55:03 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @route /auth/login
|
|
|
|
*/
|
|
|
|
public function loginAction()
|
|
|
|
{
|
2013-10-12 22:37:18 +02:00
|
|
|
$this->context->handleExceptions = true;
|
2013-10-12 19:28:52 +02:00
|
|
|
$this->context->stylesheets []= 'auth.css';
|
2013-10-06 18:50:06 +02:00
|
|
|
$this->context->subTitle = 'authentication form';
|
2013-10-05 21:22:28 +02:00
|
|
|
|
2013-10-05 12:55:03 +02:00
|
|
|
//check if already logged in
|
|
|
|
if ($this->context->loggedIn)
|
|
|
|
{
|
2013-10-05 19:24:08 +02:00
|
|
|
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
2013-10-05 12:55:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-15 13:14:48 +02:00
|
|
|
$suppliedName = InputHelper::get('name');
|
|
|
|
$suppliedPassword = InputHelper::get('password');
|
|
|
|
if ($suppliedName !== null and $suppliedPassword !== null)
|
2013-10-05 12:55:03 +02:00
|
|
|
{
|
2013-10-15 13:14:48 +02:00
|
|
|
$dbUser = R::findOne('user', 'name = ?', [$suppliedName]);
|
2013-10-05 12:55:03 +02:00
|
|
|
if ($dbUser === null)
|
|
|
|
throw new SimpleException('Invalid username');
|
|
|
|
|
2013-10-15 13:14:48 +02:00
|
|
|
$suppliedPasswordHash = Model_User::hashPassword($suppliedPassword, $dbUser->pass_salt);
|
|
|
|
if ($suppliedPasswordHash != $dbUser->pass_hash)
|
2013-10-05 12:55:03 +02:00
|
|
|
throw new SimpleException('Invalid password');
|
|
|
|
|
2013-10-13 13:53:24 +02:00
|
|
|
if (!$dbUser->staff_confirmed and $this->config->registration->staffActivation)
|
|
|
|
throw new SimpleException('Staff hasn\'t confirmed your registration yet');
|
2013-10-05 12:55:03 +02:00
|
|
|
|
2013-10-15 13:14:48 +02:00
|
|
|
if ($dbUser->banned)
|
|
|
|
throw new SimpleException('You are banned');
|
|
|
|
|
2013-10-16 18:07:23 +02:00
|
|
|
if ($this->config->registration->needEmailForRegistering)
|
|
|
|
PrivilegesHelper::confirmEmail($dbUser);
|
2013-10-05 12:55:03 +02:00
|
|
|
|
|
|
|
$_SESSION['user-id'] = $dbUser->id;
|
2013-10-05 19:24:08 +02:00
|
|
|
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
2013-10-05 12:55:03 +02:00
|
|
|
$this->context->transport->success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @route /auth/logout
|
|
|
|
*/
|
|
|
|
public function logoutAction()
|
|
|
|
{
|
|
|
|
$this->context->viewName = null;
|
|
|
|
$this->context->viewName = null;
|
|
|
|
unset($_SESSION['user-id']);
|
2013-10-05 19:24:08 +02:00
|
|
|
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
2013-10-05 12:55:03 +02:00
|
|
|
}
|
|
|
|
}
|