Module: SimpleUserAuth::Controller::ClassInstanceMethods

Defined in:
lib/simple_user_auth.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject

This is useful as a before filter, it will call your deny access callback unless signed in.



170
171
172
# File 'lib/simple_user_auth.rb', line 170

def authenticate
  return signed_in? ? true : failed_authentication
end

#current_userObject

Returns the user object of the currently signed in user.



148
149
150
# File 'lib/simple_user_auth.rb', line 148

def current_user
  @current_user ||= user_from_remember_token
end

#current_user?(user) ⇒ Boolean



165
166
167
# File 'lib/simple_user_auth.rb', line 165

def current_user?(user)
  user == current_user
end

#not_signed_in?Boolean



156
157
158
# File 'lib/simple_user_auth.rb', line 156

def not_signed_in?
  !signed_in?
end

#sign_in(user, args = {}) ⇒ Object

Signs in a user, if :remember_me is true, cookies will not expire.



138
139
140
141
142
143
144
145
# File 'lib/simple_user_auth.rb', line 138

def (user, args = {})
  if args[:remember_me]
    cookies.permanent.signed[remember_token_name] = [user.id, user.salt]
  else
    cookies.signed[remember_token_name] = [user.id, user.salt]
  end
  self.current_user = user
end

#sign_outObject



160
161
162
163
# File 'lib/simple_user_auth.rb', line 160

def sign_out
  cookies.delete(remember_token_name)
  self.current_user = nil
end

#signed_in?Boolean



152
153
154
# File 'lib/simple_user_auth.rb', line 152

def signed_in?
  !current_user.nil?
end