From d1911339d7f025e55a40dc90124090864175fb04 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Mon, 1 Dec 2008 13:35:17 +0100 Subject: [PATCH] Added signals when the user updates his password. --- src/IDF/Form/RegisterConfirmation.php | 22 ++++++++++++++++++ src/IDF/Form/UserAccount.php | 27 +++++++++++++++++++++++ src/IDF/Views/User.php | 2 ++ src/IDF/templates/idf/user/myaccount.html | 24 ++++++++++++++++---- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/IDF/Form/RegisterConfirmation.php b/src/IDF/Form/RegisterConfirmation.php index ce253d6..3832e9c 100644 --- a/src/IDF/Form/RegisterConfirmation.php +++ b/src/IDF/Form/RegisterConfirmation.php @@ -141,6 +141,28 @@ class IDF_Form_RegisterConfirmation extends Pluf_Form $this->_user->staff = false; if ($commit) { $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; } diff --git a/src/IDF/Form/UserAccount.php b/src/IDF/Form/UserAccount.php index dc2c49f..ed22dfa 100644 --- a/src/IDF/Form/UserAccount.php +++ b/src/IDF/Form/UserAccount.php @@ -88,12 +88,39 @@ class IDF_Form_UserAccount extends Pluf_Form throw new Exception(__('Cannot save the model from an invalid form.')); } unset($this->cleaned_data['password2']); + $update_pass = false; if (strlen($this->cleaned_data['password']) == 0) { unset($this->cleaned_data['password']); + } else { + $update_pass = true; } $this->user->setFromFormData($this->cleaned_data); if ($commit) { $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; } diff --git a/src/IDF/Views/User.php b/src/IDF/Views/User.php index 31bddcd..0c741bc 100644 --- a/src/IDF/Views/User.php +++ b/src/IDF/Views/User.php @@ -41,6 +41,7 @@ class IDF_Views_User // As the password is salted, we can directly take the sha1 of // the salted 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); if ($request->method == 'POST') { $form = new IDF_Form_UserAccount($request->POST, $params); @@ -56,6 +57,7 @@ class IDF_Views_User return Pluf_Shortcuts_RenderToResponse('idf/user/myaccount.html', array('page_title' => __('Your Account'), 'api_key' => $api_key, + 'ext_pass' => $ext_pass, 'form' => $form), $request); } diff --git a/src/IDF/templates/idf/user/myaccount.html b/src/IDF/templates/idf/user/myaccount.html index 5c5bcdf..e1b9a2c 100644 --- a/src/IDF/templates/idf/user/myaccount.html +++ b/src/IDF/templates/idf/user/myaccount.html @@ -40,10 +40,16 @@ {$form.f.password2|unsafe} - + +{trans 'Extra password'}: +{$ext_pass}
+{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.'} + + + {trans 'API key'}: {$api_key}
-{trans 'Your API key will automatically be regenerated if you change your password.'} +{trans 'Your API key will be regenerated automatically if you change your password.'} @@ -57,11 +63,21 @@ {block context}

{trans 'If possible, use your real name. By using your real name, people will have more trust in your comments and remarks.'}

-

{trans 'The API key is used to interact with this website using a program.'}

+

{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.'}

{/block} {block javascript} {/block}