Class: Auth::ApplicationController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/auth/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_resource!Object

will call authenticate_(first_key_in_the_auth_resources) if there is no currently signed in scoep will return true, for the first auth_resource that gives a current_(user/whatever) if nothing returns true, will redirect to not_found, use this function wherever you want to protect a controller just using devise authentication. only makes sense to use in the scope of the web app.



75
76
77
78
79
80
81
82
# File 'app/controllers/auth/application_controller.rb', line 75

def authenticate_resource!
	send("authenticate_#{Auth.configuration.auth_resources.keys.first.downcase}!") if (signed_in? == false)
	Auth.configuration.auth_resources.keys.each do |model|
		break if @resource_for_web_app = send("current_#{model.downcase}")
	end
	return if @resource_for_web_app
	not_found("Could not authenticate")
end

#check_for_create(obj) ⇒ Object



61
62
63
64
# File 'app/controllers/auth/application_controller.rb', line 61

def check_for_create(obj)
	not_found if obj.nil?
	obj.new_record? or not_found("this is not a new record")
end

#check_for_destroy(obj) ⇒ Object



66
67
68
# File 'app/controllers/auth/application_controller.rb', line 66

def check_for_destroy(obj)
	not_found("please provide a cart id") if obj.new_record?
end

#check_for_update(obj) ⇒ Object



55
56
57
58
59
# File 'app/controllers/auth/application_controller.rb', line 55

def check_for_update(obj)
	puts "Came to check for update."
	not_found if obj.nil?
   	not_found("please provide a valid id for the update") if obj.new_record?
end

#from_bson(bson_doc, klass) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/auth/application_controller.rb', line 16

def from_bson(bson_doc,klass)

	if !bson_doc.nil?

		user = Mongoid::Factory.from_db(klass,bson_doc)
		return user

	else

		return nil

	end

end

#from_view(view, klass) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/auth/application_controller.rb', line 31

def from_view(view,klass)

	if !view.nil? && view.count > 0

		user = Mongoid::Factory.from_db(klass,view.first)
		return user

	else

		return nil

	end

end

#not_found(error = 'Not Found') ⇒ Object

CURRENTLY BEING USED IN THE DUMMY APP IN OTP_CONTROLLER RENDERS A NOT FOUND RESPONSE, in case the user is not found.

Raises:

  • (ActionController::RoutingError)


49
50
51
# File 'app/controllers/auth/application_controller.rb', line 49

def not_found(error = 'Not Found')
	  raise ActionController::RoutingError.new(error)
end