From 821f6d08f47778e430c1368ad9b3fd5c2c9d70fb Mon Sep 17 00:00:00 2001 From: Michael Francis Date: Sun, 10 Jul 2011 00:36:26 -0400 Subject: Moved signup stuff to it's own controller --- controllers/SignupController.php | 119 +++++++++++++++++++++++++++++++++++++++ views/signup/confirm.html.php | 1 + views/signup/index.html.php | 17 ++++++ views/users/confirm.html.php | 1 - views/users/signup.html.php | 17 ------ 5 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 controllers/SignupController.php create mode 100644 views/signup/confirm.html.php create mode 100644 views/signup/index.html.php delete mode 100644 views/users/confirm.html.php delete mode 100644 views/users/signup.html.php 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 @@ +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/views/signup/confirm.html.php b/views/signup/confirm.html.php new file mode 100644 index 0000000..cd0a6a7 --- /dev/null +++ b/views/signup/confirm.html.php @@ -0,0 +1 @@ +

Thanks for signing up. Please check your email to confirm your registration. If you lost you key click here to have it resent

diff --git a/views/signup/index.html.php b/views/signup/index.html.php new file mode 100644 index 0000000..5b26977 --- /dev/null +++ b/views/signup/index.html.php @@ -0,0 +1,17 @@ +styles($this->html->style("/css/signup.css")); +?> + + +Confirmation Link: Link + +flashMessage->output(); ?> + + +form->create($user); ?> + form->field('username'); ?> + form->field('newpass', array('type' => 'password', 'label' => 'password')); ?> + form->field('email'); ?> + form->submit('Signup!'); ?> +form->end(); ?> + \ No newline at end of file diff --git a/views/users/confirm.html.php b/views/users/confirm.html.php deleted file mode 100644 index cd0a6a7..0000000 --- a/views/users/confirm.html.php +++ /dev/null @@ -1 +0,0 @@ -

Thanks for signing up. Please check your email to confirm your registration. If you lost you key click here to have it resent

diff --git a/views/users/signup.html.php b/views/users/signup.html.php deleted file mode 100644 index 5b26977..0000000 --- a/views/users/signup.html.php +++ /dev/null @@ -1,17 +0,0 @@ -styles($this->html->style("/css/signup.css")); -?> - - -Confirmation Link: Link - -flashMessage->output(); ?> - - -form->create($user); ?> - form->field('username'); ?> - form->field('newpass', array('type' => 'password', 'label' => 'password')); ?> - form->field('email'); ?> - form->submit('Signup!'); ?> -form->end(); ?> - \ No newline at end of file -- cgit v1.2.3