Class: User

Inherits:
ApplicationRecord show all
Defined in:
app/models/user.rb

Overview

This model manage the users

Relations

has many Happening

Validates

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adminBoolean

Returns [true] if User is an admin.

Returns:

  • (Boolean)
    true

    if User is an admin



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#confirmation_sent_atDateTime

Returns when the confirmation email was sent.

Returns:

  • (DateTime)

    when the confirmation email was sent



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#confirmation_tokenString

Returns confirmation token to check email.

Returns:

  • (String)

    confirmation token to check email



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#confirmed_atDateTime

Returns when email is confirmed.

Returns:

  • (DateTime)

    when email is confirmed



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#created_atDateTime

Returns when the record was created.

Returns:

  • (DateTime)

    when the record was created



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#current_sign_in_atDateTime

Returns Time of current sign in.

Returns:

  • (DateTime)

    Time of current sign in



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#current_sign_in_ipInet

Returns ip of current sign in.

Returns:

  • (Inet)

    ip of current sign in



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#editorBoolean

Returns [true] if User is an editor.

Returns:

  • (Boolean)
    true

    if User is an editor



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#emailString

Returns unique contact and login name for User.

Returns:

  • (String)

    unique contact and login name for User



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#faileds_attemptsInteger

Returns number of failed login recived.

Returns:

  • (Integer)

    number of failed login recived



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#idInteger

Returns unique identifier for User.

Returns:

  • (Integer)

    unique identifier for User



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#last_sign_in_atDateTime

Returns Time of last sign in.

Returns:

  • (DateTime)

    Time of last sign in



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#last_sign_in_ipInet

Returns ip of last sign in.

Returns:

  • (Inet)

    ip of last sign in



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#locked_atDateTime

Returns when User was locked.

Returns:

  • (DateTime)

    when User was locked



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#passwordObject

Returns the value of attribute password.



60
61
62
# File 'app/models/user.rb', line 60

def password
  @password
end

#sign_in_countInteger

Returns sign in count for User, default is 0, null is false.

Returns:

  • (Integer)

    sign in count for User, default is 0, null is false



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#unconfirmed_emailString

Returns address to check before an email chand.

Returns:

  • (String)

    address to check before an email chand



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#unlock_tockenString

Returns tocken to unlock an User.

Returns:

  • (String)

    tocken to unlock an User



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#updated_atDateTime

Returns when the record was updated.

Returns:

  • (DateTime)

    when the record was updated



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

#usernameString

Returns unique username for user.

Returns:

  • (String)

    unique username for user



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
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 47

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise *RAILS_DEVISE_MODULES
  has_many :tickets, dependent: :destroy
  has_and_belongs_to_many :groups
  has_many :events, through: :groups
  scope :editors, -> { where editor: true }
  scope :admins, -> { where admin: true }
  scope :member, -> { where member: true }
  before_validation :add_username, on: :create
  validates :username, presence: true, uniqueness: true
  unless RAILS_DEVISE_DATABASE_AUTHENTICATABLE
    attr_accessor :password
  end

  # Make gravatar url from email
  # @return [String] gravatar user url
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end

  # @return [String] name and/or surname if presents, otherwise return username or email
  # @example User without name, surname, and username
  #   user = User.new email: '[email protected]'
  #   user.title -> '[email protected]'
  # @example user with username
  #   user = User.new email: '[email protected]', username: 'test'
  #   user.title -> 'test'
  # @example user with all data
  #   user = User.new name: 'Mario', surname: 'Rossi', username....
  #   user.title: 'Mario Rossi'
  def title
    name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
  end

  private

  # if username is empty, set username value as email
  # @return [String] username value
  def add_username
    self.username = email unless username?
    username
  end
end

Instance Method Details

#avatar_urlString

Make gravatar url from email

Returns:

  • (String)

    gravatar user url



65
66
67
68
# File 'app/models/user.rb', line 65

def avatar_url
  hash = Digest::MD5.hexdigest(email)
  "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
end

#titleString

Returns name and/or surname if presents, otherwise return username or email.

Examples:

User without name, surname, and username

user = User.new email: '[email protected]'
user.title -> '[email protected]'

user with username

user = User.new email: '[email protected]', username: 'test'
user.title -> 'test'

user with all data

user = User.new name: 'Mario', surname: 'Rossi', username....
user.title: 'Mario Rossi'

Returns:

  • (String)

    name and/or surname if presents, otherwise return username or email



80
81
82
# File 'app/models/user.rb', line 80

def title
  name.present? || surname.present? ? [ name, surname ].join(" ") : username || email
end