Add UI to let manager change users password

A submenu has been added to the side menu's
'Edit user account' option. This submenu has
two options:

- Reset password via email: an email is send
so that the user can change their password by
themselves.
- Reset password manually: the manager has to
write the password manually (or generate a random
one).

The passwords generated by the random password
generator don't contain characters like $ or !.
It uses some capital letters, some other lower
case letters and some numbers. Ambiguous
characters like 1, l, I has been removed.
This commit is contained in:
iagirre
2018-03-23 09:17:48 +01:00
parent d84895b800
commit 3a62fc9bda
9 changed files with 120 additions and 5 deletions

View File

@@ -76,6 +76,7 @@
//= require table_sortable
//= require investment_report_alert
//= require send_newsletter_alert
//= require managers
var initialize_modules = function() {
App.Comments.initialize();
@@ -119,6 +120,7 @@ var initialize_modules = function() {
App.TableSortable.initialize();
App.InvestmentReportAlert.initialize();
App.SendNewsletterAlert.initialize();
App.Managers.initialize();
};
$(function(){

View File

@@ -0,0 +1,25 @@
App.Managers =
generatePassword: ->
chars = 'aAbcdeEfghiJkmnpqrstuUvwxyz23456789'
pass = ''
x = 0
while x < 12
i = Math.floor(Math.random() * chars.length)
pass += chars.charAt(i)
x++
return pass
togglePassword: (type) ->
$('#user_password').prop 'type', type
initialize: ->
$(".generate-random-value").on "click", (event) ->
password = App.Managers.generatePassword()
$('#user_password').val(password)
$(".show-password").on "click", (event) ->
if $("#user_password").is("input[type='password']")
App.Managers.togglePassword('text')
else
App.Managers.togglePassword('password')

View File

@@ -278,6 +278,10 @@ $sidebar-active: #f4fcd0;
cursor: pointer;
}
.no-margin-bottom {
margin-bottom: 0 !important;
}
// 02. Sidebar
// -----------

View File

@@ -1,5 +1,5 @@
<div class="admin-sidebar">
<ul id="admin_menu">
<ul id="admin_menu" data-accordion-menu data-multi-open="false">
<li <%= "class=active" if controller_name == "document_verifications" ||
controller_name == "email_verifications" ||
controller_name == "users" %>>
@@ -9,11 +9,21 @@
<% end %>
</li>
<li <%= "class=active" if controller_name == "account" %>>
<%= link_to management_account_path do %>
<li class="section-title">
<a href="#">
<span class="icon-user"></span>
<%= t("management.menu.edit_user_accounts") %>
<% end %>
<strong><%= t("management.menu.edit_user_accounts") %></strong>
</a>
<ul <%= "class=is-active" if controller_name == "account" %>>
<% if managed_user.email %>
<li>
<%= link_to t("management.account.menu.reset_password_email"), edit_password_email_management_account_path %>
</li>
<% end %>
<li>
<%= link_to t("management.account.menu.reset_password_manually"), edit_password_manually_management_account_path %>
</li>
</ul>
</li>
<li <%= "class=active" if controller_name == "proposals" && action_name == "new" %>>

View File

@@ -0,0 +1,3 @@
<h2 class="not-print"><%= t("management.account.menu.reset_password_email") %></h2>
<%= link_to t("management.account.edit.password.send_email"), reset_password_management_account_path(managed_user.id), class: "button hollow" %>

View File

@@ -0,0 +1,20 @@
<h2 class="not-print"><%= t("management.account.menu.reset_password_manually") %></h2>
<%= form_for managed_user, url: change_password_management_account_path do |f| %>
<div class="row">
<%= f.label :password %>
<p class="help-text"><%= t("management.account.edit.password.print_help") %></p>
<div class="columns small-6 end">
<div class="input-group">
<%= f.password_field :password, class: "input-group-field no-margin-bottom", label: false, value: nil %>
<span class="input-group-label">
<a href="#" class="show-password"><i class="icon-eye"></i></a>
</span>
</div>
<%= link_to t("management.account.edit.password.random"), '#', class: 'generate-random-value float-right' %>
</div>
</div>
<%= f.submit t("management.account.edit.password.save"), class: "button success" %>
<% end %>

View File

@@ -0,0 +1,21 @@
<h2 class="not-print"><%= t("management.account.edit.title") %></h2>
<div class="for-print-only">
<%= t("management.account.edit.password.password") %>:
<strong><%= session[:new_password] %></strong>
</div>
<div class="row">
<div class="columns small-4">
<p class="callout success not-print"><%= t("management.account.edit.password.reseted") %></p>
</div>
</div>
<div class="row">
<div class="columns small-4">
<%= link_to t("management.account.edit.back"), edit_password_manually_management_account_path(managed_user.id), class: "button hollow" %>
<a id="print_link" href="javascript:window.print();" class="button warning">
<%= t('management.account.edit.password.print') %>
</a>
</div>
</div>

View File

@@ -1,10 +1,25 @@
en:
management:
account:
menu:
reset_password_email: Reset password via email
reset_password_manually: Reset password manually
alert:
unverified_user: No verified user logged in yet
show:
title: User account
edit:
title: 'Edit user account: Reset password'
back: Back
password:
password: Password
send_email: Send reset password email
reset_email_send: Email correctly sent.
reseted: Password reseted successfully
random: Generate random password
save: Save
print: Print password
print_help: You will be able to print the password when it is saved.
account_info:
change_user: Change user
document_number_label: 'Document number:'

View File

@@ -1,10 +1,25 @@
es:
management:
account:
menu:
reset_password_email: Restablecer contraseña via email
reset_password_manually: Restablecer contraseña manualmente
alert:
unverified_user: Solo se pueden editar cuentas de usuarios verificados
show:
title: Cuenta de usuario
edit:
title: 'Editar cuenta de usuario: Restablecer contraseña'
back: Atrás
password:
password: Contraseña
send_email: Enviar email para restablecer la contraseña
reset_email_send: Email enviado correctamente.
reseted: Contraseña restablecida correctamente
random: Generar contraseña aleatoria
save: Guardar
print: Imprimir contraseña
print_help: Podrás imprimir la contraseña cuando se haya guardado.
account_info:
change_user: Cambiar usuario
document_number_label: 'Número de documento:'