Got the log out working.

This commit is contained in:
Josh Sherman 2013-12-16 22:17:39 -05:00
parent 74257193f1
commit 34c41764b5
4 changed files with 26 additions and 19 deletions

View file

@ -27,7 +27,7 @@ class User extends RedisModel
return false; return false;
} }
public static function getCookie() public function getCookie()
{ {
if (isset($_COOKIE['__auth'])) if (isset($_COOKIE['__auth']))
{ {
@ -39,9 +39,10 @@ class User extends RedisModel
public static function isAuthenticated() public static function isAuthenticated()
{ {
if ($cookie = self::getCookie()) $user = new self();
if ($cookie = $user->getCookie())
{ {
$user = new self();
$auth_token = $user->getAuth($cookie['uid']); $auth_token = $user->getAuth($cookie['uid']);
return $auth_token === $cookie['token']; return $auth_token === $cookie['token'];

View file

@ -7,6 +7,8 @@ class logout extends UserModule
$user = new User(); $user = new User();
$user->setAuth($user->getAuthenticated('uid'), $user->generateToken()); $user->setAuth($user->getAuthenticated('uid'), $user->generateToken());
setcookie('__auth', '', time() - Time::YEAR, '/');
Browser::goHome(); Browser::goHome();
} }
} }

View file

@ -4,33 +4,37 @@
echo $this->html->div( echo $this->html->div(
array('class' => 'form-group'), array('class' => 'form-group'),
$this->html->inputEmail(array( $this->html->inputEmail(array(
'label' => 'Email Address', 'label' => 'Email Address',
'name' => 'email', 'name' => 'email',
'class' => 'form-control input-lg email required', 'class' => 'form-control input-lg email required',
'placeholder' => 'Your email address, double check it!', 'placeholder' => 'Your email address, double check it!',
'autocomplete' => 'off',
'autofocus' => 'autofocus',
)) ))
); );
echo $this->html->div( echo $this->html->div(
array('class' => 'form-group'), array('class' => 'form-group'),
$this->html->input(array( $this->html->input(array(
'label' => 'Username', 'label' => 'Username',
'name' => 'username', 'name' => 'username',
'class' => 'form-control input-lg required', 'class' => 'form-control input-lg required',
'minlength' => 4, 'minlength' => 4,
'maxlength' => 50, 'maxlength' => 50,
'placeholder' => 'At least four letters or numbers', 'placeholder' => 'At least four letters or numbers',
'autocomplete' => 'off',
)) ))
); );
echo $this->html->div( echo $this->html->div(
array('class' => 'form-group'), array('class' => 'form-group'),
$this->html->inputPassword(array( $this->html->inputPassword(array(
'label' => 'Password', 'label' => 'Password',
'name' => 'password', 'name' => 'password',
'class' => 'form-control input-lg required', 'class' => 'form-control input-lg required',
'minlength' => 8, 'minlength' => 8,
'placeholder' => 'Use symbols along with letters and numbers', 'placeholder' => 'Use symbols along with letters and numbers',
'autocomplete' => 'off',
)) ))
); );
?> ?>

View file

@ -1,4 +1,4 @@
<form role="form" class="row col-xs-12 col-sm-6 col-sm-offset-3" method="post"> <form role="form" class="row col-xs-12 col-sm-6 col-sm-offset-3" method="post" action="/user/authenticate">
<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(