Added signals when the user updates his password.

This commit is contained in:
Loic d'Anterroches 2008-12-01 13:35:17 +01:00
parent 9c5156e6ef
commit d1911339d7
4 changed files with 71 additions and 4 deletions

View File

@ -141,6 +141,28 @@ class IDF_Form_RegisterConfirmation extends Pluf_Form
$this->_user->staff = false; $this->_user->staff = false;
if ($commit) { if ($commit) {
$this->_user->update(); $this->_user->update();
/**
* [signal]
*
* Pluf_User::passwordUpdated
*
* [sender]
*
* IDF_Form_RegisterConfirmation
*
* [description]
*
* This signal is sent when the user updated his
* password from his account page.
*
* [parameters]
*
* array('user' => $user)
*
*/
$params = array('user' => $this->_user);
Pluf_Signal::send('Pluf_User::passwordUpdated',
'IDF_Form_RegisterConfirmation', $params);
} }
return $this->_user; return $this->_user;
} }

View File

@ -88,12 +88,39 @@ class IDF_Form_UserAccount extends Pluf_Form
throw new Exception(__('Cannot save the model from an invalid form.')); throw new Exception(__('Cannot save the model from an invalid form.'));
} }
unset($this->cleaned_data['password2']); unset($this->cleaned_data['password2']);
$update_pass = false;
if (strlen($this->cleaned_data['password']) == 0) { if (strlen($this->cleaned_data['password']) == 0) {
unset($this->cleaned_data['password']); unset($this->cleaned_data['password']);
} else {
$update_pass = true;
} }
$this->user->setFromFormData($this->cleaned_data); $this->user->setFromFormData($this->cleaned_data);
if ($commit) { if ($commit) {
$this->user->update(); $this->user->update();
if ($update_pass) {
/**
* [signal]
*
* Pluf_User::passwordUpdated
*
* [sender]
*
* IDF_Form_UserAccount
*
* [description]
*
* This signal is sent when the user updated his
* password from his account page.
*
* [parameters]
*
* array('user' => $user)
*
*/
$params = array('user' => $this->user);
Pluf_Signal::send('Pluf_User::passwordUpdated',
'IDF_Form_UserAccount', $params);
}
} }
return $this->user; return $this->user;
} }

View File

@ -41,6 +41,7 @@ class IDF_Views_User
// As the password is salted, we can directly take the sha1 of // As the password is salted, we can directly take the sha1 of
// the salted password. // the salted password.
$api_key = sha1($request->user->password); $api_key = sha1($request->user->password);
$ext_pass = substr(sha1($request->user->password.Pluf::f('secret_key')), 0, 8);
$params = array('user' => $request->user); $params = array('user' => $request->user);
if ($request->method == 'POST') { if ($request->method == 'POST') {
$form = new IDF_Form_UserAccount($request->POST, $params); $form = new IDF_Form_UserAccount($request->POST, $params);
@ -56,6 +57,7 @@ class IDF_Views_User
return Pluf_Shortcuts_RenderToResponse('idf/user/myaccount.html', return Pluf_Shortcuts_RenderToResponse('idf/user/myaccount.html',
array('page_title' => __('Your Account'), array('page_title' => __('Your Account'),
'api_key' => $api_key, 'api_key' => $api_key,
'ext_pass' => $ext_pass,
'form' => $form), 'form' => $form),
$request); $request);
} }

View File

@ -40,10 +40,16 @@
{$form.f.password2|unsafe} {$form.f.password2|unsafe}
</td> </td>
</tr> </tr>
<tr> <tr class="pass-info" id="extra-password">
<th>{trans 'Extra password'}:</th>
<td><span class="mono">{$ext_pass}</span><br />
<span class="helptext">{trans 'This password is used to access some of the external systems managed by our infrastructure. It will be regenerated if you change your password.'}</span>
</td>
</tr>
<tr class="pass-info">
<th>{trans 'API key'}:</th> <th>{trans 'API key'}:</th>
<td><span class="mono">{$api_key}</span><br /> <td><span class="mono">{$api_key}</span><br />
<span class="helptext">{trans 'Your API key will automatically be regenerated if you change your password.'}</span> <span class="helptext">{trans 'Your API key will be regenerated automatically if you change your password.'}</span>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -57,11 +63,21 @@
{block context} {block context}
<div class="issue-submit-info"> <div class="issue-submit-info">
<p>{trans 'If possible, use your real name. By using your real name, people will have more trust in your comments and remarks.'}</p> <p>{trans 'If possible, use your real name. By using your real name, people will have more trust in your comments and remarks.'}</p>
<p>{trans 'The API key is used to interact with this website using a program.'}</p> <p>{trans 'The extra password is used to access some of the external systems and the API key is used to interact with this website using a program.'}</p>
</div>{/block} </div>{/block}
{block javascript}<script type="text/javascript"> {block javascript}<script type="text/javascript">
document.getElementById('id_first_name').focus() document.getElementById('id_first_name').focus();
{literal}
$(document).ready(function() {
// Hide the key password by default.
$("#extra-password").before("{/literal}<tr id=\"form-block-0\"><td>&nbsp;</td><td><img style=\"vertical-align: text-bottom;\" src=\"{media '/idf/img/start.png'}\" alt=\" \" align=\"bottom\" /> <a id=\"form-show-0\" href=\"#\">{trans 'Show API key and extra password'}{literal}</a>.</td></tr>");
$("#form-show-0").click(function(){
$(".pass-info").show();
$("#form-block-0").hide();
});
$(".pass-info").hide();
});{/literal}
</script> </script>
{/block} {/block}