Skip to content

Commit

Permalink
[api] Store available password hashing algorithms in constant variable
Browse files Browse the repository at this point in the history
and drop the two methods that were storing them before.
  • Loading branch information
bgeuken committed Mar 16, 2017
1 parent 6acdb30 commit a60da39
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/api/app/models/user.rb
Expand Up @@ -22,6 +22,8 @@ def groups(user)
class User < ApplicationRecord
include CanRenderModel

PASSWORD_HASH_TYPES = ['md5', 'md5crypt', 'sha256crypt']

has_many :taggings, dependent: :destroy
has_many :tags, through: :taggings

Expand Down Expand Up @@ -164,12 +166,6 @@ def self.default_user_state
::Configuration.registration == 'confirmation' ? 'unconfirmed' : 'confirmed'
end

# This method returns an array with the names of all available
# password hash types supported by this User class.
def self.password_hash_types
default_password_hash_types
end

# This method allows to execute a block while deactivating timestamp
# updating.
def self.execute_without_timestamps
Expand All @@ -181,11 +177,6 @@ def self.execute_without_timestamps
ApplicationRecord.record_timestamps = old_state
end

# This method returns an array which contains all valid hash types.
def self.default_password_hash_types
%w(md5 md5crypt sha256crypt)
end

def self.update_notifications(params, user = nil)
Event::Base.notification_events.each do |event_type|
values = params[event_type.to_s] || {}
Expand Down Expand Up @@ -332,7 +323,7 @@ def self.realname_for_login(login)
# state an password hash type being in the range of allowed values.
def validate
# validate state and password has type to be in the valid range of values
errors.add(:password_hash_type, 'must be in the list of hash types.') unless password_hash_type.in?(User.password_hash_types)
errors.add(:password_hash_type, 'must be in the list of hash types.') unless password_hash_type.in?(PASSWORD_HASH_TYPES)
# check that the state transition is valid
errors.add(:state, 'must be a valid new state from the current state.') unless state_transition_allowed?(@old_state, state)

Expand Down

0 comments on commit a60da39

Please sign in to comment.