[scu-smp] r280 committed - Complete - issue 42: Password recovery ...

2 views
Skip to first unread message

scu...@googlecode.com

unread,
Oct 11, 2010, 8:10:41 PM10/11/10
to scu...@googlegroups.com
Revision: 280
Author: sid.moradi
Date: Mon Oct 11 17:09:53 2010
Log: Complete - issue 42: Password recovery
http://code.google.com/p/scu-smp/issues/detail?id=42
http://code.google.com/p/scu-smp/source/detail?r=280

Added:
/trunk/smp-php/smp/command/public/ForgotPasswordCommand.php
/trunk/smp-php/smp/command/public/ResetPasswordCommand.php
/trunk/smp-php/smp/view/public/forgotPassword.php
/trunk/smp-php/smp/view/public/resetPassword.php
Modified:
/trunk/smp-php/smp/Constants.php
/trunk/smp-php/smp/command/public/LoginCommand.php
/trunk/smp-php/smp/service/UserService.php
/trunk/smp-php/smp/util/EmailTemplate.php
/trunk/smp-php/smp/view/public/login.php

=======================================
--- /dev/null
+++ /trunk/smp-php/smp/command/public/ForgotPasswordCommand.php Mon Oct 11
17:09:53 2010
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Created at 12/10/2010 9:29:24 AM
+ * smp_command_public_ForgotPasswordCommand
+ *
+ * @author <a href="mailto:smor...@scu.edu.au">Sid</a>
+ * @version 1.0
+ */
+require_once('smp/util/Validator.php');
+require_once('smp/service/UserService.php');
+require_once('smp/util/MailUtil.php');
+require_once('smp/util/EmailTemplate.php');
+require_once('smp/domain/Mail.php');
+
+class smp_command_public_ForgotPasswordCommand extends smp_command_Command
{
+
+ function doExecute(smp_controller_Request $request) {
+ $request->setTitle("Forget your Password ?");
+
+ if ($request->isPost()) {
+ $validator = new smp_util_Validator();
+ $validator->checkEmptiness("scuEmail", "SCU-Email address is
compulsory.");
+ $validator->checkWithRegex("scuEmail", "SCU-Email is not valid SCU
email account. For example (s.moradi.12@<b>scu.edu.au</b>) is
valid", "/^[a-z0-9A-Z_\\.\\-]+@scu.edu.au$/");
+
+ if ($validator->isValid()) {
+ $userService = new smp_service_UserService();
+ $scuEmail = $validator->getProperty('scuEmail');
+ $user = $userService->findUserByScuEmail($scuEmail);
+ if (is_null($user)) {
+ $validator->setError("scuEmail", "Sorry, we're unable to send a
password to this SCU email address ($scuEmail).");
+ }
+ if ($validator->isValid()) {
+
+ // Sending an Email
+ $mailUtil = new smp_util_MailUtil();
+ $mailBean = new smp_bean_Mail();
+ $mailBean->setRecipients($scuEmail);
+ $mailBean->setFrom(Constants::APPLICATION_EMAIL);
+ $mailBean->setTo($scuEmail);
+
$mailBean->setSubject(smp_util_EmailTemplate::subjectForForgotPassword());
+
$mailBean->setBody(smp_util_EmailTemplate::bodyForForgotPassword($user));
+
+ $result = $mailUtil->sendEmail($mailBean);
+
+ if (is_bool($result)) {
+ $request->addFeedback("We sent a password reset to this SCU email
address($scuEmail).");
+ // make textfield empty
+ $validator->setProperty('scuEmail', '');
+ } else {
+ $request->addError("Sending Email failed, Error:" . $result);
+ }
+ }
+ }
+ }
+ }
+
+ function doSecurity() {
+ $this->roles = array(Constants::ROLE_ANONYMOUS);
+ }
+}
=======================================
--- /dev/null
+++ /trunk/smp-php/smp/command/public/ResetPasswordCommand.php Mon Oct 11
17:09:53 2010
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Created at 12/10/2010 10:39:16 AM
+ * smp_command_public_ResetPasswordCommand
+ *
+ * @author <a href="mailto:smor...@scu.edu.au">Sid</a>
+ * @version 1.0
+ */
+require_once('smp/service/UserService.php');
+
+class smp_command_public_ResetPasswordCommand extends smp_command_Command {
+
+ function doExecute(smp_controller_Request $request) {
+ $scuEmail = $request->getProperty('scuEmail');
+ $key = $request->getProperty('key');
+
+ $userService = new smp_service_UserService();
+ $user = $userService->findUserByScuEmail($scuEmail);
+
+ if (is_null($user)) {
+ $request->addError('User account does not exists.');
+ } else {
+ if ($user->getPassword() != $key) {
+ $request->addError('Wrong key, password can not be reset.');
+ } else {
+ // auto login and redirect to edit profile
+ $user = $userService->findUserRoles($user);
+ smp_base_SessionRegistry::setUser($user);
+ $request->redirect('profile/editUser');
+ }
+ }
+
+
+ $request->setTitle('Reset Password');
+ }
+
+ function doSecurity() {
+ $this->roles = array(Constants::ROLE_ANONYMOUS);
+ }
+}
=======================================
--- /dev/null
+++ /trunk/smp-php/smp/view/public/forgotPassword.php Mon Oct 11 17:09:53
2010
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Created at 12/10/2010 9:32:14 AM
+ * smp/view/public/forgotPassword.php
+ *
+ * @author <a href="mailto:smor...@scu.edu.au">Sid</a>
+ * @version 1.0
+ */
+include('smp/view/common/header.php');
+require_once('smp/util/FormBuilder.php');
+
+$indent = " ";
+$objLoginForm = new smp_util_FormBuilder();
+$objLoginForm->setIndent($indent);
+$validator = VH::getValidator();
+print $objLoginForm->strIndent."<h1>Forget your password ?</h1>\r\n";
+
+if ($objLoginForm->isPost()) {
+ $objLoginForm->setValues($validator->getValues());
+ if ($validator->isInvalid()) {
+ $objLoginForm->setErrors($validator->getErrors());
+ print $validator->getErrorMessagesString($objLoginForm->strIndent);
+ }
+}
+
+print $objLoginForm->open("passwordRecoveryForm");
+print $objLoginForm->hidden("cmd", "public/forgotPassword");
+print $objLoginForm->note("grid_12", "Please type your SCU email
address.");
+print $objLoginForm->label("scuEmail", "SCU email:","grid_2",true);
+print
$objLoginForm->textBox("scuEmail", "","",1,"grid_10","input",20,"text");
+print $objLoginForm->label("", "&nbsp;", "grid_2");
+print $objLoginForm->button("submit", "Send ","submit", 3, "grid_10");
+print $objLoginForm->close();
+
+include('smp/view/common/footer.php');
=======================================
--- /dev/null
+++ /trunk/smp-php/smp/view/public/resetPassword.php Mon Oct 11 17:09:53
2010
@@ -0,0 +1,13 @@
+<?php
+/**
+ * Created at 12/10/2010 10:58:18 AM
+ * smp/view/public/resetPassword.php
+ *
+ * @author <a href="mailto:smor...@scu.edu.au">Sid</a>
+ * @version 1.0
+ */
+include('smp/view/common/header.php');
+
+print "<h1>Reset Password</h1>";
+
+include('smp/view/common/footer.php');
=======================================
--- /trunk/smp-php/smp/Constants.php Fri Oct 1 01:30:37 2010
+++ /trunk/smp-php/smp/Constants.php Mon Oct 11 17:09:53 2010
@@ -8,6 +8,16 @@
*/
class Constants {

+ // Application root domain address
+ const APPLICATION_DOMAIN = 'http://infotech.scu.edu.au/~smp/';
+
+ // Admin email address
+ const ADMIN_EMAIL = 'smp_...@scu.edu.au';
+ const APPLICATION_EMAIL = 's...@scu.edu.au';
+
+ // Image upload directory
+ const IMAGE_UPLOAD_DIR = 'static/images/profile/';
+
// Exsiting Role in SMP application
const ROLE_ANONYMOUS = 'ROLE_ANONYMOUS';
const ROLE_ADMIN = 'ROLE_ADMIN';
@@ -22,38 +32,16 @@
const TABLE_LOG = 'smp_log';
const TABLE_COORDINATOR = 'smp_coordinator';
const TABLE_CAMPUS = 'smp_campus';
-
- // Existing Account status for students in SMP application
- const AS_NEW_MENTOR = 'AS_NEW_MENTOR';
- const AS_NEW_MENTEE = 'AS_NEW_MENTEE';
- const AS_MATCHED_MENTOR = 'AS_MATCHED_MENTOR';
- const AS_MATCHED_MENTEE = 'AS_MATCHED_MENTEE';
- const AS_EXPIRED_MENTOR = 'AS_EXPIRED_MENTOR';
- const AS_EXPIRED_MENTEE = 'AS_EXPIRED_MENTEE';
- const AS_TRAINED_MENTOR = 'AS_TRAINED_MENTOR';
-
+
// Messaging constants
const MESSAGE_MENTOR = 'MESSAGE_MENTOR';
const MESSAGE_MENTEE = 'MESSAGE_MENTEE';
- const MESSAGE_MANAGER = 'MESSAGE_MANAGER';
- const MESSAGE_COORDINATOR = 'MESSAGE_COORDINATOR';
-
const MS_FOR_MENTOR = 'MS_FOR_MENTOR';
const MS_FOR_MENTEE = 'MS_FOR_MENTEE';
- const MS_FOR_MANAGER = 'MS_FOR_MANAGER';
- const MS_FOR_COORDINATOR = 'MS_FOR_COORDINATOR';
-
+
+ // Actions constants
const ACTION = 'ACTION';
const ACTION_SEARCH = 'ACTION_SEARCH';
const ACTION_UPDATE = 'ACTION_UPDATE';
const ACTION_SUBMIT = 'ACTION_SUBMIT';
-
- // Image upload directory
- const IMAGE_UPLOAD_DIR = 'static/images/profile/';
-
- // Admin email address
- const ADMIN_EMAIL = 'smp_...@scu.edu.au';
- const APPLICATION_EMAIL = 's...@scu.edu.au';
- // Application root domain address
- const APPLICATION_DOMAIN = 'http://infotech.scu.edu.au/~smp/';
-}
+}
=======================================
--- /trunk/smp-php/smp/command/public/LoginCommand.php Fri Sep 10 00:00:54
2010
+++ /trunk/smp-php/smp/command/public/LoginCommand.php Mon Oct 11 17:09:53
2010
@@ -7,8 +7,8 @@
*/
require_once('smp/util/Validator.php');
require_once('smp/service/UserService.php');
-require_once('smp/mapper/UserMapper.php');
require_once('smp/base/SessionRegistry.php');
+
class smp_command_public_LoginCommand extends smp_command_Command {

function doExecute(smp_controller_Request $request) {
=======================================
--- /trunk/smp-php/smp/service/UserService.php Fri Oct 1 01:30:37 2010
+++ /trunk/smp-php/smp/service/UserService.php Mon Oct 11 17:09:53 2010
@@ -42,8 +42,8 @@
* @param $scuEmail
* @return smp_domain_User
*/
- function findUserByScuEmail($username) {
- return $this->userMapper->findUserByScuEmail($username);
+ function findUserByScuEmail($scuEmail) {
+ return $this->userMapper->findUserByScuEmail($scuEmail);
}

/**
=======================================
--- /trunk/smp-php/smp/util/EmailTemplate.php Mon Sep 27 00:24:51 2010
+++ /trunk/smp-php/smp/util/EmailTemplate.php Mon Oct 11 17:09:53 2010
@@ -62,4 +62,16 @@
$body .=Constants::APPLICATION_DOMAIN."index.php?cmd=public/login";
return $body;
}
-}
+
+ static function subjectForForgotPassword(){
+ return "Forgot your Password ?";
+ }
+
+ static function bodyForForgotPassword($user){
+ $body="Dear " . $user->getUsername() . "\n\n";
+ $body .="Please click below url for reset your password.\n";
+
$body .=Constants::APPLICATION_DOMAIN."index.php?cmd=public/resetPassword&scuEmail=".$user->getScuEmail()."&key=".$user->getPassword()."\n\n";
+ $body .="Sent from SMP application.\n";
+ return $body;
+ }
+}
=======================================
--- /trunk/smp-php/smp/view/public/login.php Thu Jul 29 21:45:50 2010
+++ /trunk/smp-php/smp/view/public/login.php Mon Oct 11 17:09:53 2010
@@ -33,13 +33,6 @@
print $objLoginForm->button("submit", "Login","submit", 3, "grid_11");
print $objLoginForm->close();

-print $objLoginForm->strIndent."<br /><p> These Username / Password for
testing:</p>\r\n";
-print $objLoginForm->strIndent."<ul>\r\n";
-print $objLoginForm->strIndent." <li>admin / admin <span
style=\"padding-left: 45px;\"> Role Admin</span></li>\r\n";
-print $objLoginForm->strIndent." <li>rob / rob <span
style=\"padding-left: 80px;\"> Role Manager</span></li>\r\n";
-print $objLoginForm->strIndent." <li>jo / jo <span style=\"padding-left:
95px;\">Role Coordinator</span></li>\r\n";
-print $objLoginForm->strIndent." <li>jiya / jiya <span
style=\"padding-left: 75px;\">Role Mentor</span></li>\r\n";
-print $objLoginForm->strIndent." <li>lucy / lucy <span
style=\"padding-left: 50px;\">Role Mentee</span></li>\r\n";
-print $objLoginForm->strIndent."</ul>\r\n";
+print $objLoginForm->strIndent."<div style=\"padding-top:110px;
padding-left:10px;\"><a href=\"index.php?cmd=public/forgotPassword\">Forgot
Password?</a></div>\r\n";

include("smp/view/common/footer.php");

Reply all
Reply to author
Forward
0 new messages