Class: DeviseTokenAuth::RegistrationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/devise_token_auth/registrations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#resource_data, #resource_errors

Instance Method Details

#account_update_paramsObject



102
103
104
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 102

def 
  params.permit(*params_for_resource(:account_update))
end

#createObject



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
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 8

def create
  @resource            = resource_class.new(.except(:confirm_success_url))
  @resource.provider   = provider

  # honor devise configuration for case_insensitive_keys
  if resource_class.case_insensitive_keys.include?(:email)
    @resource.email = [:email].try :downcase
  else
    @resource.email = [:email]
  end

  # give redirect value from params priority
  @redirect_url = [:confirm_success_url]

  # fall back to default value if provided
  @redirect_url ||= DeviseTokenAuth.default_confirm_success_url

  # success redirect url is required
  if confirmable_enabled? && !@redirect_url
    return render_create_error_missing_confirm_success_url
  end

  # if whitelist is set, validate redirect_url against whitelist
  if DeviseTokenAuth.redirect_whitelist
    unless DeviseTokenAuth::Url.whitelisted?(@redirect_url)
      return render_create_error_redirect_url_not_allowed
    end
  end

  begin
    # override email confirmation, must be sent manually from ctrl
    resource_class.set_callback("create", :after, :send_on_create_confirmation_instructions)
    resource_class.skip_callback("create", :after, :send_on_create_confirmation_instructions)
    if @resource.respond_to? :skip_confirmation_notification!
      # Fix duplicate e-mails by disabling Devise confirmation e-mail
      @resource.skip_confirmation_notification!
    end
    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, @token = @resource.create_token

        @resource.save!

        update_auth_header
      end
      render_create_success
    else
      clean_up_passwords @resource
      render_create_error
    end
  rescue ActiveRecord::RecordNotUnique
    clean_up_passwords @resource
    render_create_error_email_already_exists
  end
end

#destroyObject



87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 87

def destroy
  if @resource
    @resource.destroy
    yield @resource if block_given?

    render_destroy_success
  else
    render_destroy_error
  end
end

#sign_up_paramsObject



98
99
100
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 98

def 
  params.permit([*params_for_resource(:sign_up), :confirm_success_url])
end

#updateObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 74

def update
  if @resource
    if @resource.send(resource_update_method, )
      yield @resource if block_given?
      render_update_success
    else
      render_update_error
    end
  else
    render_update_error_user_not_found
  end
end