Class: User

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

Overview

This model manage the users

Relations

has many Happening

Validates

  • presence of username

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#confirmation_sent_atDateTime

Returns when the confirmation email was sent.

Returns:

  • (DateTime)

    when the confirmation email was sent



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#confirmation_tokenString

Returns confirmation token to check email.

Returns:

  • (String)

    confirmation token to check email



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#confirmed_atDateTime

Returns when email is confirmed.

Returns:

  • (DateTime)

    when email is confirmed



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#created_atDateTime

Returns when the record was created.

Returns:

  • (DateTime)

    when the record was created



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#current_sign_in_atDateTime

Returns Time of current sign in.

Returns:

  • (DateTime)

    Time of current sign in



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#current_sign_in_ipInet

Returns ip of current sign in.

Returns:

  • (Inet)

    ip of current sign in



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#editorBoolean

Returns [true] if User is an editor.

Returns:

  • (Boolean)
    true

    if User is an editor



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#emailString

Returns unique contact and login name for User.

Returns:

  • (String)

    unique contact and login name for User



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#faileds_attemptsInteger

Returns number of failed login recived.

Returns:

  • (Integer)

    number of failed login recived



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#idInteger

Returns unique identifier for User.

Returns:

  • (Integer)

    unique identifier for User



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#last_sign_in_atDateTime

Returns Time of last sign in.

Returns:

  • (DateTime)

    Time of last sign in



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#last_sign_in_ipInet

Returns ip of last sign in.

Returns:

  • (Inet)

    ip of last sign in



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#locked_atDateTime

Returns when User was locked.

Returns:

  • (DateTime)

    when User was locked



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

  # @return [String] gravatar url for user
  def avatar_url
    hash = Digest::MD5.hexdigest(email)
    "https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon"
  end
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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#unconfirmed_emailString

Returns address to check before an email chand.

Returns:

  • (String)

    address to check before an email chand



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#unlock_tockenString

Returns tocken to unlock an User.

Returns:

  • (String)

    tocken to unlock an User



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

#updated_atDateTime

Returns when the record was updated.

Returns:

  • (DateTime)

    when the record was updated



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/user.rb', line 45

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :timeoutable, :trackable,
         :lockable
  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 }

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

Instance Method Details

#avatar_urlString

Returns gravatar url for user.

Returns:

  • (String)

    gravatar url for user



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

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