And we have login!
This commit is contained in:
parent
3e769286d2
commit
10836461b9
3 changed files with 49 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
class login extends AnonymousModule
|
class login extends AnonymousModule
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
47
modules/user/authenticate.php
Normal file
47
modules/user/authenticate.php
Normal 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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -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>
|
<h1>Sign in <small>Welcome back!</small></h1>
|
||||||
<?php
|
<?php
|
||||||
echo $this->html->div(
|
echo $this->html->div(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue