class OpenShift::MongoAuthService

Public Class Methods

new(auth_info=nil) click to toggle source
# File lib/openshift/mongo_auth_service.rb, line 6
def initialize(auth_info=nil)
  @salt = (auth_info || Rails.configuration.auth)[:salt]
end

Public Instance Methods

authenticate(login, password) click to toggle source
# File lib/openshift/mongo_auth_service.rb, line 19
def authenticate(login, password)
  raise OpenShift::AccessDeniedException if login.nil? || login.empty? || password.nil? || password.empty?
  encoded_password = Digest::MD5.hexdigest(Digest::MD5.hexdigest(password) + @salt)

  account = UserAccount.find_by(user: login, password_hash: encoded_password)
  {:username => account.user}
rescue Mongoid::Errors::DocumentNotFound
  raise OpenShift::AccessDeniedException
end
register_user(login, password) click to toggle source
# File lib/openshift/mongo_auth_service.rb, line 10
def register_user(login, password)
  accnt = UserAccount.new(user: login, password: password)
  accnt.save
end
user_exists?(login) click to toggle source
# File lib/openshift/mongo_auth_service.rb, line 15
def user_exists?(login)
  UserAccount.where(user: login).count == 1
end