Class: DeviseTokenAuth::RegistrationsController
- Inherits:
-
ApplicationController
- Object
- DeviseController
- ApplicationController
- DeviseTokenAuth::RegistrationsController
- Defined in:
- app/controllers/devise_token_auth/registrations_controller.rb
Instance Method Summary collapse
- #account_update_params ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #sign_up_params ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#account_update_params ⇒ Object
138 139 140 |
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 138 def account_update_params params.permit(devise_parameter_sanitizer.for(:account_update)) end |
#create ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 8 def create @resource = resource_class.new(sign_up_params) @resource.provider = "email" # honor devise configuration for case_insensitive_keys if resource_class.case_insensitive_keys.include?(:email) @resource.email = sign_up_params[:email].try :downcase else @resource.email = sign_up_params[:email] end # give redirect value from params priority redirect_url = params[:confirm_success_url] # fall back to default value if provided redirect_url ||= DeviseTokenAuth.default_confirm_success_url # success redirect url is required if resource_class.devise_modules.include?(:confirmable) && !redirect_url return render json: { status: 'error', data: @resource.as_json, errors: [I18n.t("devise_token_auth.registrations.missing_confirm_success_url")] }, status: 403 end # if whitelist is set, validate redirect_url against whitelist if DeviseTokenAuth.redirect_whitelist unless DeviseTokenAuth.redirect_whitelist.include?(redirect_url) return render json: { status: 'error', data: @resource.as_json, errors: [I18n.t("devise_token_auth.registrations.redirect_url_not_allowed", redirect_url: redirect_url)] }, status: 403 end end begin # override email confirmation, must be sent manually from ctrl resource_class.skip_callback("create", :after, :send_on_create_confirmation_instructions) if @resource.save yield @resource if block_given? unless @resource.confirmed? # user will require email authentication @resource.send_confirmation_instructions({ client_config: params[:config_name], redirect_url: redirect_url }) else # email auth has been bypassed, authenticate user @client_id = SecureRandom.urlsafe_base64(nil, false) @token = SecureRandom.urlsafe_base64(nil, false) @resource.tokens[@client_id] = { token: BCrypt::Password.create(@token), expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i } @resource.save! update_auth_header end render json: { status: 'success', data: @resource.as_json } else clean_up_passwords @resource render json: { status: 'error', data: @resource.as_json, errors: @resource.errors.to_hash.merge(full_messages: @resource.errors.) }, status: 403 end rescue ActiveRecord::RecordNotUnique clean_up_passwords @resource render json: { status: 'error', data: @resource.as_json, errors: [I18n.t("devise_token_auth.registrations.email_already_exists", email: @resource.email)] }, status: 403 end end |
#destroy ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 117 def destroy if @resource @resource.destroy yield @resource if block_given? render json: { status: 'success', message: I18n.t("devise_token_auth.registrations.account_with_uid_destroyed", uid: @resource.uid) } else render json: { status: 'error', errors: [I18n.t("devise_token_auth.registrations.account_to_destroy_not_found")] }, status: 404 end end |
#sign_up_params ⇒ Object
134 135 136 |
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 134 def sign_up_params params.permit(devise_parameter_sanitizer.for(:sign_up)) end |
#update ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 95 def update if @resource if @resource.send(resource_update_method, account_update_params) yield @resource if block_given? render json: { status: 'success', data: @resource.as_json } else render json: { status: 'error', errors: @resource.errors.to_hash.merge(full_messages: @resource.errors.) }, status: 403 end else render json: { status: 'error', errors: [I18n.t("devise_token_auth.registrations.user_not_found")] }, status: 404 end end |