Class: User

Inherits:
ApplicationRecord
  • Object
show all
Includes:
ConfigManager
Defined in:
app/models/user.rb

Overview

Publify user. TODO: Should belong to a blog

Constant Summary collapse

ADMIN =
"admin"
PUBLISHER =
"publisher"
CONTRIBUTOR =
"contributor"
STATUS =
%w(active inactive).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConfigManager

append_features, #canonicalize

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



36
37
38
# File 'app/models/user.rb', line 36

def filename
  @filename
end

Class Method Details

.saltObject



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

def self.salt
  "20ac4d290c2293702c64b3b287ae5ea79b26a5c1"
end

.to_prefixObject



100
101
102
# File 'app/models/user.rb', line 100

def self.to_prefix
  "author"
end

Instance Method Details

#active_for_authentication?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/models/user.rb', line 92

def active_for_authentication?
  super && state == "active"
end

#admin?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'app/models/user.rb', line 122

def admin?
  profile == User::ADMIN
end

#article_counterObject



104
105
106
# File 'app/models/user.rb', line 104

def article_counter
  articles.size
end

#devise_valid_password?Object

Authenticate users with old password hashes



75
# File 'app/models/user.rb', line 75

alias devise_valid_password? valid_password?

#display_nameObject



108
109
110
111
112
113
114
115
116
# File 'app/models/user.rb', line 108

def display_name
  if nickname.present?
    nickname
  elsif name.present?
    name
  else
    
  end
end

#display_namesObject



69
70
71
72
# File 'app/models/user.rb', line 69

def display_names
  [:login, :nickname, :firstname, :lastname, :first_and_last_name].
    map { |f| send(f) }.delete_if(&:empty?)
end

#first_and_last_nameObject



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

def first_and_last_name
  return "" unless firstname.present? && lastname.present?

  "#{firstname} #{lastname}"
end

#has_twitter_configured?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'app/models/user.rb', line 133

def has_twitter_configured?
  twitter_oauth_token.present? && twitter_oauth_token_secret.present?
end


118
119
120
# File 'app/models/user.rb', line 118

def permalink
  
end

#text_filterObject



96
97
98
# File 'app/models/user.rb', line 96

def text_filter
  TextFilter.make_filter(text_filter_name)
end

#update_twitter_profile_image(img) ⇒ Object



126
127
128
129
130
131
# File 'app/models/user.rb', line 126

def update_twitter_profile_image(img)
  return if twitter_profile_image == img

  self.twitter_profile_image = img
  save
end

#valid_password?(password) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/user.rb', line 77

def valid_password?(password)
  devise_valid_password?(password)
rescue BCrypt::Errors::InvalidHash
  digest = Digest::SHA1.hexdigest("#{self.class.salt}--#{password}--")
  if digest == encrypted_password
    # Update old SHA1 password with new Devise ByCrypt password
    self.encrypted_password = password_digest(password)
    save
    true
  else
    # If not BCrypt password and not old SHA1 password deny access
    false
  end
end