Added signals when the user updates his password.
This commit is contained in:
		| @@ -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; | ||||
|     } | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
|   | ||||
| @@ -40,10 +40,16 @@ | ||||
| {$form.f.password2|unsafe} | ||||
| </td> | ||||
| </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> | ||||
| <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> | ||||
| </tr> | ||||
| <tr> | ||||
| @@ -57,11 +63,21 @@ | ||||
| {block context} | ||||
| <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 '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} | ||||
|  | ||||
| {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> </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> | ||||
| {/block} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user