module Blunt::Controller
Private Instance Methods
access_token()
click to toggle source
# File lib/blunt/controller.rb, line 49 def access_token @access_token ||= begin encoded_jwt = get_access_token if encoded_jwt.nil? || encoded_jwt.empty? nil else Token.new(encoded_jwt) end end end
authenticate!()
click to toggle source
# File lib/blunt/controller.rb, line 27 def authenticate! redirect_to '/login' unless authenticated? end
authenticated?()
click to toggle source
# File lib/blunt/controller.rb, line 31 def authenticated? !!current_user end
current_user()
click to toggle source
# File lib/blunt/controller.rb, line 35 def current_user @current_user ||= begin user = begin if access_token && access_token.valid? UserRepository.new.find(access_token.sub) end rescue nil end set_access_token(access_token.to_s) user end end
login!(params = {})
click to toggle source
# File lib/blunt/controller.rb, line 13 def login!(params = {}) if token = Blunt.login(params) set_access_token(token.to_s) else unset_access_token end end
logout!()
click to toggle source
# File lib/blunt/controller.rb, line 21 def logout! access_token && access_token.invalidate! @current_user = nil unset_access_token end
signup!(params = {})
click to toggle source
# File lib/blunt/controller.rb, line 7 def signup!(params = {}) if user = Blunt.signup(params) login!(user) end end