From 10836461b90954c523c209974829b796cff59020 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Mon, 16 Dec 2013 22:40:53 -0500 Subject: [PATCH] And we have login! --- modules/login.php | 1 + modules/user/authenticate.php | 47 +++++++++++++++++++++++++++++++++++ templates/login.phtml | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 modules/user/authenticate.php diff --git a/modules/login.php b/modules/login.php index 273f87e..1578df8 100644 --- a/modules/login.php +++ b/modules/login.php @@ -2,6 +2,7 @@ class login extends AnonymousModule { + } ?> diff --git a/modules/user/authenticate.php b/modules/user/authenticate.php new file mode 100644 index 0000000..bda6f16 --- /dev/null +++ b/modules/user/authenticate.php @@ -0,0 +1,47 @@ + 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.'); + } +} + +?> diff --git a/templates/login.phtml b/templates/login.phtml index 8d7b009..dcec1b4 100644 --- a/templates/login.phtml +++ b/templates/login.phtml @@ -1,4 +1,4 @@ -
+

Sign in Welcome back!

html->div(