And we have login!

This commit is contained in:
Josh Sherman 2013-12-16 22:40:53 -05:00
parent 3e769286d2
commit 10836461b9
3 changed files with 49 additions and 1 deletions

View file

@ -2,6 +2,7 @@
class login extends AnonymousModule
{
}
?>

View file

@ -0,0 +1,47 @@
<?php
class user_authenticate extends AnonymousModule
{
protected $ajax = true;
protected $method = 'POST';
protected $validate = array(
'email' => array(
'length:>:100' => 'Invalid email address or password.',
'filter:email' => 'Invalid email address or password.',
),
'password' => array(
'length:<:8' => 'Invalid email address or password.',
),
);
public function __default()
{
try
{
$user = new User();
// Checks if the email supplied is valid
if ($uid = $user->getMapping('email', $_POST['email']))
{
// Checks if the password is valid
$password = $user->getPassword($uid);
if ($password == crypt($_POST['password'], $password))
{
$auth_token = $user->getAuth($uid);
setcookie('__auth', base64_encode($uid . '|' . $auth_token), time() + Time::YEAR, '/');
}
}
return array('status' => 'success', 'url' => '/');
}
catch (RedisException $e)
{
return array('error' => $e->getMessage());
}
return array('error' => 'Invalid email address or password.');
}
}
?>

View file

@ -1,4 +1,4 @@
<form role="form" class="row col-xs-12 col-sm-6 col-sm-offset-3" method="post" action="/user/authenticate">
<form role="form" class="ajax row col-xs-12 col-sm-6 col-sm-offset-3" method="post" action="/user/authenticate" onsubmit="return false">
<h1>Sign in <small>Welcome back!</small></h1>
<?php
echo $this->html->div(