Module: Skyline::Authentication::User

Included in:
User
Defined in:
lib/skyline/authentication/user.rb

Overview

Use this module in your User model you want Skyline to use. By default Skyline

uses its own Skyline::User model, but you can specify your own using this
interface.

class User < ActiveRecord::Base

include Skyline::Authentication::User

def self.authenticate(email, password)
  self.first(:conditions => {:email => email.to_s.downcase, :password => encrypt(password.to_s)})
end

def identification
  self.id
end

def allow?(right_or_class, suffix = nil)
  true
end

def display_name
  self.name.present? ? self.name : self.email
end

end

Examples:

Usage

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.self.authenticate(email, password) ⇒ User

Return the logged in user when successfully authenticated

Parameters:

  • email (String)

    The e-mail address or username of the user.

  • password (String)

    The password the user entered.

Returns:

  • (User)

    an instance of the class this module includes

See Also:



43
44
45
# File 'lib/skyline/authentication/user.rb', line 43

def self.authenticate(email, password)
  raise "self.authenticate(email, password) is not implemented yet"
end

Instance Method Details

#allow?(right_or_class, suffix = nil) ⇒ Boolean

Check if a user has a specific right

Parameters:

  • right_or_class (String, Symbol, ~right_prefix)

    Can be a string or a symbol to check a specific right, or you can pass an object that responds to #right_prefix, right_prefix must return a string

  • suffix (String, Symbol) (defaults to: nil)

    A suffix to append to the right, mostly usefull in combination with an object

Returns:

  • (Boolean)

    true if the right exists in one of the roles fo the user

See Also:



66
67
68
# File 'lib/skyline/authentication/user.rb', line 66

def allow?(right_or_class, suffix = nil)
  raise "allow?(right_or_class, suffix = nil) is not implemented yet"
end

#display_nameString

Display the name or e-mailaddress of the user for display purposes.

Returns:

  • (String)

    The user’s name to be displayed in Skyline

See Also:



77
78
79
# File 'lib/skyline/authentication/user.rb', line 77

def display_name
  raise "display_name is not implemented yet"
end

#identificationInteger, String

Return the unique identifier for this user (probably the DB id)

Returns:

  • (Integer, String)

    an identification String or Integer



50
51
52
# File 'lib/skyline/authentication/user.rb', line 50

def identification
  raise "identification is not implemented yet"
end