Skip to content

Commit e38f565

Browse files
authored
Add avatar removal, tweaks to partials (#33)
1 parent bf28200 commit e38f565

File tree

6 files changed

+60
-8
lines changed

6 files changed

+60
-8
lines changed

components/Account.php

+30
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,36 @@ public function onUpdate()
444444
$this->prepareVars();
445445
}
446446

447+
/**
448+
* Removes the user's avatar if available.
449+
*
450+
* This will remove the user's avatar and default back to the Gravatar attached to the user's
451+
* email address.
452+
*
453+
* @return void
454+
*/
455+
public function onRemoveAvatar()
456+
{
457+
if (!$user = $this->user()) {
458+
return;
459+
}
460+
461+
if (!$user->avatar) {
462+
Flash::info(Lang::get(/*Settings successfully saved!*/'winter.user::lang.account.no_avatar'));
463+
return;
464+
}
465+
466+
$user->avatar()->remove($user->avatar);
467+
468+
Flash::success(Lang::get(/*Settings successfully saved!*/'winter.user::lang.account.avatar_removed'));
469+
470+
$this->prepareVars();
471+
472+
// Force the avatar relationship to be removed even if User::getAvatarThumb()
473+
// has stale references
474+
$this->page['user']->setRelation('avatar', null);
475+
}
476+
447477
/**
448478
* Deactivate user
449479
*/

components/account/deactivate_link.htm

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
<a
99
href="javascript:;"
10-
onclick="toggleAccountDeactivateForm()">
10+
onclick="toggleAccountDeactivateForm()"
11+
class="deactivate"
12+
>
1113
Deactivate account
1214
</a>
1315

1416
<div id="accountDeactivateForm" style="display: none">
1517
{{ form_ajax('onDeactivate') }}
16-
<hr />
1718
<h3>Deactivate your account?</h3>
1819
<p>
19-
Your account will be disabled and your details removed from the site.
20-
You can reactivate your account any time by signing back in.
20+
Your account will be disabled and your details removed from the site. You can reactivate your account any time by signing back in.
2121
</p>
2222
<div class="form-group">
2323
<label for="accountDeletePassword">To continue, please enter your password:</label>

components/account/default.htm

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<div class="row">
44

55
<div class="col-md-6">
6-
<h3>Sign in</h3>
76
{% partial __SELF__ ~ '::signin' %}
87
</div>
98

components/account/signin.htm

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{{ form_ajax('onSignin') }}
1+
<h3>Sign in</h3>
22

3+
{{ form_ajax('onSignin') }}
34
<div class="form-group">
45
<label for="userSigninLogin">{{ loginAttributeLabel }}</label>
56
<input

components/account/update.htm

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{{ form_ajax('onUpdate') }}
1+
<h3>Profile</h3>
2+
3+
{{ form_ajax('onUpdate', { flash: 1 }) }}
24

35
<div class="form-group">
46
<label for="accountName">Full Name</label>
@@ -20,6 +22,24 @@
2022
<input name="password_confirmation" type="password" class="form-control" id="accountPasswordConfirm">
2123
</div>
2224

25+
<div class="form-group">
26+
<label for="accountAvatar">Display Picture</label>
27+
<input
28+
name="avatar"
29+
type="file"
30+
class="form-control"
31+
id="accountAvatar"
32+
accept="image/jpg, image/jpeg, image/png, image/gif, image/webp"
33+
capture="user"
34+
>
35+
36+
{% if user.avatar %}
37+
<a href="javascript:;" data-request="onRemoveAvatar" data-request-flash class="remove-avatar">
38+
Remove current display picture
39+
</a>
40+
{% endif %}
41+
</div>
42+
2343
{% if updateRequiresPassword %}
2444
<p>To change these details, please confirm your current password.</p>
2545
<div class="form-group">

lang/en/lang.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@
197197
'new_password' => 'New Password',
198198
'new_password_confirm' => 'Confirm New Password',
199199
'update_requires_password' => 'Confirm password on update',
200-
'update_requires_password_comment' => 'Require the current password of the user when changing their profile.'
200+
'update_requires_password_comment' => 'Require the current password of the user when changing their profile.',
201+
'no_avatar' => 'Your account has no display picture to remove.',
202+
'avatar_removed' => 'Your display picture has been successfully removed.',
201203
],
202204
'reset_password' => [
203205
'reset_password' => 'Reset Password',

0 commit comments

Comments
 (0)