Indefero

Indefero Commit Details


Date:2011-02-21 03:50:07 (13 years 10 months ago)
Author:Patrick Georgi
Branch:develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, release-1.1, release-1.2, release-1.3
Commit:dfa223b39e61d381b2117c4505437b4642a3c156
Parents: 0a8d771c1132c4fe5df50b28a99a531c4c077597
Message:Manage addition of secondary emails

Changes:

File differences

src/IDF/Form/UserAccount.php
172172
173173
174174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
175204
176205
177206
......
195224
196225
197226
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
227
218228
219229
220230
......
226236
227237
228238
239
240
241
229242
230243
231244
));
}
private function send_validation_mail($new_email, $secondary_mail=false)
{
if ($secondary_mail) {
$type = "secondary";
} else {
$type = "primary";
}
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
$encrypted = trim($cr->encrypt($new_email.':'.$this->user->id.':'.time().':'.$type), '~');
$key = substr(md5(Pluf::f('secret_key').$encrypted), 0, 2).$encrypted;
$url = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($key), array(), false);
$urlik = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey', array(), array(), false);
$context = new Pluf_Template_Context(
array('key' => Pluf_Template::markSafe($key),
'url' => Pluf_Template::markSafe($url),
'urlik' => Pluf_Template::markSafe($urlik),
'email' => $new_email,
'user'=> $this->user,
)
);
$tmpl = new Pluf_Template('idf/user/changeemail-email.txt');
$text_email = $tmpl->render($context);
$email = new Pluf_Mail(Pluf::f('from_email'), $new_email,
__('Confirm your new email address.'));
$email->addTextMessage($text_email);
$email->sendMail();
$this->user->setMessage(sprintf(__('A validation email has been sent to "%s" to validate the email address change.'), Pluf_esc($new_email)));
}
/**
* Save the model in the database.
*
$new_email = $this->cleaned_data['email'];
unset($this->cleaned_data['email']);
if ($old_email != $new_email) {
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
$encrypted = trim($cr->encrypt($new_email.':'.$this->user->id.':'.time()), '~');
$key = substr(md5(Pluf::f('secret_key').$encrypted), 0, 2).$encrypted;
$url = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($key), array(), false);
$urlik = Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey', array(), array(), false);
$context = new Pluf_Template_Context(
array('key' => Pluf_Template::markSafe($key),
'url' => Pluf_Template::markSafe($url),
'urlik' => Pluf_Template::markSafe($urlik),
'email' => $new_email,
'user'=> $this->user,
)
);
$tmpl = new Pluf_Template('idf/user/changeemail-email.txt');
$text_email = $tmpl->render($context);
$email = new Pluf_Mail(Pluf::f('from_email'), $new_email,
__('Confirm your new email address.'));
$email->addTextMessage($text_email);
$email->sendMail();
$this->user->setMessage(sprintf(__('A validation email has been sent to "%s" to validate the email address change.'), Pluf_esc($new_email)));
$this->send_validation_mail($new_email);
}
$this->user->setFromFormData($this->cleaned_data);
// Add key as needed.
$key->create();
}
}
if ('' !== $this->cleaned_data['secondary_mail']) {
$this->send_validation_mail($this->cleaned_data['secondary_mail'], true);
}
if ($commit) {
$this->user->update();
src/IDF/Form/UserChangeEmail.php
5353
5454
5555
56
56
5757
5858
5959
* Throw a Pluf_Form_Invalid exception if the key is not valid.
*
* @param string Key
* @return array array($new_email, $user_id, time())
* @return array array($new_email, $user_id, time(), [primary|secondary])
*/
public static function validateKey($key)
{
src/IDF/Views/User.php
212212
213213
214214
215
215
216216
217217
218218
......
220220
221221
222222
223
224
223
224
225
226
227
228
229
230
231
225232
226233
227234
$key = $match[1];
$url = Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey');
try {
list($email, $id, $time) = IDF_Form_UserChangeEmail::validateKey($key);
list($email, $id, $time, $type) = IDF_Form_UserChangeEmail::validateKey($key);
} catch (Pluf_Form_Invalid $e) {
return new Pluf_HTTP_Response_Redirect($url);
}
return new Pluf_HTTP_Response_Redirect($url);
}
// Now we have a change link coming from the right user.
$request->user->email = $email;
$request->user->update();
if ($type == "primary") {
$request->user->email = $email;
$request->user->update();
} else {
$mailaddress = new IDF_EmailAddress();
$mailaddress->user = $request->user;
$mailaddress->address = $email;
$mailaddress->create();
}
$request->user->setMessage(sprintf(__('Your new email address "%s" has been validated. Thank you!'), Pluf_esc($email)));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_User::myAccount');
return new Pluf_HTTP_Response_Redirect($url);

Archive Download the corresponding diff file

Page rendered in 0.08362s using 13 queries.