mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
fix error on end of each request at cleanup_application
declaring self.method caused rails to error Signed-off-by: Reinier Balt <lrbalt@gmail.com>
This commit is contained in:
parent
033b4daf9a
commit
eb26f4f7b9
2 changed files with 62 additions and 62 deletions
|
|
@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
layout proc{ |controller| controller.mobile? ? "mobile" : "standard" }
|
layout proc{ |controller| controller.mobile? ? "mobile" : "standard" }
|
||||||
exempt_from_layout /\.js\.erb$/
|
exempt_from_layout /\.js\.erb$/
|
||||||
|
|
||||||
before_filter :check_for_deprecated_password_hash
|
before_filter :check_for_deprecated_password_hash
|
||||||
before_filter :set_session_expiration
|
before_filter :set_session_expiration
|
||||||
before_filter :set_time_zone
|
before_filter :set_time_zone
|
||||||
|
|
@ -24,12 +24,12 @@ class ApplicationController < ActionController::Base
|
||||||
prepend_before_filter :login_required
|
prepend_before_filter :login_required
|
||||||
prepend_before_filter :enable_mobile_content_negotiation
|
prepend_before_filter :enable_mobile_content_negotiation
|
||||||
after_filter :set_charset
|
after_filter :set_charset
|
||||||
|
|
||||||
# By default, sets the charset to UTF-8 if it isn't already set
|
# By default, sets the charset to UTF-8 if it isn't already set
|
||||||
def set_charset
|
def set_charset
|
||||||
headers["Content-Type"] ||= "text/html; charset=UTF-8"
|
headers["Content-Type"] ||= "text/html; charset=UTF-8"
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_locale
|
def set_locale
|
||||||
locale = params[:locale] # specifying a locale in the request takes precedence
|
locale = params[:locale] # specifying a locale in the request takes precedence
|
||||||
locale = locale || prefs.locale unless current_user.nil? # otherwise, the locale of the currently logged in user takes over
|
locale = locale || prefs.locale unless current_user.nil? # otherwise, the locale of the currently logged in user takes over
|
||||||
|
|
@ -37,7 +37,7 @@ class ApplicationController < ActionController::Base
|
||||||
I18n.locale = locale.nil? ? I18n.default_locale : (I18n::available_locales.include?(locale.to_sym) ? locale : I18n.default_locale)
|
I18n.locale = locale.nil? ? I18n.default_locale : (I18n::available_locales.include?(locale.to_sym) ? locale : I18n.default_locale)
|
||||||
logger.debug("Selected '#{I18n.locale}' as locale")
|
logger.debug("Selected '#{I18n.locale}' as locale")
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_session_expiration
|
def set_session_expiration
|
||||||
# http://wiki.rubyonrails.com/rails/show/HowtoChangeSessionOptions
|
# http://wiki.rubyonrails.com/rails/show/HowtoChangeSessionOptions
|
||||||
unless session == nil
|
unless session == nil
|
||||||
|
|
@ -68,11 +68,11 @@ class ApplicationController < ActionController::Base
|
||||||
redirect_to change_password_user_path current_user
|
redirect_to change_password_user_path current_user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_failure message, status = 404
|
def render_failure message, status = 404
|
||||||
render :text => message, :status => status
|
render :text => message, :status => status
|
||||||
end
|
end
|
||||||
|
|
||||||
# def rescue_action(exception)
|
# def rescue_action(exception)
|
||||||
# log_error(exception) if logger
|
# log_error(exception) if logger
|
||||||
# respond_to do |format|
|
# respond_to do |format|
|
||||||
|
|
@ -84,7 +84,7 @@ class ApplicationController < ActionController::Base
|
||||||
# format.xml { render :text => 'An error occurred on the server.' + $! }
|
# format.xml { render :text => 'An error occurred on the server.' + $! }
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# Returns a count of next actions in the given context or project The result
|
# Returns a count of next actions in the given context or project The result
|
||||||
# is count and a string descriptor, correctly pluralised if there are no
|
# is count and a string descriptor, correctly pluralised if there are no
|
||||||
# actions or multiple actions
|
# actions or multiple actions
|
||||||
|
|
@ -94,7 +94,7 @@ class ApplicationController < ActionController::Base
|
||||||
word = count == 1 ? string.singularize : string.pluralize
|
word = count == 1 ? string.singularize : string.pluralize
|
||||||
return count.to_s + " " + word
|
return count.to_s + " " + word
|
||||||
end
|
end
|
||||||
|
|
||||||
def count_undone_todos(todos_parent)
|
def count_undone_todos(todos_parent)
|
||||||
if todos_parent.nil?
|
if todos_parent.nil?
|
||||||
count = 0
|
count = 0
|
||||||
|
|
@ -162,11 +162,11 @@ class ApplicationController < ActionController::Base
|
||||||
def create_todo_from_recurring_todo(rt, date=nil)
|
def create_todo_from_recurring_todo(rt, date=nil)
|
||||||
# create todo and initialize with data from recurring_todo rt
|
# create todo and initialize with data from recurring_todo rt
|
||||||
todo = current_user.todos.build( { :description => rt.description, :notes => rt.notes, :project_id => rt.project_id, :context_id => rt.context_id})
|
todo = current_user.todos.build( { :description => rt.description, :notes => rt.notes, :project_id => rt.project_id, :context_id => rt.context_id})
|
||||||
|
|
||||||
# set dates
|
# set dates
|
||||||
todo.recurring_todo_id = rt.id
|
todo.recurring_todo_id = rt.id
|
||||||
todo.due = rt.get_due_date(date)
|
todo.due = rt.get_due_date(date)
|
||||||
|
|
||||||
show_from_date = rt.get_show_from_date(date)
|
show_from_date = rt.get_show_from_date(date)
|
||||||
if show_from_date.nil?
|
if show_from_date.nil?
|
||||||
todo.show_from=nil
|
todo.show_from=nil
|
||||||
|
|
@ -174,20 +174,20 @@ class ApplicationController < ActionController::Base
|
||||||
# make sure that show_from is not in the past
|
# make sure that show_from is not in the past
|
||||||
todo.show_from = show_from_date < Time.zone.now ? nil : show_from_date
|
todo.show_from = show_from_date < Time.zone.now ? nil : show_from_date
|
||||||
end
|
end
|
||||||
|
|
||||||
saved = todo.save
|
saved = todo.save
|
||||||
if saved
|
if saved
|
||||||
todo.tag_with(rt.tag_list)
|
todo.tag_with(rt.tag_list)
|
||||||
todo.tags.reload
|
todo.tags.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
# increate number of occurences created from recurring todo
|
# increate number of occurences created from recurring todo
|
||||||
rt.inc_occurences
|
rt.inc_occurences
|
||||||
|
|
||||||
# mark recurring todo complete if there are no next actions left
|
# mark recurring todo complete if there are no next actions left
|
||||||
checkdate = todo.due.nil? ? todo.show_from : todo.due
|
checkdate = todo.due.nil? ? todo.show_from : todo.due
|
||||||
rt.toggle_completion! unless rt.has_next_todo(checkdate)
|
rt.toggle_completion! unless rt.has_next_todo(checkdate)
|
||||||
|
|
||||||
return saved ? todo : nil
|
return saved ? todo : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -198,21 +198,21 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def admin_login_required
|
def admin_login_required
|
||||||
unless User.find_by_id_and_is_admin(session['user_id'], true)
|
unless User.find_by_id_and_is_admin(session['user_id'], true)
|
||||||
render :text => t('errors.user_unauthorized'), :status => 401
|
render :text => t('errors.user_unauthorized'), :status => 401
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_back_or_home
|
def redirect_back_or_home
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_back_or_default home_url }
|
format.html { redirect_back_or_default home_url }
|
||||||
format.m { redirect_back_or_default mobile_url }
|
format.m { redirect_back_or_default mobile_url }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def boolean_param(param_name)
|
def boolean_param(param_name)
|
||||||
return false if param_name.blank?
|
return false if param_name.blank?
|
||||||
s = params[param_name]
|
s = params[param_name]
|
||||||
|
|
@ -220,11 +220,11 @@ class ApplicationController < ActionController::Base
|
||||||
return true if s == true || s =~ /^true$/i
|
return true if s == true || s =~ /^true$/i
|
||||||
raise ArgumentError.new("invalid value for Boolean: \"#{s}\"")
|
raise ArgumentError.new("invalid value for Boolean: \"#{s}\"")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.openid_enabled?
|
def self.openid_enabled?
|
||||||
Tracks::Config.openid_enabled?
|
Tracks::Config.openid_enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
def openid_enabled?
|
def openid_enabled?
|
||||||
self.class.openid_enabled?
|
self.class.openid_enabled?
|
||||||
end
|
end
|
||||||
|
|
@ -244,18 +244,18 @@ class ApplicationController < ActionController::Base
|
||||||
def prefered_auth?
|
def prefered_auth?
|
||||||
self.class.prefered_auth?
|
self.class.prefered_auth?
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||||
start_of_this_day = Time.zone.now.beginning_of_day
|
start_of_this_day = Time.zone.now.beginning_of_day
|
||||||
completed_todos.completed_after(start_of_this_day).all(includes)
|
completed_todos.completed_after(start_of_this_day).all(includes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_done_this_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
def get_done_this_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||||
start_of_this_week = Time.zone.now.beginning_of_week
|
start_of_this_week = Time.zone.now.beginning_of_week
|
||||||
start_of_this_day = Time.zone.now.beginning_of_day
|
start_of_this_day = Time.zone.now.beginning_of_day
|
||||||
completed_todos.completed_after(start_of_this_week).completed_before(start_of_this_day).all(includes)
|
completed_todos.completed_after(start_of_this_week).completed_before(start_of_this_day).all(includes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_done_this_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
def get_done_this_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||||
start_of_this_month = Time.zone.now.beginning_of_month
|
start_of_this_month = Time.zone.now.beginning_of_month
|
||||||
start_of_this_week = Time.zone.now.beginning_of_week
|
start_of_this_week = Time.zone.now.beginning_of_week
|
||||||
|
|
@ -264,11 +264,11 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def parse_date_per_user_prefs( s )
|
def parse_date_per_user_prefs( s )
|
||||||
prefs.parse_date(s)
|
prefs.parse_date(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_data_for_sidebar
|
def init_data_for_sidebar
|
||||||
@completed_projects = current_user.projects.completed
|
@completed_projects = current_user.projects.completed
|
||||||
@hidden_projects = current_user.projects.hidden
|
@hidden_projects = current_user.projects.hidden
|
||||||
|
|
@ -276,25 +276,25 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
@active_contexts = current_user.contexts.active
|
@active_contexts = current_user.contexts.active
|
||||||
@hidden_contexts = current_user.contexts.hidden
|
@hidden_contexts = current_user.contexts.hidden
|
||||||
|
|
||||||
init_not_done_counts
|
init_not_done_counts
|
||||||
if prefs.show_hidden_projects_in_sidebar
|
if prefs.show_hidden_projects_in_sidebar
|
||||||
init_project_hidden_todo_counts(['project'])
|
init_project_hidden_todo_counts(['project'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_not_done_counts(parents = ['project','context'])
|
def init_not_done_counts(parents = ['project','context'])
|
||||||
parents.each do |parent|
|
parents.each do |parent|
|
||||||
eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || current_user.todos.active.count(:group => :#{parent}_id)")
|
eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || current_user.todos.active.count(:group => :#{parent}_id)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_project_hidden_todo_counts(parents = ['project','context'])
|
def init_project_hidden_todo_counts(parents = ['project','context'])
|
||||||
parents.each do |parent|
|
parents.each do |parent|
|
||||||
eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || current_user.todos.count(:conditions => ['state = ? or state = ?', 'project_hidden', 'active'], :group => :#{parent}_id)")
|
eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || current_user.todos.count(:conditions => ['state = ? or state = ?', 'project_hidden', 'active'], :group => :#{parent}_id)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the contents of the flash message from a controller Usage: notify
|
# Set the contents of the flash message from a controller Usage: notify
|
||||||
# :warning, "This is the message" Sets the flash of type 'warning' to "This is
|
# :warning, "This is the message" Sets the flash of type 'warning' to "This is
|
||||||
# the message"
|
# the message"
|
||||||
|
|
@ -302,7 +302,7 @@ class ApplicationController < ActionController::Base
|
||||||
flash[type] = message
|
flash[type] = message
|
||||||
logger.error("ERROR: #{message}") if type == :error
|
logger.error("ERROR: #{message}") if type == :error
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_time_zone
|
def set_time_zone
|
||||||
Time.zone = current_user.prefs.time_zone if logged_in?
|
Time.zone = current_user.prefs.time_zone if logged_in?
|
||||||
end
|
end
|
||||||
|
|
@ -311,5 +311,5 @@ class ApplicationController < ActionController::Base
|
||||||
# this counter can be used to handle the IE z-index bug
|
# this counter can be used to handle the IE z-index bug
|
||||||
@z_index_counter = 500
|
@z_index_counter = 500
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -65,10 +65,10 @@ class User < ActiveRecord::Base
|
||||||
todos_in_project.sort!{ |x, y| -(x.todos.active.count <=> y.todos.active.count) }
|
todos_in_project.sort!{ |x, y| -(x.todos.active.count <=> y.todos.active.count) }
|
||||||
todos_in_project.reject{ |p| p.todos.active.count > 0 }
|
todos_in_project.reject{ |p| p.todos.active.count > 0 }
|
||||||
sorted_project_ids = todos_in_project.map {|p| p.id}
|
sorted_project_ids = todos_in_project.map {|p| p.id}
|
||||||
|
|
||||||
all_project_ids = find(:all).map {|p| p.id}
|
all_project_ids = find(:all).map {|p| p.id}
|
||||||
other_project_ids = all_project_ids - sorted_project_ids
|
other_project_ids = all_project_ids - sorted_project_ids
|
||||||
|
|
||||||
update_positions(sorted_project_ids + other_project_ids)
|
update_positions(sorted_project_ids + other_project_ids)
|
||||||
|
|
||||||
return find(:all, :conditions => scope_conditions)
|
return find(:all, :conditions => scope_conditions)
|
||||||
|
|
@ -90,14 +90,14 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
|
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
|
||||||
has_one :preference, :dependent => :destroy
|
has_one :preference, :dependent => :destroy
|
||||||
|
|
||||||
attr_protected :is_admin
|
attr_protected :is_admin
|
||||||
|
|
||||||
validates_presence_of :login
|
validates_presence_of :login
|
||||||
validates_presence_of :password, :if => :password_required?
|
validates_presence_of :password, :if => :password_required?
|
||||||
validates_length_of :password, :within => 5..40, :if => :password_required?
|
validates_length_of :password, :within => 5..40, :if => :password_required?
|
||||||
validates_presence_of :password_confirmation, :if => :password_required?
|
validates_presence_of :password_confirmation, :if => :password_required?
|
||||||
validates_confirmation_of :password
|
validates_confirmation_of :password
|
||||||
validates_length_of :login, :within => 3..80
|
validates_length_of :login, :within => 3..80
|
||||||
validates_uniqueness_of :login, :on => :create
|
validates_uniqueness_of :login, :on => :create
|
||||||
validates_presence_of :open_id_url, :if => :using_openid?
|
validates_presence_of :open_id_url, :if => :using_openid?
|
||||||
|
|
@ -109,7 +109,7 @@ class User < ActiveRecord::Base
|
||||||
#for will_paginate plugin
|
#for will_paginate plugin
|
||||||
cattr_accessor :per_page
|
cattr_accessor :per_page
|
||||||
@@per_page = 5
|
@@per_page = 5
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
unless Tracks::Config.auth_schemes.include?(auth_type)
|
unless Tracks::Config.auth_schemes.include?(auth_type)
|
||||||
errors.add("auth_type", "not a valid authentication type (#{auth_type})")
|
errors.add("auth_type", "not a valid authentication type (#{auth_type})")
|
||||||
|
|
@ -127,41 +127,41 @@ class User < ActiveRecord::Base
|
||||||
return candidate if candidate.auth_type == 'database' and
|
return candidate if candidate.auth_type == 'database' and
|
||||||
candidate.password_matches? pass
|
candidate.password_matches? pass
|
||||||
end
|
end
|
||||||
|
|
||||||
if Tracks::Config.auth_schemes.include?('ldap')
|
if Tracks::Config.auth_schemes.include?('ldap')
|
||||||
return candidate if candidate.auth_type == 'ldap' && SimpleLdapAuthenticator.valid?(login, pass)
|
return candidate if candidate.auth_type == 'ldap' && SimpleLdapAuthenticator.valid?(login, pass)
|
||||||
end
|
end
|
||||||
|
|
||||||
if Tracks::Config.auth_schemes.include?('cas')
|
if Tracks::Config.auth_schemes.include?('cas')
|
||||||
# because we can not auth them with out thier real password we have to settle for this
|
# because we can not auth them with out thier real password we have to settle for this
|
||||||
return candidate if candidate.auth_type.eql?("cas")
|
return candidate if candidate.auth_type.eql?("cas")
|
||||||
end
|
end
|
||||||
|
|
||||||
if Tracks::Config.auth_schemes.include?('open_id')
|
if Tracks::Config.auth_schemes.include?('open_id')
|
||||||
# hope the user enters the correct data
|
# hope the user enters the correct data
|
||||||
return candidate if candidate.auth_type.eql?("open_id")
|
return candidate if candidate.auth_type.eql?("open_id")
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_by_open_id_url(raw_identity_url)
|
def self.find_by_open_id_url(raw_identity_url)
|
||||||
normalized_open_id_url = OpenIdAuthentication.normalize_identifier(raw_identity_url)
|
normalized_open_id_url = OpenIdAuthentication.normalize_identifier(raw_identity_url)
|
||||||
find(:first, :conditions => ['open_id_url = ?', normalized_open_id_url])
|
find(:first, :conditions => ['open_id_url = ?', normalized_open_id_url])
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.no_users_yet?
|
def self.no_users_yet?
|
||||||
count == 0
|
count == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_admin
|
def self.find_admin
|
||||||
find(:first, :conditions => [ "is_admin = ?", true ])
|
find(:first, :conditions => [ "is_admin = ?", true ])
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
login
|
login
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_name
|
def display_name
|
||||||
if first_name.blank? && last_name.blank?
|
if first_name.blank? && last_name.blank?
|
||||||
return login
|
return login
|
||||||
|
|
@ -172,13 +172,13 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
"#{first_name} #{last_name}"
|
"#{first_name} #{last_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_password(pass,pass_confirm)
|
def change_password(pass,pass_confirm)
|
||||||
self.password = pass
|
self.password = pass
|
||||||
self.password_confirmation = pass_confirm
|
self.password_confirmation = pass_confirm
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def time
|
def time
|
||||||
Time.now.in_time_zone(prefs.time_zone)
|
Time.now.in_time_zone(prefs.time_zone)
|
||||||
end
|
end
|
||||||
|
|
@ -186,19 +186,19 @@ class User < ActiveRecord::Base
|
||||||
def date
|
def date
|
||||||
time.midnight
|
time.midnight
|
||||||
end
|
end
|
||||||
|
|
||||||
def at_midnight(date)
|
def at_midnight(date)
|
||||||
return ActiveSupport::TimeZone[prefs.time_zone].local(date.year, date.month, date.day, 0, 0, 0)
|
return ActiveSupport::TimeZone[prefs.time_zone].local(date.year, date.month, date.day, 0, 0, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_token
|
def generate_token
|
||||||
self.token = self.class.sha1 "#{Time.now.to_i}#{rand}"
|
self.token = self.class.sha1 "#{Time.now.to_i}#{rand}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def remember_token?
|
def remember_token?
|
||||||
remember_token_expires_at && Time.now.utc < remember_token_expires_at
|
remember_token_expires_at && Time.now.utc < remember_token_expires_at
|
||||||
end
|
end
|
||||||
|
|
||||||
# These create and unset the fields required for remembering users between browser closes
|
# These create and unset the fields required for remembering users between browser closes
|
||||||
def remember_me
|
def remember_me
|
||||||
self.remember_token_expires_at = 2.weeks.from_now.utc
|
self.remember_token_expires_at = 2.weeks.from_now.utc
|
||||||
|
|
@ -227,40 +227,40 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def self.salted(s)
|
def salted(s)
|
||||||
"#{Tracks::Config.salt}--#{s}--"
|
"#{Tracks::Config.salt}--#{s}--"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sha1(s)
|
def sha1(s)
|
||||||
Digest::SHA1.hexdigest salted s
|
Digest::SHA1.hexdigest salted s
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hash(s)
|
def hash(s)
|
||||||
BCrypt::Password.create s
|
BCrypt::Password.create s
|
||||||
end
|
end
|
||||||
|
|
||||||
def crypt_password
|
def crypt_password
|
||||||
return if password.blank?
|
return if password.blank?
|
||||||
write_attribute("crypted_password", self.class.hash(password)) if password == password_confirmation
|
write_attribute("crypted_password", self.class.hash(password)) if password == password_confirmation
|
||||||
end
|
end
|
||||||
|
|
||||||
def password_required?
|
def password_required?
|
||||||
auth_type == 'database' && crypted_password.blank? || !password.blank?
|
auth_type == 'database' && crypted_password.blank? || !password.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def using_openid?
|
def using_openid?
|
||||||
auth_type == 'open_id'
|
auth_type == 'open_id'
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_open_id_url
|
def normalize_open_id_url
|
||||||
return if open_id_url.nil?
|
return if open_id_url.nil?
|
||||||
|
|
||||||
# fixup empty url value
|
# fixup empty url value
|
||||||
if open_id_url.empty?
|
if open_id_url.empty?
|
||||||
self.open_id_url = nil
|
self.open_id_url = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.open_id_url = OpenIdAuthentication.normalize_identifier(open_id_url)
|
self.open_id_url = OpenIdAuthentication.normalize_identifier(open_id_url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue