Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit ba7fc08

Browse files
author
Charles Marion
committed
Enh: added forgot my password (bug: 9599)
1 parent 68e28a3 commit ba7fc08

File tree

7 files changed

+144
-1
lines changed

7 files changed

+144
-1
lines changed

core/AppController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ public function preDispatch()
152152
Zend_Loader::loadClass("JsonComponent",BASE_PATH.'/core/controllers/components');
153153
} // end preDispatch()
154154

155+
156+
function getServerURL()
157+
{
158+
$currentPort="";
159+
$prefix = "http://";
160+
161+
if($_SERVER['SERVER_PORT']!=80 && $_SERVER['SERVER_PORT']!=443)
162+
{
163+
$currentPort=":".$_SERVER['SERVER_PORT'];
164+
}
165+
if($_SERVER['SERVER_PORT']==443 || ( isset($_SERVER['HTTPS']) && !empty( $_SERVER['HTTPS'])))
166+
{
167+
$prefix = "https://";
168+
}
169+
return $prefix.$_SERVER['SERVER_NAME'].$currentPort;
170+
}
171+
155172

156173
public function postDispatch()
157174
{

core/controllers/UserController.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,76 @@ function init()
1818
}
1919
} // end init()
2020

21+
22+
/** Recover the password (ajax) */
23+
function recoverpasswordAction()
24+
{
25+
if($this->logged)
26+
{
27+
throw new Zend_Exception('Shouldn\'t be logged in');
28+
}
29+
$this->_helper->layout->disableLayout();
30+
$email=$this->_getParam('email');
31+
if(isset($email))
32+
{
33+
$this->_helper->viewRenderer->setNoRender();
34+
$user=$this->User->getByEmail($email);
35+
36+
// Check if the email is already registered
37+
if(!$user)
38+
{
39+
echo JsonComponent::encode(array(false,$this->t('Unable to find e-mail.')));
40+
}
41+
42+
// Create a new password
43+
$keychars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
44+
$length = 10;
45+
46+
function make_seed_recoverpass()
47+
{
48+
list($usec, $sec) = explode(' ', microtime());
49+
return (float) $sec + ((float) $usec * 100000);
50+
}
51+
srand(make_seed_recoverpass());
52+
53+
$pass = "";
54+
$max=strlen($keychars)-1;
55+
for ($i=0;$i<=$length;$i++)
56+
{
57+
$pass .= substr($keychars, rand(0, $max), 1);
58+
}
59+
$encrypted = md5($pass);
60+
61+
$passwordPrefix=Zend_Registry::get('configGlobal')->password->prefix;
62+
if(isset($passwordPrefix)&&!empty($passwordPrefix))
63+
{
64+
$pass=$passwordPrefix.$pass;
65+
}
66+
67+
$user->setPassword(md5($pass));
68+
69+
70+
// Send the email
71+
$url = $this->getServerURL().$this->view->webroot;
72+
73+
$text = "Hello,<br><br> You have asked for a new password for MIDAS.<br>";
74+
$text .= "Please go to this page to login into MIDAS and change your password:<br>";
75+
$text .= "<a href=\"$url\">$url</a><br>";
76+
$text .= "Your new password is: ".$pass."<br>";
77+
$text .= "<br><br>Generated by MIDAS";
78+
79+
if( @mail("$email", "MIDAS: Password request","$text","From: \nReply-To: no-reply\nX-Mailer: PHP/" . phpversion()."\nMIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1"))
80+
{
81+
$this->User->save($user);
82+
echo JsonComponent::encode(array(true,$this->t('An Email has been sent to').' '.$email));
83+
}
84+
else
85+
{
86+
$alert = "Problem during process !";
87+
echo JsonComponent::encode(array(false,$this->t('Problem during process !')));
88+
}
89+
}
90+
} // end recoverpassword
2191

2292
/** logout an user*/
2393
function logoutAction()

core/public/css/user/user.recoverpassword.css

Whitespace-only changes.

core/public/js/user/user.login.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ $('form#loginForm').submit(function(){
88
return valid;
99
});
1010

11+
$('a#forgotPasswordLink').click(function()
12+
{
13+
loadDialog("forgotpassword","/user/recoverpassword");
14+
showDialog("Recover Password");
15+
});
16+
1117
$('form#loginForm input[name=submit]').click(function(){
1218
$("form#loginForm div.loginError img").show();
1319
$("form#loginForm div.loginError span").hide();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
$('#recoverPasswordForm').ajaxForm( {beforeSubmit: validateRecoverPassword, success: successRecoverPassword} );
2+
3+
4+
function validateRecoverPassword(formData, jqForm, options) {
5+
6+
var form = jqForm[0];
7+
if (form.email.value.length<1)
8+
{
9+
createNotive('Error email',4000);
10+
return false;
11+
}
12+
}
13+
14+
function successRecoverPassword(responseText, statusText, xhr, form)
15+
{
16+
jsonResponse = jQuery.parseJSON(responseText);
17+
if(jsonResponse==null)
18+
{
19+
createNotive('Error',4000);
20+
return;
21+
}
22+
if(jsonResponse[0])
23+
{
24+
createNotive(jsonResponse[1],4000);
25+
$( "div.MainDialog" ).dialog("close");
26+
}
27+
else
28+
{
29+
createNotive(jsonResponse[1],4000);
30+
}
31+
}

core/views/user/login.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/u
2626
<tr>
2727
<td><?php echo $this->form['remerberMe']?>
2828
<label id="rememberMeText" for="remerberMe"><?php echo $this->t("Remember Me")?></label></td>
29-
<td> <a class="registerLink"> <?php echo $this->t("Register")?></a>, <a href="#"><?php echo $this->t("Forgot your password")?>?</a></td>
29+
<td> <a class="registerLink"> <?php echo $this->t("Register")?></a>, <a id='forgotPasswordLink' href="#"><?php echo $this->t("Forgot your password")?>?</a></td>
3030
<td></td>
3131
</tr>
3232
</table>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/** AJAX Action !!!! */
3+
echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/jquery/jquery.form.js"></script>';
4+
echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/user/user.recoverpassword.js?'.time().'"></script>';
5+
?>
6+
7+
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/user/user.recoverpassword.css" />
8+
9+
<form id="recoverPasswordForm" class="genericForm" method="POST" action="<?php echo $this->webroot?>/user/recoverpassword">
10+
<h4><?php echo $this->t('Please enter your e-mail address.');?></h4>
11+
<div >
12+
<label for="email"><?php echo $this->t("E-mail")?></label>
13+
<input type='text' name="email"/>
14+
</div>
15+
<br/>
16+
<div>
17+
<input type='submit' name='createFolder' value='<?php echo $this->t('Recover')?>'/>
18+
</div>
19+
</form>

0 commit comments

Comments
 (0)