forked from External/greenlight
Added the ability for admins to send a reset password email for users (#737)
This commit is contained in:
parent
1256554ce6
commit
7e3c44575e
|
@ -22,7 +22,7 @@ class AdminsController < ApplicationController
|
||||||
include Emailer
|
include Emailer
|
||||||
include Recorder
|
include Recorder
|
||||||
|
|
||||||
manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve]
|
manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve, :reset]
|
||||||
site_settings = [:branding, :coloring, :coloring_lighten, :coloring_darken,
|
site_settings = [:branding, :coloring, :coloring_lighten, :coloring_darken,
|
||||||
:registration_method, :room_authentication, :room_limit, :default_recording_visibility]
|
:registration_method, :room_authentication, :room_limit, :default_recording_visibility]
|
||||||
|
|
||||||
|
@ -106,6 +106,14 @@ class AdminsController < ApplicationController
|
||||||
redirect_to admins_path
|
redirect_to admins_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /admins/reset
|
||||||
|
def reset
|
||||||
|
@user.create_reset_digest
|
||||||
|
|
||||||
|
send_password_reset_email(@user)
|
||||||
|
|
||||||
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.reset_password") }
|
||||||
|
end
|
||||||
# SITE SETTINGS
|
# SITE SETTINGS
|
||||||
|
|
||||||
# POST /admins/branding
|
# POST /admins/branding
|
||||||
|
|
|
@ -53,7 +53,7 @@ class PasswordResetsController < ApplicationController
|
||||||
elsif params[:user][:password] != params[:user][:password_confirmation]
|
elsif params[:user][:password] != params[:user][:password_confirmation]
|
||||||
flash.now[:alert] = I18n.t("password_different_notice")
|
flash.now[:alert] = I18n.t("password_different_notice")
|
||||||
render 'edit'
|
render 'edit'
|
||||||
elsif current_user.update_attributes(user_params)
|
elsif @user.update_attributes(user_params)
|
||||||
flash[:success] = I18n.t("password_reset_success")
|
flash[:success] = I18n.t("password_reset_success")
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
else
|
else
|
||||||
|
@ -67,23 +67,19 @@ class PasswordResetsController < ApplicationController
|
||||||
@user = User.find_by(email: params[:email])
|
@user = User.find_by(email: params[:email])
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_user
|
|
||||||
@user
|
|
||||||
end
|
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:password, :password_confirmation)
|
params.require(:user).permit(:password, :password_confirmation)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks expiration of reset token.
|
# Checks expiration of reset token.
|
||||||
def check_expiration
|
def check_expiration
|
||||||
redirect_to new_password_reset_url, alert: I18n.t("expired_reset_token") if current_user.password_reset_expired?
|
redirect_to new_password_reset_url, alert: I18n.t("expired_reset_token") if @user.password_reset_expired?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Confirms a valid user.
|
# Confirms a valid user.
|
||||||
def valid_user
|
def valid_user
|
||||||
unless current_user.authenticated?(:reset, params[:id])
|
unless @user.authenticated?(:reset, params[:id])
|
||||||
current_user&.activate unless current_user&.activated?
|
@user&.activate unless @user&.activated?
|
||||||
redirect_to root_url
|
redirect_to root_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -128,4 +128,9 @@ module ApplicationHelper
|
||||||
role.name
|
role.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_reset_password
|
||||||
|
# Check if admin is editting user
|
||||||
|
Rails.application.routes.recognize_path(request.env['PATH_INFO'])[:action] == "edit_user"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Ability
|
||||||
|
|
||||||
if highest_role.can_manage_users
|
if highest_role.can_manage_users
|
||||||
can [:index, :roles, :edit_user, :promote, :demote, :ban_user, :unban_user,
|
can [:index, :roles, :edit_user, :promote, :demote, :ban_user, :unban_user,
|
||||||
:approve, :invite], :admin
|
:approve, :invite, :reset], :admin
|
||||||
end
|
end
|
||||||
|
|
||||||
if !highest_role.can_edit_site_settings && !highest_role.can_edit_roles && !highest_role.can_manage_users
|
if !highest_role.can_edit_site_settings && !highest_role.can_edit_roles && !highest_role.can_manage_users
|
||||||
|
|
|
@ -75,6 +75,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<%= f.submit t("update"), class: "btn btn-primary float-right" %>
|
<%= f.submit t("update"), class: "btn btn-primary float-right ml-4" %>
|
||||||
|
|
||||||
|
<% if can_reset_password %>
|
||||||
|
<%= link_to "Reset user password", admin_reset_path(user_uid: @user.uid), class: "btn btn-primary float-right" %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= t('mailer.user.password_reset.welcome', bigbluebutton: t('bigbluebutton')) %>
|
<%= t('mailer.user.password_reset.welcome', email: @user.email).html_safe %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p style="margin-bottom:45px;">
|
<p style="margin-bottom:45px;">
|
||||||
|
@ -38,11 +38,11 @@
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<p style="margin-top:45px;">
|
<p style="margin-top:45px;">
|
||||||
<%= t('mailer.user.password_reset.expire') %>
|
<%= t('mailer.user.password_reset.ignore') %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= t('mailer.user.password_reset.ignore') %>
|
<%= t('mailer.user.password_reset.expire') %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<%= t('mailer.user.password_reset.title') %>
|
<%= t('mailer.user.password_reset.title') %>
|
||||||
|
|
||||||
<%= t('mailer.user.password_reset.welcome', bigbluebutton: t('bigbluebutton')) %>
|
<%= t('mailer.user.password_reset.welcome', email: @user.email) %>
|
||||||
<%= t('mailer.user.password_reset.message') %>
|
<%= t('mailer.user.password_reset.message') %>
|
||||||
|
|
||||||
<%= @url %>
|
<%= @url %>
|
||||||
|
|
|
@ -75,6 +75,7 @@ en:
|
||||||
invite_email_verification: Emails must be enabled in order to use this method. Please contact your system administrator.
|
invite_email_verification: Emails must be enabled in order to use this method. Please contact your system administrator.
|
||||||
promoted: User has been successfully promoted
|
promoted: User has been successfully promoted
|
||||||
registration_method_updated: Registration method successfully updated
|
registration_method_updated: Registration method successfully updated
|
||||||
|
reset_password: The user has been sent an email to reset their password. (Please ask them to check their spam folder if they haven't received it)
|
||||||
settings: Site Settings successfully changed
|
settings: Site Settings successfully changed
|
||||||
unauthorized: You are not authorized to perform actions on this user
|
unauthorized: You are not authorized to perform actions on this user
|
||||||
recordings:
|
recordings:
|
||||||
|
@ -262,11 +263,11 @@ en:
|
||||||
username: Your username is %{email}.
|
username: Your username is %{email}.
|
||||||
password_reset:
|
password_reset:
|
||||||
title: 'Password reset'
|
title: 'Password reset'
|
||||||
welcome: It seems like you forgot your password for %{bigbluebutton}
|
welcome: A password reset has been requested for the email <b>%{email}</b>
|
||||||
message: 'If this is true, please click the link below to reset your password:'
|
message: 'If you requested this reset, then please click the link below to reset your password:'
|
||||||
reset_link: Reset Password
|
reset_link: Reset Password
|
||||||
expire: This link will expire in two hours.
|
expire: This link will expire in two hours.
|
||||||
ignore: You can safely ignore this email if you did not request a password reset.
|
ignore: You can safely ignore this email if you did not make this request.
|
||||||
promoted:
|
promoted:
|
||||||
admins_link: Visit the Organization Page
|
admins_link: Visit the Organization Page
|
||||||
info: You are now an %{role} on %{url}.
|
info: You are now an %{role} on %{url}.
|
||||||
|
|
|
@ -51,6 +51,7 @@ Rails.application.routes.draw do
|
||||||
post '/invite', to: 'admins#invite', as: :invite_user
|
post '/invite', to: 'admins#invite', as: :invite_user
|
||||||
post '/registration_method/:method', to: 'admins#registration_method', as: :admin_change_registration
|
post '/registration_method/:method', to: 'admins#registration_method', as: :admin_change_registration
|
||||||
post '/approve/:user_uid', to: 'admins#approve', as: :admin_approve
|
post '/approve/:user_uid', to: 'admins#approve', as: :admin_approve
|
||||||
|
get '/reset', to: 'admins#reset', as: :admin_reset
|
||||||
post '/room_limit', to: 'admins#room_limit', as: :admin_room_limit
|
post '/room_limit', to: 'admins#room_limit', as: :admin_room_limit
|
||||||
post '/default_recording_visibility', to: 'admins#default_recording_visibility', as: :admin_recording_visibility
|
post '/default_recording_visibility', to: 'admins#default_recording_visibility', as: :admin_recording_visibility
|
||||||
get '/roles', to: 'admins#roles', as: :admin_roles
|
get '/roles', to: 'admins#roles', as: :admin_roles
|
||||||
|
|
|
@ -124,6 +124,7 @@ describe PasswordResetsController, type: :controller do
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
id: token,
|
id: token,
|
||||||
|
email: user.email,
|
||||||
user: {
|
user: {
|
||||||
password: :password,
|
password: :password,
|
||||||
password_confirmation: :password,
|
password_confirmation: :password,
|
||||||
|
|
Loading…
Reference in New Issue