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



95
96
97
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 95

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

#createObject



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

def create
  build_resource

  unless @resource.present?
    raise DeviseTokenAuth::Errors::NoResourceDefinedError,
          "#{self.class.name} #build_resource does not define @resource,"\
          ' execution stopped.'
  end

  # give redirect value from params priority
  @redirect_url = params.fetch(
    :confirm_success_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
  return render_create_error_redirect_url_not_allowed if blacklisted_redirect_url?(@redirect_url)

  # override email confirmation, must be sent manually from ctrl
  callback_name = defined?(ActiveRecord) && resource_class < ActiveRecord::Base ? :commit : :create
  resource_class.set_callback(callback_name, :after, :send_on_create_confirmation_instructions)
  resource_class.skip_callback(callback_name, :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
      })
    end

    if active_for_authentication?
      # email auth has been bypassed, authenticate user
      @token = @resource.create_token
      @resource.save!
      update_auth_header
    end

    render_create_success
  else
    clean_up_passwords @resource
    render_create_error
  end
end

#destroyObject



81
82
83
84
85
86
87
88
89
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 81

def destroy
  if @resource
    @resource.destroy
    yield @resource if block_given?
    render_destroy_success
  else
    render_destroy_error
  end
end

#sign_up_paramsObject



91
92
93
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 91

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

#updateObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 68

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