Module: Pixnet::SSO::ControllerMethods
- Defined in:
- lib/pixnet-sso/controller_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
- #current_user ⇒ Object
- #current_user=(new_user) ⇒ Object
-
#get_login_user(type = 'pixnet') ⇒ Object
sso2.
- #logged_in? ⇒ Boolean
- #login_from_cookie ⇒ Object
- #login_from_session ⇒ Object
- #login_required ⇒ Object
Class Method Details
.included(base) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/pixnet-sso/controller_methods.rb', line 59 def self.included(base) base.helper_method :logged_in? base.helper_method :current_user base.helper_method :login_required #sso1 base.helper_method :redirect_back_or_default base.helper_method :get_login_user end |
Instance Method Details
#current_user ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/pixnet-sso/controller_methods.rb', line 8 def current_user if Pixnet::SSO::Config.version == 1 @current_user ||= login_from_session unless @current_user == false else @current_user ||= unless @current_user == false end end |
#current_user=(new_user) ⇒ Object
16 17 18 19 |
# File 'lib/pixnet-sso/controller_methods.rb', line 16 def current_user=(new_user) session[:user_id] = new_user ? new_user.id : nil @current_user = new_user || false end |
#get_login_user(type = 'pixnet') ⇒ Object
sso2
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pixnet-sso/controller_methods.rb', line 45 def get_login_user(type = 'pixnet') pixdata = ['pixdata'] ? JSON::parse(['pixdata']) : nil if (!pixdata or !pixdata['sig']) return nil end sig = pixdata['sig'] str = ['pixdata'].gsub(/,"sig":\d+/, '') crc32 = Zlib.crc32("#{str}#{pixdata['nonce']}#{Pixnet::SSO::Config.sso_secret}") return nil unless sig == crc32 return pixdata if 'pixnet' == type && pixdata['user_name'] return pixdata if 'openid' == type && pixdata['openid'] return nil end |
#logged_in? ⇒ Boolean
4 5 6 |
# File 'lib/pixnet-sso/controller_methods.rb', line 4 def logged_in? !!current_user end |
#login_from_cookie ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/pixnet-sso/controller_methods.rb', line 25 def pixdata = get_login_user if pixdata sso = Pixnet::SSO::App.new self.current_user = sso.get_user(pixdata['user_name']) else self.current_user = nil end end |
#login_from_session ⇒ Object
21 22 23 |
# File 'lib/pixnet-sso/controller_methods.rb', line 21 def login_from_session self.current_user = Pixnet::SSO::Config.user_klass.find(session[:user_id]) if session[:user_id] end |
#login_required ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/pixnet-sso/controller_methods.rb', line 35 def login_required if logged_in? return true else redirect_to root_path return false end end |