Module: OAuthCampingPlugin::Views

Defined in:
lib/camping-oauth.rb

Overview

Views module for the OAuth Camping Plugin. The module will be plugged in to the main app views module using:

- extend to add class methods to the app views module
  • include_oauth_views to dynamically plugin the common OAuth views (e.g. authorize_view)

Example:

module CampingOAuthProvider::Views

extend OAuthCampingPlugin::Views

# …

include_oauth_views

end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authorize_viewObject

Returns the source code for the authorize_view



1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
# File 'lib/camping-oauth.rb', line 1013

def self.authorize_view
	<<-VIEW
	
def authorize
	div @info if @info
	form :action => R(OAuthAuthorizeToken), :method => 'post' do
		input :name => 'oauth_token', :type=>'hidden', :value=>@oauth_token;
		input :name => 'authorize', :type=>'checkbox';
		label 'Authorize token ' + @oauth_token, :for => 'authorize'; br
		
		input :type => 'submit', :name => 'authorize_btn', :value => 'Authorize'
		a "Cancel", :href=>"/applications"
	end
end

	VIEW
end

.common_oauth_viewsObject

Returns the source code for all common OAuth views such as error views (e.g. authorize_failure)



936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
# File 'lib/camping-oauth.rb', line 936

def self.common_oauth_views
	<<-VIEW_DEFS
	
def authorize_failure
	h1 "You have denied access to this token"
end

def authorize_failure_token_not_found
	h1 "Token not found"
end

def authorize_failure_invalidated
	h1 "Token could not be authorized since it has become invalid"
end		

def authorize_success
	h1 "You have successfully authorized access to this token"
	p @info
end	

def revoke_success
	h1 "You have successfully revoked access to this token"
	p @info
end	
	VIEW_DEFS
end

.register_viewObject

Returns the source code for the register_view



964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
# File 'lib/camping-oauth.rb', line 964

def self.register_view
	<<-VIEW

def new_application_registration
	h2 "New OAuth Consumer"
	h3 "Application Registration"
	div.info @info if @info
	form.new_app_reg! :action => R(OAuthRegisterApplication), :method => 'post' do
		label 'Name (*)', :for => 'name'; br
		input.app_name! :name => 'name', :type => 'text'; br

		label 'Url (*)', :for => 'url'; br
		input.url :name => 'url', :type => 'text'; br

		label 'Callback Url (*)', :for => 'callback_url'; br
		input.url :name => 'callback_url', :type => 'text'; br;

		label 'Support Url', :for => 'support_url'; br
		input.url :name => 'support_url', :type => 'text'; br;br;

		input :type => 'submit', :name => 'signup', :value => 'Register'
	end
end		

	VIEW
end

.registration_viewObject

Returns the source code for the registration_view



992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'lib/camping-oauth.rb', line 992

def self.registration_view
	<<-VIEW

def application_registration
	h2 "Application Registration"
	div @info if @info
	
	table.application_registration do
		tr { td "Name"; 			td @application.name}
		tr { td "Url"; 					td @application.url}
		tr { td "Support Url";		td @application.support_url}
		tr { td "Callback Url";	td @application.callback_url}
		tr { td "Key"; 				td @application.key}
		tr { td "Secret"; 			td @application.secret}
	end		
end		

	VIEW
end

.revoke_viewObject

Returns the source code for the revoke_view



1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
# File 'lib/camping-oauth.rb', line 1032

def self.revoke_view
	<<-VIEW
	
def revoke
	div @info if @info
	form :action => R(OAuthRevokeToken), :method => 'post' do
		input :name => 'oauth_token', :type=>'hidden', :value=>@token.token;
		input :name => 'revoke', :type=>'checkbox';
		label 'Revoke token ' + @token.token, :for => 'revoke'; br
		
		input :type => 'submit', :name => 'revoke_btn', :value => 'Revoke'
		a "Cancel", :href=>"/applications"
	end
end

	VIEW
end

Instance Method Details

#include_oauth_viewsObject

Includes all common OAuth views inside the views module using module_eval (this is why the call must be the last statement in the views module)



1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File 'lib/camping-oauth.rb', line 1052

def include_oauth_views
	module_eval OAuthCampingPlugin::Views.common_oauth_views
	
	module_eval do
		app_module_name = self.to_s.split("::").first	
		mab_class_name = "#{app_module_name}::Mab"	
		mab_class = mab_class_name.constantize

		unless mab_class.public_instance_methods.include? 'register' 
			module_eval OAuthCampingPlugin::Views.register_view
		end

		unless mab_class.public_instance_methods.include? 'application_registration' 
			module_eval OAuthCampingPlugin::Views.registration_view
		end
		
		unless mab_class.public_instance_methods.include? 'authorize' 
			module_eval OAuthCampingPlugin::Views.authorize_view
		end
		
		unless mab_class.public_instance_methods.include? 'revoke' 
			module_eval OAuthCampingPlugin::Views.revoke_view
		end
	end
	
end