Class: LatoUsers::UsersController
- Inherits:
-
ApplicationController
- Object
- Lato::ApplicationController
- ApplicationController
- LatoUsers::UsersController
- Defined in:
- app/controllers/lato_users/users_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #force_update_password ⇒ Object
- #index ⇒ Object
- #manual_verify_email ⇒ Object
- #new ⇒ Object
- #resend_verification_email ⇒ Object
- #revoke_email_verification ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/lato_users/users_controller.rb', line 24 def create @user = Lato::User.new(user_params.merge( accepted_privacy_policy_version: Lato.config.legal_privacy_policy_version, accepted_terms_and_conditions_version: Lato.config.legal_terms_and_conditions_version )) if @user.save redirect_to users_path else render 'new' end end |
#destroy ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/lato_users/users_controller.rb', line 49 def destroy if params[:id]&.to_i == @session.user_id redirect_to users_path, alert: I18n.t('lato_users.cannot_delete_self') return end @user = Lato::User.find(params[:id]) @user.destroy redirect_to users_path end |
#edit ⇒ Object
36 37 38 |
# File 'app/controllers/lato_users/users_controller.rb', line 36 def edit @user = Lato::User.find(params[:id]) end |
#force_update_password ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/lato_users/users_controller.rb', line 87 def force_update_password @user = Lato::User.find(params[:id]) new_password = SecureRandom.hex(8) if @user.update(password: new_password, password_confirmation: new_password) redirect_to user_path(@user), notice: I18n.t('lato_users.password_updated', password: new_password) else redirect_to user_path(@user), alert: I18n.t('lato_users.password_update_failed') end end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/lato_users/users_controller.rb', line 5 def index @users = lato_index_collection( Lato::User.all, columns: %i[id email first_name last_name locale actions], searchable_columns: %i[email first_name last_name], sortable_columns: %i[id email first_name last_name], pagination: true, default_sort_by: "id|asc" ) end |
#manual_verify_email ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/controllers/lato_users/users_controller.rb', line 69 def manual_verify_email @user = Lato::User.find(params[:id]) if @user.update(email_verified_at: Time.current) redirect_to user_path(@user), notice: I18n.t('lato_users.email_manually_verified') else redirect_to user_path(@user), alert: @user.errors..join(', ') end end |
#new ⇒ Object
20 21 22 |
# File 'app/controllers/lato_users/users_controller.rb', line 20 def new @user = Lato::User.new end |
#resend_verification_email ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/controllers/lato_users/users_controller.rb', line 60 def resend_verification_email @user = Lato::User.find(params[:id]) if @user.request_verify_email redirect_to user_path(@user), notice: I18n.t('lato_users.verification_email_sent') else redirect_to user_path(@user), alert: @user.errors..join(', ') end end |
#revoke_email_verification ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'app/controllers/lato_users/users_controller.rb', line 78 def revoke_email_verification @user = Lato::User.find(params[:id]) if @user.update(email_verified_at: nil) redirect_to user_path(@user), notice: I18n.t('lato_users.email_verification_revoked') else redirect_to user_path(@user), alert: @user.errors..join(', ') end end |
#show ⇒ Object
16 17 18 |
# File 'app/controllers/lato_users/users_controller.rb', line 16 def show @user = Lato::User.find(params[:id]) end |
#update ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/lato_users/users_controller.rb', line 40 def update @user = Lato::User.find(params[:id]) if @user.update(user_params) redirect_to(params[:redirect_to] || users_path) else render 'edit' end end |