Class: DeviseTokenAuth::RegistrationsController

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

Instance Method Summary collapse

Instance Method Details

#account_update_paramsObject



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

def 
  params.permit(devise_parameter_sanitizer.for(: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
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 8

def create
  @resource            = resource_class.new()
  @resource.uid        = [:email]
  @resource.provider   = "email"

  # success redirect url is required
  unless params[:confirm_success_url]
    return render json: {
      status: 'error',
      data:   @resource,
      errors: ["Missing `confirm_success_url` param."]
    }, status: 403
  end

  begin
    if @resource.save
      @resource.send_confirmation_instructions({
        client_config: params[:config_name],
        redirect_url: params[:confirm_success_url]
      })

      render json: {
        status: 'success',
        data:   @resource.as_json
      }
    else
      clean_up_passwords @resource
      render json: {
        status: 'error',
        data:   @resource,
        errors: @resource.errors
      }, status: 403
    end
  rescue ActiveRecord::RecordNotUnique
    clean_up_passwords @resource
    render json: {
      status: 'error',
      data:   @resource,
      errors: ["An account already exists for #{@resource.email}"]
    }, status: 403
  end
end

#destroyObject



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

def destroy
  if @user
    @user.destroy

    render json: {
      status: 'success',
      message: "Account with uid #{@user.uid} has been destroyed."
    }
  else
    render json: {
      status: 'error',
      errors: ["Unable to locate account for destruction."]
    }, status: 404
  end
end

#sign_up_paramsObject



88
89
90
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 88

def 
  params.permit(devise_parameter_sanitizer.for(:sign_up))
end

#updateObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/devise_token_auth/registrations_controller.rb', line 51

def update
  if @user
    if @user.update_attributes()
      render json: {
        status: 'success',
        data:   @user.as_json
      }
    else
      render json: {
        status: 'error',
        errors: @user.errors
      }, status: 403
    end
  else
    render json: {
      status: 'error',
      errors: ["User not found."]
    }, status: 404
  end
end