Class: Sixsense::AuthController
- Defined in:
- lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb
Class Method Summary collapse
-
.is_admin ⇒ Object
TODO: Convert to genuine Goldberg role check?.
- .is_site_admin ⇒ Object
- .logger ⇒ Object
- .login_goldberg(cookies, session) ⇒ Object
- .login_vb(cookies, session) ⇒ Object
- .logout(cookies) ⇒ Object
- .process_login(cookies, session) ⇒ Object
- .save_goldberg_cookie(cookies) ⇒ Object
- .save_vb_cookie(cookies) ⇒ Object
Class Method Details
.is_admin ⇒ Object
TODO: Convert to genuine Goldberg role check?
11 12 13 14 15 16 17 18 19 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 11 def self.is_admin if Goldberg.user if Goldberg.user.role.id == 3#4 #logger.info "User is admin" return true end end false end |
.is_site_admin ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 21 def self.is_site_admin if Goldberg.user if [3].include? Goldberg.user.role.id # , 4 #logger.info "User is site admin" return true end end false end |
.logger ⇒ Object
6 7 8 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 6 def self.logger ActionController::Base.logger end |
.login_goldberg(cookies, session) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 86 def self.login_goldberg(, session) return unless ([:goldberg_user_id] && [:goldberg_user_password]) begin user = Goldberg::User.find([:goldberg_user_id]) if Digest::MD5.hexdigest( user.password + COOKIE_SALT2 ) == [:goldberg_user_password] Goldberg.user = user logger.info "Found goldberguser by cookie!" else logger.info "WARNING: Found goldberguser by cookie, but hash mismatch!" end rescue => e logger.info "WARNING: Something went wrong during login_goldberg: ERROR: #{e.class} #{e.} #{e.backtrace.join("\n")}" end end |
.login_vb(cookies, session) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 102 def self.login_vb(, session) return unless ([:bbuserid] && [:bbpassword]) forumuser = nil begin forumuser = Remote::Vbulletin::User.find([:bbuserid]) rescue => e logger.info "WARNING: Something went wrong during login_vb: ERROR: #{e.class} #{e.} #{e.backtrace.join("\n")}" end return unless forumuser if forumuser.banned? logger.info "User is banned!!" return end if forumuser.sixuser.nil? logger.info "Has no sixuser" return end if Digest::MD5.hexdigest( forumuser.password + COOKIE_SALT ) == [:bbpassword] Sixsense.user = forumuser.sixuser logger.info "Found forumuser by cookie!" else logger.info "WARNING: Found forumuser by cookie, but hash mismatch!" end end |
.logout(cookies) ⇒ Object
31 32 33 34 35 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 31 def self.logout() .delete :goldberg_user_id if [:goldberg_user_id] .delete :goldberg_user_password if [:goldberg_user_password] .delete :sixsense if [:sixsense] end |
.process_login(cookies, session) ⇒ Object
37 38 39 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 37 def self.process_login(, session) session[:sixsense] ||= Hash.new Sixsense.user = if session[:sixsense][:user_id] logger.info "Finding user by session" Sixuser.find(session[:sixsense][:user_id]) else nil end # Try login from Goldberg Cookie when available login_goldberg(, session) unless Goldberg.user # Try to find Sixuser from Goldberg.user or vB cookie unless Sixsense.user if Goldberg.user Sixsense.user = Sixuser.find_by_goldberguser_id(Goldberg.user.id) logger.info "Found sixuser by goldbergid" if Sixsense.user end unless Sixsense.user # Else, Try login from vBulletin Cookie when available login_vb(, session) end end #unless Goldberg.user # DISABLED: No logging into Goldberg from vB or anything for now #if Sixsense.user # if Sixsense.user.goldberguser # Goldberg.user = Sixsense.user.goldberguser # end #end #end if Sixsense.user Sixsense.user.last_activity = Time.now # TODO: Evaluate if we should possibly only do this on specific actions ? Sixsense.user.save session[:sixsense][:user_id] ||= Sixsense.user.id session[:sixsense][:timezoneoffset] = if Sixsense.user.forumuser offset = Sixsense.user.forumuser.timezoneoffset.to_f offset unless offset == 0.0 end end session[:sixsense][:timezoneoffset] ||= "London" Time.zone = session[:sixsense][:timezoneoffset] Sixsense.zone_id = Sixsense.calc logger.info "#{Sixsense.user.name} (#{Sixsense.user.forumuser.id if Sixsense.user.forumuser}): #{Time.zone} - #{Sixsense.zone_id}" if Sixsense.user end |
.save_goldberg_cookie(cookies) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 127 def self.() [:goldberg_user_id] = { :value => Goldberg.user.id, :DOMAIN => DOMAIN, :expires => 1.year.from_now } [:goldberg_user_password] = { :value => Digest::MD5.hexdigest( Goldberg.user.password + COOKIE_SALT2 ), :DOMAIN => DOMAIN, :expires => 1.year.from_now } end |
.save_vb_cookie(cookies) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/six-updater-web/vendor/plugins/six-query/app/controllers/sixsense/auth_controller.rb', line 140 def self.() if Sixsense.user # Workaround for vBulletin missing begin if Sixsense.user.forumuser unless Sixsense.user.forumuser.banned? [:bbuserid] = { :value => Sixsense.user.forumuser.userid, :DOMAIN => DOMAIN, :expires => 1.year.from_now } [:bbpassword] = { # TODO: Shouldn't this be the password in Goldberg ? :D :value => Digest::MD5.hexdigest( Sixsense.user.forumuser.password + COOKIE_SALT ), :DOMAIN => DOMAIN, :expires => 1.year.from_now } end end rescue => e logger.info "WARNING: Something went wrong during save_vb_cookie: ERROR: #{e.class} #{e.} #{e.backtrace.join("\n")}" end end end |