Class: User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- User
- Defined in:
- app/models/user.rb
Overview
Instance Attribute Summary collapse
-
#admin ⇒ Boolean
- true
-
if User is an admin.
-
#confirmation_sent_at ⇒ DateTime
When the confirmation email was sent.
-
#confirmation_token ⇒ String
Confirmation token to check email.
-
#confirmed_at ⇒ DateTime
When email is confirmed.
-
#created_at ⇒ DateTime
When the record was created.
-
#current_sign_in_at ⇒ DateTime
Time of current sign in.
-
#current_sign_in_ip ⇒ Inet
Ip of current sign in.
-
#editor ⇒ Boolean
- true
-
if User is an editor.
-
#email ⇒ String
Unique contact and login name for User.
-
#faileds_attempts ⇒ Integer
Number of failed login recived.
-
#id ⇒ Integer
Unique identifier for User.
-
#last_sign_in_at ⇒ DateTime
Time of last sign in.
-
#last_sign_in_ip ⇒ Inet
Ip of last sign in.
-
#locked_at ⇒ DateTime
When User was locked.
-
#password ⇒ Object
Returns the value of attribute password.
-
#sign_in_count ⇒ Integer
Sign in count for User, default is 0, null is false.
-
#unconfirmed_email ⇒ String
Address to check before an email chand.
-
#unlock_tocken ⇒ String
Tocken to unlock an User.
-
#updated_at ⇒ DateTime
When the record was updated.
-
#username ⇒ String
Unique username for user.
Instance Method Summary collapse
-
#avatar_url ⇒ String
Make gravatar url from email.
-
#title ⇒ String
Name and/or surname if presents, otherwise return username or email.
Instance Attribute Details
#admin ⇒ Boolean
Returns [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_at ⇒ DateTime
Returns 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_token ⇒ String
Returns 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_at ⇒ DateTime
Returns 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_at ⇒ DateTime
Returns 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_at ⇒ DateTime
Returns 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_ip ⇒ Inet
Returns 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 |
#editor ⇒ Boolean
Returns [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 |
#email ⇒ String
Returns 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_attempts ⇒ Integer
Returns 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 |
#id ⇒ Integer
Returns 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_at ⇒ DateTime
Returns 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_ip ⇒ Inet
Returns 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_at ⇒ DateTime
Returns 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 |
#password ⇒ Object
Returns the value of attribute password.
60 61 62 |
# File 'app/models/user.rb', line 60 def password @password end |
#sign_in_count ⇒ Integer
Returns 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_email ⇒ String
Returns 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_tocken ⇒ String
Returns 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_at ⇒ DateTime
Returns 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 |
#username ⇒ String
Returns 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_url ⇒ String
Make gravatar url from email
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 |
#title ⇒ String
Returns 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 |