Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/backend/controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ public function update_onImpersonateUser($recordId)
return Backend::redirect('backend/users/myaccount');
}

/**
* Send a password restore email to this user
* @param int $recordId
* @return Response|void
*/
public function update_onSendPasswordRestore($recordId)
{
if (!$this->user->hasAccess('backend.manage_users')) {
return Response::make(Lang::get('backend::lang.page.access_denied.label'), 403);
}

$this->formFindModelObject($recordId)->sendPasswordRestore();

Flash::success(Lang::get('backend::lang.account.send_password_restore_success'));
}

/**
* Unsuspend this user
*/
Expand Down
14 changes: 14 additions & 0 deletions modules/backend/controllers/users/_btn_password_restore.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php if ($this->user->hasAccess('backend.manage_users')): ?>
<div class="loading-indicator-container">
<button
type="button"
data-request="onSendPasswordRestore"
data-load-indicator="<?= e(trans('backend::lang.account.send_password_restore_working')) ?>"
data-request-confirm="<?= e(trans('backend::lang.account.send_password_restore_confirm')) ?>"
class="btn btn-default wn-icon-unlock-alt"
style="width: 100%; text-align: center"
>
<?= e(trans('backend::lang.account.send_password_restore')) ?>
</button>
</div>
<?php endif ?>
6 changes: 5 additions & 1 deletion modules/backend/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
'reset_success' => 'Password has been reset. You may now sign in.',
'reset_error' => 'Invalid password reset data supplied. Please try again!',
'reset_fail' => 'Unable to reset your password!',
'send_password_restore' => 'Send Password Restore',
'send_password_restore_confirm' => 'Are you sure you want to send this user a passowrd restore email?',
'send_password_restore_success' => 'Password restore email sent',
'send_password_restore_working' => 'Sending...',
'apply' => 'Apply',
'cancel' => 'Cancel',
'delete' => 'Delete',
Expand Down Expand Up @@ -148,7 +152,7 @@
'superuser' => 'Super User',
'superuser_comment' => 'Grants this account unlimited access to all areas of the system. Super users can add and manage other users. ',
'send_invite' => 'Send invitation by email',
'send_invite_comment' => 'Sends a welcome message containing login and password information.',
'send_invite_comment' => 'Sends a welcome message containing login and password information. If a password is not set, the message will include a password reset link.',
'delete_confirm' => 'Delete this administrator?',
'return' => 'Return to admin list',
'allow' => 'Allow',
Expand Down
43 changes: 39 additions & 4 deletions modules/backend/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class User extends UserBase
public $rules = [
'email' => 'required|between:6,255|email|unique:backend_users',
'login' => 'required|between:2,255|unique:backend_users',
'password' => 'required:create|min:4|confirmed',
'password_confirmation' => 'required_with:password|min:4'
'password' => 'sometimes|min:4|confirmed',
'password_confirmation' => 'sometimes|required_with:password|min:4'
];

/**
Expand Down Expand Up @@ -152,6 +152,21 @@ public function afterLogin()
Event::fire('backend.user.login', [$this]);
}

/**
* Generates a link to the backend, or a password reset link if no password was set on creation.
* @return string
*/
public function getInvitationLink()
{
if (!$this->password) {
$code = $this->getResetPasswordCode();

return Backend::url('backend/auth/reset/' . $this->id . '/' . $code);
}

return Backend::url('backend');
}

/**
* Sends an invitation to the user using template "backend::mail.invite".
* @return void
Expand All @@ -161,15 +176,35 @@ public function sendInvitation()
$data = [
'name' => $this->full_name,
'login' => $this->login,
'password' => $this->getOriginalHashValue('password'),
'link' => Backend::url('backend'),
'link' => $this->getInvitationLink(),
];

Mail::send('backend::mail.invite', $data, function ($message) {
$message->to($this->email, $this->full_name);
});
}


/**
* Sends a password restore link to the user using template "backend::mail.restore".
* @return void
*/
public function sendPasswordRestore()
{
$code = $this->getResetPasswordCode();

$link = Backend::url('backend/auth/reset/' . $this->id . '/' . $code);

$data = [
'name' => $this->full_name,
'link' => $link,
];

Mail::send('backend::mail.restore', $data, function ($message) {
$message->to($this->email, $this->full_name)->subject(trans('backend::lang.account.password_reset'));
});
}

public function getGroupsOptions()
{
$result = [];
Expand Down
4 changes: 4 additions & 0 deletions modules/backend/models/user/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ secondaryTabs:
label: ''
context: [update]
type: partial
btn_password_restore:
label: ''
context: [update]
type: partial
avatar:
label: backend::lang.user.avatar
type: fileupload
Expand Down
3 changes: 1 addition & 2 deletions modules/backend/views/mail/invite.htm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

{% partial 'panel' body %}
- Login: `{{ login ?: 'sample' }}`
- Password: `{{ (password ?: '********') | raw }}`
{% endpartial %}

You can use the following link to sign in:
Expand All @@ -17,4 +16,4 @@
Sign in to admin area
{% endpartial %}

After signing in you should change your password by clicking your name on the top right corner of the administration area.
After signing in, you may be asked to set a new password if one was not created for you.