2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class UsersController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource
|
|
|
|
|
|
2014-07-31 19:23:46 +05:30
|
|
|
def new
|
|
|
|
|
@user = User.new
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2017-01-10 17:07:28 +02:00
|
|
|
def create
|
|
|
|
|
@user = User.new(user_params)
|
|
|
|
|
@user.skip_confirmation!
|
|
|
|
|
if @user.save
|
|
|
|
|
redirect_to admin_users_path, notice: 'User successfully created.'
|
|
|
|
|
else
|
|
|
|
|
flash.now[:error] = "Creating User failed: #{@user.errors.full_messages.join('. ')}."
|
|
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def index
|
2018-06-18 10:04:17 -07:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
format.json do
|
2022-02-10 18:30:28 +01:00
|
|
|
render json: UserDatatable.new(view_context: view_context)
|
2018-06-18 10:04:17 -07:00
|
|
|
end
|
|
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2016-07-11 04:41:25 -04:00
|
|
|
# This action allow admins to manually toggle confirmation state of another user
|
|
|
|
|
def toggle_confirmation
|
|
|
|
|
if user_params[:to_confirm] == 'true'
|
|
|
|
|
@user.confirm
|
|
|
|
|
elsif user_params[:to_confirm] == 'false'
|
|
|
|
|
@user.confirmed_at = nil
|
|
|
|
|
@user.save
|
|
|
|
|
end
|
|
|
|
|
head :ok
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def show
|
|
|
|
|
# Variable @show_attributes holds the attributes that are visible for the 'show' action
|
|
|
|
|
# If you want to change the attributes that are shown in the 'show' action of users
|
|
|
|
|
# add/remove the attributes in the following string array
|
2015-03-02 11:35:08 +02:00
|
|
|
@show_attributes = %w(name email username nickname affiliation biography registered attended roles created_at
|
2014-06-23 19:07:50 +03:00
|
|
|
updated_at sign_in_count current_sign_in_at last_sign_in_at
|
|
|
|
|
current_sign_in_ip last_sign_in_ip)
|
|
|
|
|
end
|
2014-03-27 20:14:52 +05:30
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def update
|
2014-11-01 00:19:36 +02:00
|
|
|
message = ''
|
|
|
|
|
if params[:user] && !params[:user][:email].nil?
|
|
|
|
|
if (new_email = params[:user][:email]) != @user.email
|
|
|
|
|
message = " Confirmation email sent to #{new_email}. The new email needs to be confirmed before it can be used."
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-02-14 17:53:58 +01:00
|
|
|
if @user.update(user_params)
|
2014-11-01 00:19:36 +02:00
|
|
|
redirect_to admin_users_path, notice: "Updated #{@user.name} (#{@user.email})!" + message
|
2014-08-13 22:46:41 +03:00
|
|
|
else
|
2016-03-16 11:20:56 +05:30
|
|
|
redirect_to admin_users_path, error: "Could not update #{@user.name} (#{@user.email}). #{@user.errors.full_messages.join('. ')}."
|
2014-08-13 22:46:41 +03:00
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|
2014-03-27 20:14:52 +05:30
|
|
|
|
2014-08-12 22:27:02 +03:00
|
|
|
def edit; end
|
2015-10-28 18:05:15 +02:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def user_params
|
2017-01-10 17:07:28 +02:00
|
|
|
params.require(:user).permit(:email, :name, :email_public, :biography, :nickname, :affiliation, :is_admin,
|
|
|
|
|
:username, :login, :is_disabled, :tshirt, :mobile, :volunteer_experience,
|
|
|
|
|
:languages, :to_confirm, :password, role_ids: [])
|
2015-10-28 18:05:15 +02:00
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|
2014-05-05 02:28:46 +04:00
|
|
|
end
|