Class: Auth::RegistrationsController

Inherits:
Devise::RegistrationsController
  • Object
show all
Includes:
Concerns::DeviseConcern, Concerns::TokenConcern
Defined in:
app/controllers/auth/registrations_controller.rb

Constant Summary collapse

TCONDITIONS =
{:only => [:update,:destroy,:show]}

Instance Method Summary collapse

Instance Method Details

#authenticate_scope!Object

only required in case of registrations controller, for the update action, and destroy actions, wherein we need to make sure that the resource is authenticated before doing anything. have overridden the devise method here. it has nothing to do with the simple_token_authentication being done in other controllers. this was just done here because we cannot add simple_token_authentication to a devise controller.



97
98
99
100
101
102
# File 'app/controllers/auth/registrations_controller.rb', line 97

def authenticate_scope!
  
 
  do_before_request  

end

#create {|resource| ... } ⇒ Object

before_action :check_recaptcha, only: [:create, :update]

Yields:

  • (resource)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/auth/registrations_controller.rb', line 11

def create
	check_recaptcha
	build_resource()
	resource.m_client = self.m_client
 	resource.set_client_authentication
    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        (resource_name, resource)
        respond_with resource, location: (resource)
      else
        set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: (resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource
    end

end

#respond_with(*args) ⇒ Object

had to do this, cuz after update, the authentication token changes, and that needs to be communicated back to the client, or they will never be able to update or access the resource again.



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

def respond_with(*args)
  if is_json_request?
    if args[0] && args[0].respond_to?(:authentication_token)
      render :json => args[0] 
    else
      super(*args)
    end
  else
    super(*args)
  end
end

#respond_with_navigational(*args, &block) ⇒ Object



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

def respond_with_navigational(*args, &block)
  if is_json_request?
    respond_with(*args)
  else
    respond_with(*args) do |format|
      format.any(*navigational_formats, &block)
    end
  end
end

#update {|resource| ... } ⇒ Object

Yields:

  • (resource)


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

def update
	check_recaptcha
	self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
    prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
    ## added these two lines
    resource.m_client = self.m_client
 	resource.set_client_authentication
 	## end.
 	puts " ----- the account update params are: --- "
 	k = 
 	puts k
 	puts " ----- -------------------"
    resource_updated = update_resource(resource, k)
    
    yield resource if block_given?
    if resource_updated
      if is_flashing_format?
        flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
          :update_needs_confirmation : :updated
        set_flash_message :notice, flash_key
      end
       resource_name, resource, bypass: true
      respond_with resource, location: after_update_path_for(resource)
    else
      clean_up_passwords resource
      respond_with resource
    end
end