Corrected with rubocop cop 'Rails/FindBy'.
This commit is contained in:
parent
8f54cf18f5
commit
6a41d0ee18
26 changed files with 76 additions and 80 deletions
|
@ -182,10 +182,6 @@ Rails/ActionFilter:
|
|||
Description: 'Enforces consistent use of action filter methods.'
|
||||
Enabled: false
|
||||
|
||||
Rails/FindBy:
|
||||
Description: 'Prefer find_by over where.first.'
|
||||
Enabled: false
|
||||
|
||||
Style/SymbolProc:
|
||||
Description: 'Use symbols as procs instead of blocks when possible.'
|
||||
Enabled: false
|
||||
|
|
|
@ -312,7 +312,7 @@ returns
|
|||
cache = self.cache_get( data[:id] )
|
||||
return cache if cache
|
||||
|
||||
record = self.where( id: data[:id] ).first
|
||||
record = self.find_by( id: data[:id] )
|
||||
self.cache_set( data[:id], record )
|
||||
return record
|
||||
elsif data[:name]
|
||||
|
@ -358,7 +358,7 @@ returns
|
|||
|
||||
def self.create_if_not_exists(data)
|
||||
if data[:id]
|
||||
record = self.where( id: data[:id] ).first
|
||||
record = self.find_by( id: data[:id] )
|
||||
return record if record
|
||||
elsif data[:name]
|
||||
records = self.where( name: data[:name] )
|
||||
|
|
|
@ -10,7 +10,7 @@ class Authorization < ApplicationModel
|
|||
validates :provider, presence: true
|
||||
|
||||
def self.find_from_hash(hash)
|
||||
auth = Authorization.where( provider: hash['provider'], uid: hash['uid'] ).first
|
||||
auth = Authorization.find_by( provider: hash['provider'], uid: hash['uid'] )
|
||||
if auth
|
||||
|
||||
# update auth tokens
|
||||
|
|
|
@ -89,11 +89,11 @@ add a avatar
|
|||
# check if avatar with url already exists
|
||||
avatar_already_exists = nil
|
||||
if data[:source] && !data[:source].empty?
|
||||
avatar_already_exists = Avatar.where(
|
||||
avatar_already_exists = Avatar.find_by(
|
||||
object_lookup_id: object_id,
|
||||
o_id: data[:o_id],
|
||||
source: data[:source],
|
||||
).first
|
||||
)
|
||||
end
|
||||
|
||||
# fetch image
|
||||
|
@ -208,11 +208,11 @@ set avatars as default
|
|||
|
||||
def self.set_default( object_name, o_id, avatar_id )
|
||||
object_id = ObjectLookup.by_name( object_name )
|
||||
avatar = Avatar.where(
|
||||
avatar = Avatar.find_by(
|
||||
object_lookup_id: object_id,
|
||||
o_id: o_id,
|
||||
id: avatar_id,
|
||||
).first
|
||||
)
|
||||
avatar.default = true
|
||||
avatar.save!
|
||||
|
||||
|
@ -308,9 +308,9 @@ returns:
|
|||
=end
|
||||
|
||||
def self.get_by_hash(hash)
|
||||
avatar = Avatar.where(
|
||||
avatar = Avatar.find_by(
|
||||
store_hash: hash,
|
||||
).first
|
||||
)
|
||||
return if !avatar
|
||||
file = Store.find(avatar.store_resize_id)
|
||||
end
|
||||
|
@ -329,11 +329,11 @@ returns:
|
|||
|
||||
def self.get_default(object_name, o_id)
|
||||
object_id = ObjectLookup.by_name( object_name )
|
||||
Avatar.where(
|
||||
Avatar.find_by(
|
||||
object_lookup_id: object_id,
|
||||
o_id: o_id,
|
||||
default: true,
|
||||
).first
|
||||
)
|
||||
end
|
||||
|
||||
def self.set_default_items(object_id, o_id, avatar_id)
|
||||
|
|
|
@ -360,10 +360,10 @@ class Channel::EmailParser
|
|||
|
||||
# create sender
|
||||
if mail[ 'x-zammad-customer-login'.to_sym ]
|
||||
user = User.where( login: mail[ 'x-zammad-customer-login'.to_sym ] ).first
|
||||
user = User.find_by( login: mail[ 'x-zammad-customer-login'.to_sym ] )
|
||||
end
|
||||
if !user
|
||||
user = User.where( email: mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email] ).first
|
||||
user = User.find_by( email: mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email] )
|
||||
end
|
||||
if !user
|
||||
user = user_create(
|
||||
|
@ -407,7 +407,7 @@ class Channel::EmailParser
|
|||
end
|
||||
|
||||
if state_type.name != 'new'
|
||||
ticket.state = Ticket::State.where( name: 'open' ).first
|
||||
ticket.state = Ticket::State.find_by( name: 'open' )
|
||||
ticket.save
|
||||
end
|
||||
end
|
||||
|
@ -420,8 +420,8 @@ class Channel::EmailParser
|
|||
group_id: channel[:group_id] || 1,
|
||||
customer_id: user.id,
|
||||
title: mail[:subject] || '',
|
||||
state_id: Ticket::State.where( name: 'new' ).first.id,
|
||||
priority_id: Ticket::Priority.where( name: '2 normal' ).first.id,
|
||||
state_id: Ticket::State.find_by( name: 'new' ).id,
|
||||
priority_id: Ticket::Priority.find_by( name: '2 normal' ).id,
|
||||
)
|
||||
|
||||
set_attributes_by_x_headers( ticket, 'ticket', mail )
|
||||
|
@ -435,8 +435,8 @@ class Channel::EmailParser
|
|||
# set attributes
|
||||
article = Ticket::Article.new(
|
||||
ticket_id: ticket.id,
|
||||
type_id: Ticket::Article::Type.where( name: 'email' ).first.id,
|
||||
sender_id: Ticket::Article::Sender.where( name: 'Customer' ).first.id,
|
||||
type_id: Ticket::Article::Type.find_by( name: 'email' ).id,
|
||||
sender_id: Ticket::Article::Sender.find_by( name: 'Customer' ).id,
|
||||
body: mail[:body],
|
||||
from: mail[:from],
|
||||
to: mail[:to],
|
||||
|
@ -500,7 +500,7 @@ class Channel::EmailParser
|
|||
def user_create(data)
|
||||
|
||||
# return existing
|
||||
user = User.where( login: data[:email].downcase ).first
|
||||
user = User.find_by( login: data[:email].downcase )
|
||||
return user if user
|
||||
|
||||
# create new user
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'net/imap'
|
|||
|
||||
module Channel::EmailSend
|
||||
def self.send(attr, notification = false)
|
||||
channel = Channel.where( area: 'Email::Outbound', active: true ).first
|
||||
channel = Channel.find_by( area: 'Email::Outbound', active: true )
|
||||
begin
|
||||
c = eval 'Channel::' + channel[:adapter] + '.new'
|
||||
c.send(attr, channel, notification)
|
||||
|
|
|
@ -75,7 +75,7 @@ class Channel::TWITTER2
|
|||
all_tweets.each do |tweet|
|
||||
|
||||
# check if tweet is already imported
|
||||
article = Ticket::Article.where( message_id: tweet.id.to_s ).first
|
||||
article = Ticket::Article.find_by( message_id: tweet.id.to_s )
|
||||
|
||||
# check if sender already exists
|
||||
next if article
|
||||
|
@ -141,11 +141,11 @@ class Channel::TWITTER2
|
|||
# create sender in db
|
||||
# puts tweet.inspect
|
||||
# user = User.where( :login => tweet.sender.screen_name ).first
|
||||
auth = Authorization.where( uid: sender.id, provider: 'twitter' ).first
|
||||
auth = Authorization.find_by( uid: sender.id, provider: 'twitter' )
|
||||
user = nil
|
||||
if auth
|
||||
Rails.logger.info 'user_id', auth.user_id
|
||||
user = User.where( id: auth.user_id ).first
|
||||
user = User.find_by( id: auth.user_id )
|
||||
end
|
||||
if !user
|
||||
Rails.logger.info 'create user...'
|
||||
|
@ -186,7 +186,7 @@ class Channel::TWITTER2
|
|||
# check if ticket exists
|
||||
if tweet.respond_to?('in_reply_to_status_id') && tweet.in_reply_to_status_id && tweet.in_reply_to_status_id.to_s != ''
|
||||
Rails.logger.info 'tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s
|
||||
article = Ticket::Article.where( message_id: tweet.in_reply_to_status_id.to_s ).first
|
||||
article = Ticket::Article.find_by( message_id: tweet.in_reply_to_status_id.to_s )
|
||||
if article
|
||||
Rails.logger.info 'article with id found tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s
|
||||
return article.ticket
|
||||
|
@ -194,14 +194,14 @@ class Channel::TWITTER2
|
|||
end
|
||||
|
||||
# find if record already exists
|
||||
article = Ticket::Article.where( message_id: tweet.id.to_s ).first
|
||||
article = Ticket::Article.find_by( message_id: tweet.id.to_s )
|
||||
if article
|
||||
return article.ticket
|
||||
end
|
||||
|
||||
ticket = nil
|
||||
if @article_type == 'twitter direct-message'
|
||||
ticket = Ticket.where( customer_id: user.id ).first
|
||||
ticket = Ticket.find_by( customer_id: user.id )
|
||||
if ticket
|
||||
state_type = Ticket::StateType.where( ticket.state.state_type_id )
|
||||
if state_type.name == 'closed' || state_type.name == 'closed'
|
||||
|
@ -210,17 +210,17 @@ class Channel::TWITTER2
|
|||
end
|
||||
end
|
||||
if !ticket
|
||||
group = Group.where( name: group ).first
|
||||
group = Group.find_by( name: group )
|
||||
group_id = 1
|
||||
if group
|
||||
group_id = group.id
|
||||
end
|
||||
state = Ticket::State.where( name: 'new' ).first
|
||||
state = Ticket::State.find_by( name: 'new' )
|
||||
state_id = 1
|
||||
if state
|
||||
state_id = state.id
|
||||
end
|
||||
priority = Ticket::Priority.where( name: '2 normal' ).first
|
||||
priority = Ticket::Priority.find_by( name: '2 normal' )
|
||||
priority_id = 1
|
||||
if priority
|
||||
priority_id = priority.id
|
||||
|
@ -240,12 +240,12 @@ class Channel::TWITTER2
|
|||
def fetch_article_create( _user, ticket, tweet, sender )
|
||||
|
||||
# find if record already exists
|
||||
article = Ticket::Article.where( message_id: tweet.id.to_s ).first
|
||||
article = Ticket::Article.find_by( message_id: tweet.id.to_s )
|
||||
return article if article
|
||||
|
||||
# set ticket state to open if not new
|
||||
if ticket.state.name != 'new'
|
||||
ticket.state = Ticket::State.where( name: 'open' ).first
|
||||
ticket.state = Ticket::State.find_by( name: 'open' )
|
||||
ticket.save
|
||||
end
|
||||
|
||||
|
@ -257,8 +257,8 @@ class Channel::TWITTER2
|
|||
|
||||
article = Ticket::Article.create(
|
||||
ticket_id: ticket.id,
|
||||
type_id: Ticket::Article::Type.where( name: @article_type ).first.id,
|
||||
sender_id: Ticket::Article::Sender.where( name: 'Customer' ).first.id,
|
||||
type_id: Ticket::Article::Type.find_by( name: @article_type ).id,
|
||||
sender_id: Ticket::Article::Sender.find_by( name: 'Customer' ).id,
|
||||
body: tweet.text,
|
||||
from: sender.name,
|
||||
to: to,
|
||||
|
@ -270,7 +270,7 @@ class Channel::TWITTER2
|
|||
|
||||
def send(attr, _notification = false)
|
||||
# Rails.logger.debug('tweeeeettttt!!!!!!')
|
||||
channel = Channel.where( area: 'Twitter::Inbound', active: true ).first
|
||||
channel = Channel.find_by( area: 'Twitter::Inbound', active: true )
|
||||
|
||||
client = Twitter::REST::Client.new do |config|
|
||||
config.consumer_key = channel[:options][:consumer_key]
|
||||
|
|
|
@ -76,7 +76,7 @@ add a new history entry for an object
|
|||
}
|
||||
history_record = nil
|
||||
if data[:id]
|
||||
history_record = History.where( id: data[:id] ).first
|
||||
history_record = History.find_by( id: data[:id] )
|
||||
end
|
||||
if history_record
|
||||
history_record.update_attributes(record)
|
||||
|
@ -98,7 +98,7 @@ remove whole history entries of an object
|
|||
=end
|
||||
|
||||
def self.remove( requested_object, requested_object_id )
|
||||
history_object = History::Object.where( name: requested_object ).first
|
||||
history_object = History::Object.find_by( name: requested_object )
|
||||
return if !history_object
|
||||
History.where(
|
||||
history_object_id: history_object.id,
|
||||
|
|
|
@ -152,7 +152,7 @@ class Link < ApplicationModel
|
|||
end
|
||||
|
||||
def self.link_type_get(data)
|
||||
linktype = Link::Type.where( name: data[:name] ).first
|
||||
linktype = Link::Type.find_by( name: data[:name] )
|
||||
if !linktype
|
||||
linktype = Link::Type.create(
|
||||
name: data[:name]
|
||||
|
@ -162,7 +162,7 @@ class Link < ApplicationModel
|
|||
end
|
||||
|
||||
def self.link_object_get(data)
|
||||
linkobject = Link::Object.where( name: data[:name] ).first
|
||||
linkobject = Link::Object.find_by( name: data[:name] )
|
||||
if !linkobject
|
||||
linkobject = Link::Object.create(
|
||||
name: data[:name]
|
||||
|
|
|
@ -17,7 +17,7 @@ class Locale < ApplicationModel
|
|||
|
||||
ActiveRecord::Base.transaction do
|
||||
result.data.each {|locale|
|
||||
exists = Locale.where(locale: locale['locale']).first
|
||||
exists = Locale.find_by(locale: locale['locale'])
|
||||
if exists
|
||||
exists.update(locale.symbolize_keys!)
|
||||
else
|
||||
|
|
|
@ -112,10 +112,10 @@ add a new attribute entry for an object
|
|||
data.delete(:object)
|
||||
|
||||
# check newest entry - is needed
|
||||
result = ObjectManager::Attribute.where(
|
||||
result = ObjectManager::Attribute.find_by(
|
||||
object_lookup_id: data[:object_lookup_id],
|
||||
name: data[:name],
|
||||
).first
|
||||
)
|
||||
if result
|
||||
# raise "ERROR: attribute #{data[:name]} for #{data[:object]} already exists"
|
||||
return result.update_attributes(data)
|
||||
|
@ -143,10 +143,10 @@ get the attribute model based on object and name
|
|||
data[:object_lookup_id] = ObjectLookup.by_name( data[:object] )
|
||||
end
|
||||
|
||||
ObjectManager::Attribute.where(
|
||||
ObjectManager::Attribute.find_by(
|
||||
object_lookup_id: data[:object_lookup_id],
|
||||
name: data[:name],
|
||||
).first
|
||||
)
|
||||
end
|
||||
|
||||
=begin
|
||||
|
|
|
@ -17,7 +17,7 @@ class Observer::User::Geo < ActiveRecord::Observer
|
|||
|
||||
# check if geo update is needed based on old/new location
|
||||
if record.id
|
||||
current = User.where( id: record.id ).first
|
||||
current = User.find_by( id: record.id )
|
||||
return if !current
|
||||
|
||||
current_location = {}
|
||||
|
|
|
@ -195,7 +195,7 @@ class Package < ApplicationModel
|
|||
}
|
||||
|
||||
# verify if package can get installed
|
||||
package_db = Package.where( name: meta[:name] ).first
|
||||
package_db = Package.find_by( name: meta[:name] )
|
||||
if package_db
|
||||
if !data[:reinstall]
|
||||
if Gem::Version.new( package_db.version ) == Gem::Version.new( meta[:version] )
|
||||
|
@ -253,7 +253,7 @@ class Package < ApplicationModel
|
|||
|
||||
# Package.reinstall( package_name )
|
||||
def self.reinstall(package_name)
|
||||
package = Package.where( name: package_name ).first
|
||||
package = Package.find_by( name: package_name )
|
||||
if !package
|
||||
raise "No such package '#{package_name}'"
|
||||
end
|
||||
|
@ -300,10 +300,10 @@ class Package < ApplicationModel
|
|||
end
|
||||
|
||||
# delete package
|
||||
record = Package.where(
|
||||
record = Package.find_by(
|
||||
name: meta[:name],
|
||||
version: meta[:version],
|
||||
).first
|
||||
)
|
||||
record.destroy
|
||||
|
||||
true
|
||||
|
@ -340,10 +340,10 @@ class Package < ApplicationModel
|
|||
end
|
||||
|
||||
def self._get_bin( name, version )
|
||||
package = Package.where(
|
||||
package = Package.find_by(
|
||||
name: name,
|
||||
version: version,
|
||||
).first
|
||||
)
|
||||
if !package
|
||||
raise "No such package '#{name}' version '#{version}'"
|
||||
end
|
||||
|
@ -475,20 +475,20 @@ class Package < ApplicationModel
|
|||
|
||||
# down
|
||||
if direction == 'reverse'
|
||||
done = Package::Migration.where( name: package.underscore, version: version ).first
|
||||
done = Package::Migration.find_by( name: package.underscore, version: version )
|
||||
next if !done
|
||||
logger.info "NOTICE: down package migration '#{migration}'"
|
||||
load "#{location}/#{migration}"
|
||||
classname = name.camelcase
|
||||
Kernel.const_get(classname).down
|
||||
record = Package::Migration.where( name: package.underscore, version: version ).first
|
||||
record = Package::Migration.find_by( name: package.underscore, version: version )
|
||||
if record
|
||||
record.destroy
|
||||
end
|
||||
|
||||
# up
|
||||
else
|
||||
done = Package::Migration.where( name: package.underscore, version: version ).first
|
||||
done = Package::Migration.find_by( name: package.underscore, version: version )
|
||||
next if done
|
||||
logger.info "NOTICE: up package migration '#{migration}'"
|
||||
load "#{location}/#{migration}"
|
||||
|
|
|
@ -124,7 +124,7 @@ class Scheduler < ApplicationModel
|
|||
def self.check( name, time_warning = 10, time_critical = 20 )
|
||||
time_warning_time = Time.now - time_warning.minutes
|
||||
time_critical_time = Time.now - time_critical.minutes
|
||||
scheduler = Scheduler.where( name: name ).first
|
||||
scheduler = Scheduler.find_by( name: name )
|
||||
if !scheduler
|
||||
puts "CRITICAL - no such scheduler jobs '#{name}'"
|
||||
return true
|
||||
|
|
|
@ -37,7 +37,7 @@ class Setting < ApplicationModel
|
|||
end
|
||||
|
||||
def self.set(name, value)
|
||||
setting = Setting.where( name: name ).first
|
||||
setting = Setting.find_by( name: name )
|
||||
if !setting
|
||||
raise "Can't find config setting '#{name}'"
|
||||
end
|
||||
|
|
|
@ -140,7 +140,7 @@ returns
|
|||
end
|
||||
|
||||
def content
|
||||
file = Store::File.where( id: self.store_file_id ).first
|
||||
file = Store::File.find_by( id: self.store_file_id )
|
||||
if !file
|
||||
raise "No such file #{ self.store_file_id }!"
|
||||
end
|
||||
|
@ -148,7 +148,7 @@ returns
|
|||
end
|
||||
|
||||
def provider
|
||||
file = Store::File.where( id: self.store_file_id ).first
|
||||
file = Store::File.find_by( id: self.store_file_id )
|
||||
if !file
|
||||
raise "No such file #{ self.store_file_id }!"
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ class Store
|
|||
def self.add(data)
|
||||
sha = Digest::SHA256.hexdigest( data )
|
||||
|
||||
file = Store::File.where( sha: sha ).first
|
||||
file = Store::File.find_by( sha: sha )
|
||||
if file.nil?
|
||||
|
||||
# load backend based on config
|
||||
|
@ -34,7 +34,7 @@ class Store
|
|||
c = adapter.get( self.sha )
|
||||
else
|
||||
# fallback until migration is done
|
||||
c = Store::Provider::DB.where( md5: self.md5 ).first.data
|
||||
c = Store::Provider::DB.find_by( md5: self.md5 ).data
|
||||
end
|
||||
c
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ class Store
|
|||
end
|
||||
|
||||
def self.get(sha)
|
||||
file = Store::Provider::DB.where( sha: sha ).first
|
||||
file = Store::Provider::DB.find_by( sha: sha )
|
||||
return if !file
|
||||
file.data
|
||||
end
|
||||
|
|
|
@ -81,7 +81,7 @@ class Tag < ApplicationModel
|
|||
return @@cache_item[ name ] if @@cache_item[ name ]
|
||||
|
||||
# lookup
|
||||
tag_item = Tag::Item.where( name: name ).first
|
||||
tag_item = Tag::Item.find_by( name: name )
|
||||
if tag_item
|
||||
@@cache_item[ name ] = tag_item.id
|
||||
return tag_item.id
|
||||
|
@ -112,7 +112,7 @@ class Tag < ApplicationModel
|
|||
return @@cache_object[ name ] if @@cache_object[ name ]
|
||||
|
||||
# lookup
|
||||
tag_object = Tag::Object.where( name: name ).first
|
||||
tag_object = Tag::Object.find_by( name: name )
|
||||
if tag_object
|
||||
@@cache_object[ name ] = tag_object.id
|
||||
return tag_object.id
|
||||
|
|
|
@ -166,7 +166,7 @@ returns
|
|||
self.state_id = Ticket::State.lookup( name: 'merged' ).id
|
||||
|
||||
# rest owner
|
||||
self.owner_id = User.where( login: '-' ).first.id
|
||||
self.owner_id = User.find_by( login: '-' ).id
|
||||
|
||||
# save ticket
|
||||
self.save
|
||||
|
|
|
@ -20,7 +20,7 @@ returns
|
|||
# generate number
|
||||
(1..50_000).each {
|
||||
number = adapter.generate
|
||||
ticket = Ticket.where( number: number ).first
|
||||
ticket = Ticket.find_by( number: number )
|
||||
return number if !ticket
|
||||
}
|
||||
raise "Can't generate new ticket number!"
|
||||
|
|
|
@ -75,9 +75,9 @@ module Ticket::Number::Date
|
|||
|
||||
# probe format
|
||||
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,50})/i
|
||||
ticket = Ticket.where( number: $1 ).first
|
||||
ticket = Ticket.find_by( number: $1 )
|
||||
elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,50})/i
|
||||
ticket = Ticket.where( number: $1 ).first
|
||||
ticket = Ticket.find_by( number: $1 )
|
||||
end
|
||||
ticket
|
||||
end
|
||||
|
|
|
@ -79,9 +79,9 @@ module Ticket::Number::Increment
|
|||
|
||||
# probe format
|
||||
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,48})/i
|
||||
ticket = Ticket.where( number: $1 ).first
|
||||
ticket = Ticket.find_by( number: $1 )
|
||||
elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,48})/i
|
||||
ticket = Ticket.where( number: $1 ).first
|
||||
ticket = Ticket.find_by( number: $1 )
|
||||
end
|
||||
ticket
|
||||
end
|
||||
|
|
|
@ -63,7 +63,7 @@ returns
|
|||
state_ids.push params[:ticket].state.id
|
||||
end
|
||||
state_types.each {|type|
|
||||
state_type = Ticket::StateType.where( name: type ).first
|
||||
state_type = Ticket::StateType.find_by( name: type )
|
||||
|
||||
next if !state_type
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ class Token < ActiveRecord::Base
|
|||
def self.check( data )
|
||||
|
||||
# fetch token
|
||||
token = Token.where( action: data[:action], name: data[:name] ).first
|
||||
token = Token.find_by( action: data[:action], name: data[:name] )
|
||||
return if !token
|
||||
|
||||
# check if token is still valid
|
||||
|
|
|
@ -184,11 +184,11 @@ returns
|
|||
return if !password || password == ''
|
||||
|
||||
# try to find user based on login
|
||||
user = User.where( login: username.downcase, active: true ).first
|
||||
user = User.find_by( login: username.downcase, active: true )
|
||||
|
||||
# try second lookup with email
|
||||
if !user
|
||||
user = User.where( email: username.downcase, active: true ).first
|
||||
user = User.find_by( email: username.downcase, active: true )
|
||||
end
|
||||
|
||||
# check failed logins
|
||||
|
@ -280,11 +280,11 @@ returns
|
|||
return if !username || username == ''
|
||||
|
||||
# try to find user based on login
|
||||
user = User.where( login: username.downcase, active: true ).first
|
||||
user = User.find_by( login: username.downcase, active: true )
|
||||
|
||||
# try second lookup with email
|
||||
if !user
|
||||
user = User.where( email: username.downcase, active: true ).first
|
||||
user = User.find_by( email: username.downcase, active: true )
|
||||
end
|
||||
|
||||
# check if email address exists
|
||||
|
@ -377,7 +377,7 @@ returns
|
|||
user.update_attributes( password: password )
|
||||
|
||||
# delete token
|
||||
Token.where( action: 'PasswordReset', name: token ).first.destroy
|
||||
Token.find_by( action: 'PasswordReset', name: token ).destroy
|
||||
user
|
||||
end
|
||||
|
||||
|
@ -476,7 +476,7 @@ returns
|
|||
self.login = self.login.downcase
|
||||
check = true
|
||||
while check
|
||||
exists = User.where( login: self.login ).first
|
||||
exists = User.find_by( login: self.login )
|
||||
if exists && exists.id != self.id
|
||||
self.login = self.login + rand(999).to_s
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue