diff --git a/src/IDF/Views/User.php b/src/IDF/Views/User.php index 6086ae2..f31cc5b 100644 --- a/src/IDF/Views/User.php +++ b/src/IDF/Views/User.php @@ -127,12 +127,14 @@ class IDF_Views_User $form = new IDF_Form_UserAccount(null, $params); } $keys = $request->user->get_idf_key_list(); + $mailaddrs = Pluf::factory('IDF_EmailAddress')->get_email_addresses_for_user($request->user); return Pluf_Shortcuts_RenderToResponse('idf/user/myaccount.html', array('page_title' => __('Your Account'), 'api_key' => $api_key, 'ext_pass' => $ext_pass, 'keys' => $keys, + 'mailaddrs' => $mailaddrs, 'form' => $form), $request); } @@ -157,6 +159,26 @@ class IDF_Views_User return new Pluf_HTTP_Response_Redirect($url); } + /** + * Delete a mail address. + * + * This is redirecting to the preferences + */ + public $deleteMail_precond = array('Pluf_Precondition::loginRequired'); + public function deleteMail($request, $match) + { + $url = Pluf_HTTP_URL_urlForView('IDF_Views_User::myAccount'); + if ($request->method == 'POST') { + $address = Pluf_Shortcuts_GetObjectOr404('IDF_EmailAddress', $match[1]); + if ($address->user != $request->user->id) { + return new Pluf_HTTP_Response_Forbidden($request); + } + $address->delete(); + $request->user->setMessage(__('The address has been deleted.')); + } + return new Pluf_HTTP_Response_Redirect($url); + } + /** * Enter the key to change an email address. * diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index b341580..3c5af99 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -471,6 +471,11 @@ $ctl[] = array('regex' => '#^/preferences/email/ak/(.*)/$#', 'model' => 'IDF_Views_User', 'method' => 'changeEmailDo'); +$ctl[] = array('regex' => '#^/preferences/email/(\d+)/delete/$#', + 'base' => $base, + 'model' => 'IDF_Views_User', + 'method' => 'deleteMail'); + $ctl[] = array('regex' => '#^/preferences/key/(\d+)/delete/$#', 'base' => $base, 'model' => 'IDF_Views_User', diff --git a/src/IDF/templates/idf/user/myaccount.html b/src/IDF/templates/idf/user/myaccount.html index 0b49a97..a1de2b1 100644 --- a/src/IDF/templates/idf/user/myaccount.html +++ b/src/IDF/templates/idf/user/myaccount.html @@ -129,6 +129,15 @@ {/foreach} {/if} +{if count($mailaddrs)>1} + + +{foreach $mailaddrs as $mail}{if $mail.id != -1} +{/if}{/foreach} +
{trans 'Your additional email addresses'}
+{$mail.address}
+
+{/if} {/block} {block context}