diff options
-rw-r--r-- | .gitmodules | 6 | ||||
-rw-r--r-- | config/bootstrap.php | 4 | ||||
-rw-r--r-- | config/bootstrap/auth.php | 24 | ||||
-rw-r--r-- | config/bootstrap/connections.php | 26 | ||||
-rw-r--r-- | config/bootstrap/libraries.php | 5 | ||||
-rw-r--r-- | controllers/SignupController.php | 119 | ||||
-rw-r--r-- | controllers/UsersController.php | 84 | ||||
m--------- | libraries/li3_swiftmailer | 0 | ||||
m--------- | libraries/lithium | 0 | ||||
m--------- | libraries/swiftmailer | 0 | ||||
-rw-r--r-- | models/Anime.php | 2 | ||||
-rw-r--r-- | models/Kdrama.php | 2 | ||||
-rw-r--r-- | models/User.php | 8 | ||||
-rw-r--r-- | models/confirmKey.php | 2 | ||||
-rw-r--r-- | setup/otakuhub_2011-07-10.sql | 83 | ||||
-rw-r--r-- | views/signup/confirm.html.php (renamed from views/users/confirm.html.php) | 0 | ||||
-rw-r--r-- | views/signup/index.html.php (renamed from views/users/signup.html.php) | 0 |
17 files changed, 243 insertions, 122 deletions
diff --git a/.gitmodules b/.gitmodules index f89b821..4aac635 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,9 @@ [submodule "libraries/lithium"] path = libraries/lithium url = git://github.com/UnionOfRAD/lithium.git +[submodule "libraries/li3_swiftmailer"] + path = libraries/li3_swiftmailer + url = https://github.com/greut/li3_swiftmailer.git +[submodule "libraries/swiftmailer"] + path = libraries/swiftmailer + url = https://github.com/swiftmailer/swiftmailer.git diff --git a/config/bootstrap.php b/config/bootstrap.php index 1ced565..bce1bc7 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -77,6 +77,10 @@ require __DIR__ . '/bootstrap/action.php'; */ require __DIR__ . '/bootstrap/media.php'; +//For the mail setup stuff +require __DIR__ . '/bootstrap/mail.php'; + + /** * This file configures console filters and settings, specifically output behavior and coloring. */ diff --git a/config/bootstrap/auth.php b/config/bootstrap/auth.php index 87ee787..67c3143 100644 --- a/config/bootstrap/auth.php +++ b/config/bootstrap/auth.php @@ -24,25 +24,11 @@ Auth::config(array( //'scope' => array('active' => 'true'), //The active field must be true otherwise they can't auth, though we need //to eventually send them to a page that explains they are banned. 'session' => array('options' => array('name' => 'default')), - 'filters' => array( - 'password' => function($password) - { - return $password; //prevents li3 from hashing the password before hand. - }, - function($data) { - if(isset($data['username'])) - { - //Get the user from the database - $user = User::find('first', array('conditions' => array('username' => $data['username']))); - //Hash the submitted password with the stored salt. - $data['password'] = Password::hash($data['password'], $user->salt); - } - return $data; - } - ) - ) - ) -); + 'validators' => array( + 'password' => function($form, $data) { + return password::check($form, $data); + })) +)); $secret = "cake"; diff --git a/config/bootstrap/connections.php b/config/bootstrap/connections.php index a9355e6..645e587 100644 --- a/config/bootstrap/connections.php +++ b/config/bootstrap/connections.php @@ -38,9 +38,21 @@ use lithium\data\Connections; /** + * Uncomment this configuration to use MySQL as your default database. + */ +Connections::add('default', array( + 'type' => 'database', + 'adapter' => 'MySql', + 'host' => '127.0.0.1', + 'login' => 'otakuhub', + 'password' => 'otakuhub', + 'database' => 'otakuhub' + )); + +/** * Uncomment this configuration to use MongoDB as your default database. */ - Connections::add('default', array( + Connections::add('mongo', array( 'type' => 'MongoDb', 'host' => 'localhost', 'database' => 'otakuhub', @@ -57,16 +69,6 @@ use lithium\data\Connections; // 'database' => 'my_app' // )); -/** - * Uncomment this configuration to use MySQL as your default database. - */ -// Connections::add('default', array( -// 'type' => 'database', -// 'adapter' => 'MySql', -// 'host' => 'localhost', -// 'login' => 'root', -// 'password' => '', -// 'database' => 'my_app' -// )); + ?>
\ No newline at end of file diff --git a/config/bootstrap/libraries.php b/config/bootstrap/libraries.php index e013ddc..e4d5ff4 100644 --- a/config/bootstrap/libraries.php +++ b/config/bootstrap/libraries.php @@ -124,4 +124,9 @@ Libraries::add('app', array('default' => true)); // Libraries::add('li3_docs'); Libraries::add('li3_flash_message'); Libraries::add('li3_paginate'); + +//Swiftmail integration +Libraries::add('li3_swiftmailer'); + + ?> diff --git a/controllers/SignupController.php b/controllers/SignupController.php new file mode 100644 index 0000000..6a9538a --- /dev/null +++ b/controllers/SignupController.php @@ -0,0 +1,119 @@ +<?php + +namespace app\controllers; + +use li3_swiftmailer\mailer\Transports; +use li3_swiftmailer\mailer\Message; +use app\models\User; +use app\models\confirmKey; + + +class SignupController extends \lithium\action\Controller { + public $publicActions = array('index','confirm', 'cancel' ); + + public function index() { + $user = null; + //If the request isn't empty + if($this->request->data) + { + //Create a user from the data + $user = User::Create($this->request->data); + + //The user isn't active until after they confirm. + $user->confirmed = false; + $user->active = false; + $user->joinedOn = Date("F j, Y, g:i a"); + + //By default save does validation at the same time, + //If there are errors its stuffs them into the $user->_erorrs variable, + //Accessible from $user->errors(), this is automatically passed to the view. + if ($user->save()) + { + //Generate a confirmation key for the user + $key = confirmKey::Create(array('key' => confirmKey::generate($user->email), 'username' => $user->username)); + + //Save it to the database + $key->save(); + + //Create the link for the user to click. + $link = $this->html->link('Here', array('controller' => 'signup', + 'action' => 'confirm', + 'args' => $key->key)); + + + $mailer = Transports::adapter('default'); + $message = Message::newInstance() + ->setSubject('Welcome to OtakuHUB') + ->setFrom(array('admin@weareotak.us' => 'OtakuHUB signup team')) + ->setTo(array($user->email)) + ->setBody("Hey! Wecome to our awesome site! Click $link to get started"); + + $result = $mailer->send($message); + + + return compact('key', 'link', 'user'); + } + } + //If there are validation errors, send them back to the form + return compact('user'); + } + + public function confirm($key = null) { + //Situation one + //They have a key + if (!(empty($key))) + { + //Find the key in the database + $foundKey = confirmKey::find('first', array('conditions' => compact('key'))); + + //If the key exists + if($foundKey) + { + //Find that user in the database + $foundUser = User::find('first', array('conditions' => array("username" => $foundKey->username))); + $valid = ($foundUser != NULL); + + //Set the users account active and confirmed. + $foundUser->confirmed = true; + $foundUser->active = true; + + //If the user is saved sucsessfully, + if($foundUser->save(null, array('validate' => false))) + { + /* If the save is sucsessful we are done */ + //Delete their key, + $foundKey->delete(); + + //Send them to the homepage (probably login though) + $this->redirect("/"); + + } + else + { + FlashMessage::set("There was an error."); + } + + } + else + { + //Otherwise + FlashMessage::set("There was an error finding the key."); + return; + } + } + } + + public function cancel($key = null) { + $thisKey = Key::find('first', array('conditions' => compact('key'))); + + //If the key exists + if ($thisKey) + { + $user = User::find('first', array('conditions' => array('username' => $thisKey->username))); + + $user->delete(); + $thisKey->delete(); + } + return; + } +}
\ No newline at end of file diff --git a/controllers/UsersController.php b/controllers/UsersController.php index e6e0675..57d7efe 100644 --- a/controllers/UsersController.php +++ b/controllers/UsersController.php @@ -222,42 +222,6 @@ class UsersController extends \lithium\action\Controller { } } - - - public function signup() - { - $user = null; - //If the request isn't empty - if($this->request->data) - { - //Create a user from the data - $user = User::Create($this->request->data); - - //The user isn't active until after they confirm. - $user->confirmed = false; - $user->active = false; - $user->joinedOn = new MongoDate(); - - //By default save does validation at the same time, - //If there are errors its stuffs them into the $user->_erorrs variable, - //Accessible from $user->errors(), this is automatically passed to the view. - if ($user->save()) - { - //Generate a confirmation key for the user - $key = confirmKey::Create(array('key' => confirmKey::generate($user->email), 'username' => $user->username)); - - //Save it to the database - $key->save(); - - //For testing, we return the link to the view, so they can click it, - //This will be replaced with an email in production - $link = "/users/confirm"; - return compact('key', 'link', 'user'); - } - } - return compact('user'); - } - /* If the user is valid, but not confirmed, tell the user they haven't confirmed, @@ -430,54 +394,6 @@ class UsersController extends \lithium\action\Controller { } - public function confirm($key = null) - { - //Situation one - //They have a key - if (!(empty($key))) - { - //Find the key in the database - $foundKey = confirmKey::find('first', array('conditions' => compact('key'))); - - //If the key exists - if($foundKey != NULL) - { - /* Note: foundKey->validates() does the same check, but it was added incase more validation is needed */ - //Find that user in the database - $foundUser = User::find('first', array('conditions' => array("username" => $foundKey->username))); - $valid = ($foundUser != NULL); - - //Set the users account active and confirmed. - $foundUser->confirmed = true; - $foundUser->active = true; - - //If the user is saved sucsessfully, - if($foundUser->save(null, array('validate' => false))) - { - /* If the save is sucsessful we are done */ - //Delete their key, - $foundKey->delete(); - - //Send them to the homepage (probably login though) - $this->redirect("/"); - - } - else - { - FlashMessage::set("There was an error."); - } - - } - else - { - //Otherwise - FlashMessage::set("There was an error finding the key."); - return; - } - } - } - - public function step2() { //Check that step1 is completed sucsessfully, diff --git a/libraries/li3_swiftmailer b/libraries/li3_swiftmailer new file mode 160000 +Subproject a5057ba921bb2c89e99b74faf3254ffb68d93d6 diff --git a/libraries/lithium b/libraries/lithium -Subproject 463e0743b7a1e01dba9e73f33c42609175dbcc5 +Subproject a8fd7e546b666c33b0738cfd5f0970aa7c84043 diff --git a/libraries/swiftmailer b/libraries/swiftmailer new file mode 160000 +Subproject dd12451308198f0a8576a51ed12c02258c0b8ef diff --git a/models/Anime.php b/models/Anime.php index 2798a43..4543826 100644 --- a/models/Anime.php +++ b/models/Anime.php @@ -3,7 +3,7 @@ namespace app\models; class Anime extends \lithium\data\Model { - protected $_meta = array('key' => '_id', 'source' => 'anime'); + protected $_meta = array('key' => '_id', 'source' => 'anime', 'connection' => 'mongo'); public static function search($query, $page = 1, $by = 'title') { diff --git a/models/Kdrama.php b/models/Kdrama.php index 9d3ddf7..f1eee22 100644 --- a/models/Kdrama.php +++ b/models/Kdrama.php @@ -3,7 +3,7 @@ namespace app\models; class Kdrama extends \lithium\data\Model { - protected $_meta = array('key' => '_id', 'source' => 'kdrama'); + protected $_meta = array('key' => '_id', 'source' => 'kdrama', 'connection' => 'mongo'); public static function search($query, $page = 1, $by = 'title') { diff --git a/models/User.php b/models/User.php index bf9eec2..a1c8f8d 100644 --- a/models/User.php +++ b/models/User.php @@ -10,12 +10,12 @@ use \lithium\security\Password; class User extends \lithium\data\Model { //To bypass mongo bug - protected $_meta = array('key' => '_id'); - protected $_schema = array('_id' => array('type' => 'id'), + //protected $_meta = array('key' => '_id'); + /*protected $_schema = array('_id' => array('type' => 'id'), 'feed' => array('type'=>'string', 'array' => true), 'animelist' => array('type' => 'object', 'array' => true), 'mangalist' => array('type' => 'object', 'array' => true) - ); + );*/ public static function __init() { @@ -338,7 +338,7 @@ class User extends \lithium\data\Model { //Hash their password. $data['password'] = Password::hash($entity->newpass, $salt); - $data['salt'] = $salt; + $data['pepper'] = $salt; unset($entity->newpass); } //If the entity doesn't exist or if the password password has been modified diff --git a/models/confirmKey.php b/models/confirmKey.php index 6a941ad..9348021 100644 --- a/models/confirmKey.php +++ b/models/confirmKey.php @@ -11,7 +11,7 @@ class confirmKey extends \lithium\data\Model { public $secret = "marshmellows"; //I don't know why either? //To bypass mongo bug - protected $_meta = array('key' => '_id'); + //protected $_meta = array('key' => '_id'); //array('isValidKey', 'message' => 'Key does not exist'); public static function __init() diff --git a/setup/otakuhub_2011-07-10.sql b/setup/otakuhub_2011-07-10.sql new file mode 100644 index 0000000..3e2a23a --- /dev/null +++ b/setup/otakuhub_2011-07-10.sql @@ -0,0 +1,83 @@ +# ************************************************************ +# Sequel Pro SQL dump +# Version 3348 +# +# http://www.sequelpro.com/ +# http://code.google.com/p/sequel-pro/ +# +# Host: localhost (MySQL 5.5.14) +# Database: otakuhub +# Generation Time: 2011-07-10 00:34:13 -0400 +# ************************************************************ + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + + +# Dump of table anime_list +# ------------------------------------------------------------ + +CREATE TABLE `anime_list` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + + + +# Dump of table confirm_keys +# ------------------------------------------------------------ + +CREATE TABLE `confirm_keys` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(12) NOT NULL DEFAULT '', + `username` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; + + + +# Dump of table feed +# ------------------------------------------------------------ + +CREATE TABLE `feed` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `userid` int(11) DEFAULT NULL, + `action_type` int(11) DEFAULT NULL, + `media_type` int(11) DEFAULT NULL, + `data` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + + + +# Dump of table users +# ------------------------------------------------------------ + +CREATE TABLE `users` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `username` varchar(255) NOT NULL DEFAULT '', + `password` varchar(255) NOT NULL DEFAULT '', + `pepper` varchar(255) DEFAULT NULL, + `active` tinyint(1) NOT NULL, + `email` varchar(255) DEFAULT NULL, + `level` varchar(255) DEFAULT NULL, + `joined` date DEFAULT NULL, + `last_login` date DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; + + + + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/views/users/confirm.html.php b/views/signup/confirm.html.php index cd0a6a7..cd0a6a7 100644 --- a/views/users/confirm.html.php +++ b/views/signup/confirm.html.php diff --git a/views/users/signup.html.php b/views/signup/index.html.php index 5b26977..5b26977 100644 --- a/views/users/signup.html.php +++ b/views/signup/index.html.php |