Module: MnoEnterprise::Concerns::Controllers::Auth::ConfirmationsController
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mno_enterprise/concerns/controllers/auth/confirmations_controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#finalize ⇒ Object
POST /resource/confirmation/finalize Confirm a new user and update.
-
#lounge {|:success, resource| ... } ⇒ Object
TODO: specs GET /resource/confirmation/lounge.
-
#show {|:success, resource| ... } ⇒ Object
GET /resource/confirmation?confirmation_token=abcdef Override to display a form for the user to fill the final registration details.
-
#update ⇒ Object
TODO: specs PUT /resource/confirmation.
Instance Method Details
#finalize ⇒ Object
POST /resource/confirmation/finalize Confirm a new user and update
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mno_enterprise/concerns/controllers/auth/confirmations_controller.rb', line 83 def finalize @confirmation_token = params[:user].delete(:confirmation_token) self.resource = resource_class.find_for_confirmation(@confirmation_token) # Exit action and redirect if user is already confirmed if resource && resource.confirmed? yield(:already_confirmed, resource) if block_given? redirect_to after_confirmation_path_for(resource_name, resource) return end if resource.errors.empty? resource.assign_attributes(params[:user]) unless resource.confirmed? resource.perform_confirmation(@confirmation_token) resource.save sign_in resource, bypass: true (:notice, :confirmed) if is_flashing_format? yield(:success,resource) if block_given? MnoEnterprise::EventLogger.info('user_confirm', resource.id, 'User confirmed', nil, resource) (resource){ redirect_to after_confirmation_path_for(resource_name, resource, new_user: true) } else yield(:error,resource) if block_given? (resource.errors, status: :unprocessable_entity){ render :new } end end |
#lounge {|:success, resource| ... } ⇒ Object
TODO: specs GET /resource/confirmation/lounge
111 112 113 114 |
# File 'lib/mno_enterprise/concerns/controllers/auth/confirmations_controller.rb', line 111 def lounge self.resource = @resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) yield(:success,resource) if block_given? end |
#show {|:success, resource| ... } ⇒ Object
GET /resource/confirmation?confirmation_token=abcdef Override to display a form for the user to fill the final registration details
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mno_enterprise/concerns/controllers/auth/confirmations_controller.rb', line 47 def show @confirmation_token = params[:confirmation_token] self.resource = resource_class.find_for_confirmation(@confirmation_token) # Exit if no resources unless resource.errors.empty? yield(:error, resource) if block_given? (resource.errors, status: :unprocessable_entity){ render :new } return end # Case 1: user is confirmed but trying to confirm a new email address (change of email) # Case 2: user is a new user - in this case a form is displayed with final details to fill # Case 3: user is confirmed and clicking again on the link if resource.confirmed? resource.perform_confirmation(@confirmation_token) if resource.errors.empty? sign_in(resource) (:notice, :confirmed) if is_flashing_format? yield(:reconfirmation_success, resource) if block_given? (resource){ redirect_to after_confirmation_path_for(resource_name, resource) } else (resource.errors, status: :unprocessable_entity){ render :new } end return end # Check if phone number should be required # Bypassed for invited users @phone_required = resource.organizations.map(&:users).flatten.count == 1 yield(:success, resource) if block_given? end |
#update ⇒ Object
TODO: specs PUT /resource/confirmation
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/mno_enterprise/concerns/controllers/auth/confirmations_controller.rb', line 118 def update self.resource = @resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) # Redirect straight away if no changes if @resource.email == params[:user][:email] @resource.resend_confirmation_instructions redirect_to mno_enterprise.user_confirmation_lounge_path, notice: "The confirmation email has been resent." return end # Update email previous_email = @resource.email @resource.email = params[:user][:email] @resource.skip_reconfirmation! if @resource.save @resource.resend_confirmation_instructions yield(:success,resource) if block_given? redirect_to mno_enterprise.user_confirmation_lounge_path, notice: "'Email updated! A confirmation email has been resent." else # Rollback #@resource.restore_email! yield(resource,:error) if block_given? render 'lounge' end end |