Corrected with rubocop cop 'Rails/FindBy'.

This commit is contained in:
Thorsten Eckel 2015-05-07 12:15:40 +02:00
parent 8f54cf18f5
commit 6a41d0ee18
26 changed files with 76 additions and 80 deletions

View file

@ -182,10 +182,6 @@ Rails/ActionFilter:
Description: 'Enforces consistent use of action filter methods.' Description: 'Enforces consistent use of action filter methods.'
Enabled: false Enabled: false
Rails/FindBy:
Description: 'Prefer find_by over where.first.'
Enabled: false
Style/SymbolProc: Style/SymbolProc:
Description: 'Use symbols as procs instead of blocks when possible.' Description: 'Use symbols as procs instead of blocks when possible.'
Enabled: false Enabled: false

View file

@ -312,7 +312,7 @@ returns
cache = self.cache_get( data[:id] ) cache = self.cache_get( data[:id] )
return cache if cache return cache if cache
record = self.where( id: data[:id] ).first record = self.find_by( id: data[:id] )
self.cache_set( data[:id], record ) self.cache_set( data[:id], record )
return record return record
elsif data[:name] elsif data[:name]
@ -358,7 +358,7 @@ returns
def self.create_if_not_exists(data) def self.create_if_not_exists(data)
if data[:id] if data[:id]
record = self.where( id: data[:id] ).first record = self.find_by( id: data[:id] )
return record if record return record if record
elsif data[:name] elsif data[:name]
records = self.where( name: data[:name] ) records = self.where( name: data[:name] )

View file

@ -10,7 +10,7 @@ class Authorization < ApplicationModel
validates :provider, presence: true validates :provider, presence: true
def self.find_from_hash(hash) 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 if auth
# update auth tokens # update auth tokens

View file

@ -89,11 +89,11 @@ add a avatar
# check if avatar with url already exists # check if avatar with url already exists
avatar_already_exists = nil avatar_already_exists = nil
if data[:source] && !data[:source].empty? if data[:source] && !data[:source].empty?
avatar_already_exists = Avatar.where( avatar_already_exists = Avatar.find_by(
object_lookup_id: object_id, object_lookup_id: object_id,
o_id: data[:o_id], o_id: data[:o_id],
source: data[:source], source: data[:source],
).first )
end end
# fetch image # fetch image
@ -208,11 +208,11 @@ set avatars as default
def self.set_default( object_name, o_id, avatar_id ) def self.set_default( object_name, o_id, avatar_id )
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
avatar = Avatar.where( avatar = Avatar.find_by(
object_lookup_id: object_id, object_lookup_id: object_id,
o_id: o_id, o_id: o_id,
id: avatar_id, id: avatar_id,
).first )
avatar.default = true avatar.default = true
avatar.save! avatar.save!
@ -308,9 +308,9 @@ returns:
=end =end
def self.get_by_hash(hash) def self.get_by_hash(hash)
avatar = Avatar.where( avatar = Avatar.find_by(
store_hash: hash, store_hash: hash,
).first )
return if !avatar return if !avatar
file = Store.find(avatar.store_resize_id) file = Store.find(avatar.store_resize_id)
end end
@ -329,11 +329,11 @@ returns:
def self.get_default(object_name, o_id) def self.get_default(object_name, o_id)
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
Avatar.where( Avatar.find_by(
object_lookup_id: object_id, object_lookup_id: object_id,
o_id: o_id, o_id: o_id,
default: true, default: true,
).first )
end end
def self.set_default_items(object_id, o_id, avatar_id) def self.set_default_items(object_id, o_id, avatar_id)

View file

@ -360,10 +360,10 @@ class Channel::EmailParser
# create sender # create sender
if mail[ 'x-zammad-customer-login'.to_sym ] 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 end
if !user 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 end
if !user if !user
user = user_create( user = user_create(
@ -407,7 +407,7 @@ class Channel::EmailParser
end end
if state_type.name != 'new' if state_type.name != 'new'
ticket.state = Ticket::State.where( name: 'open' ).first ticket.state = Ticket::State.find_by( name: 'open' )
ticket.save ticket.save
end end
end end
@ -420,8 +420,8 @@ class Channel::EmailParser
group_id: channel[:group_id] || 1, group_id: channel[:group_id] || 1,
customer_id: user.id, customer_id: user.id,
title: mail[:subject] || '', title: mail[:subject] || '',
state_id: Ticket::State.where( name: 'new' ).first.id, state_id: Ticket::State.find_by( name: 'new' ).id,
priority_id: Ticket::Priority.where( name: '2 normal' ).first.id, priority_id: Ticket::Priority.find_by( name: '2 normal' ).id,
) )
set_attributes_by_x_headers( ticket, 'ticket', mail ) set_attributes_by_x_headers( ticket, 'ticket', mail )
@ -435,8 +435,8 @@ class Channel::EmailParser
# set attributes # set attributes
article = Ticket::Article.new( article = Ticket::Article.new(
ticket_id: ticket.id, ticket_id: ticket.id,
type_id: Ticket::Article::Type.where( name: 'email' ).first.id, type_id: Ticket::Article::Type.find_by( name: 'email' ).id,
sender_id: Ticket::Article::Sender.where( name: 'Customer' ).first.id, sender_id: Ticket::Article::Sender.find_by( name: 'Customer' ).id,
body: mail[:body], body: mail[:body],
from: mail[:from], from: mail[:from],
to: mail[:to], to: mail[:to],
@ -500,7 +500,7 @@ class Channel::EmailParser
def user_create(data) def user_create(data)
# return existing # return existing
user = User.where( login: data[:email].downcase ).first user = User.find_by( login: data[:email].downcase )
return user if user return user if user
# create new user # create new user

View file

@ -4,7 +4,7 @@ require 'net/imap'
module Channel::EmailSend module Channel::EmailSend
def self.send(attr, notification = false) 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 begin
c = eval 'Channel::' + channel[:adapter] + '.new' c = eval 'Channel::' + channel[:adapter] + '.new'
c.send(attr, channel, notification) c.send(attr, channel, notification)

View file

@ -75,7 +75,7 @@ class Channel::TWITTER2
all_tweets.each do |tweet| all_tweets.each do |tweet|
# check if tweet is already imported # 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 # check if sender already exists
next if article next if article
@ -141,11 +141,11 @@ class Channel::TWITTER2
# create sender in db # create sender in db
# puts tweet.inspect # puts tweet.inspect
# user = User.where( :login => tweet.sender.screen_name ).first # 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 user = nil
if auth if auth
Rails.logger.info 'user_id', auth.user_id 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 end
if !user if !user
Rails.logger.info 'create user...' Rails.logger.info 'create user...'
@ -186,7 +186,7 @@ class Channel::TWITTER2
# check if ticket exists # 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 != '' 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 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 if article
Rails.logger.info 'article with id found tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s 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 return article.ticket
@ -194,14 +194,14 @@ class Channel::TWITTER2
end end
# find if record already exists # 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 if article
return article.ticket return article.ticket
end end
ticket = nil ticket = nil
if @article_type == 'twitter direct-message' if @article_type == 'twitter direct-message'
ticket = Ticket.where( customer_id: user.id ).first ticket = Ticket.find_by( customer_id: user.id )
if ticket if ticket
state_type = Ticket::StateType.where( ticket.state.state_type_id ) state_type = Ticket::StateType.where( ticket.state.state_type_id )
if state_type.name == 'closed' || state_type.name == 'closed' if state_type.name == 'closed' || state_type.name == 'closed'
@ -210,17 +210,17 @@ class Channel::TWITTER2
end end
end end
if !ticket if !ticket
group = Group.where( name: group ).first group = Group.find_by( name: group )
group_id = 1 group_id = 1
if group if group
group_id = group.id group_id = group.id
end end
state = Ticket::State.where( name: 'new' ).first state = Ticket::State.find_by( name: 'new' )
state_id = 1 state_id = 1
if state if state
state_id = state.id state_id = state.id
end end
priority = Ticket::Priority.where( name: '2 normal' ).first priority = Ticket::Priority.find_by( name: '2 normal' )
priority_id = 1 priority_id = 1
if priority if priority
priority_id = priority.id priority_id = priority.id
@ -240,12 +240,12 @@ class Channel::TWITTER2
def fetch_article_create( _user, ticket, tweet, sender ) def fetch_article_create( _user, ticket, tweet, sender )
# find if record already exists # 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 return article if article
# set ticket state to open if not new # set ticket state to open if not new
if ticket.state.name != 'new' if ticket.state.name != 'new'
ticket.state = Ticket::State.where( name: 'open' ).first ticket.state = Ticket::State.find_by( name: 'open' )
ticket.save ticket.save
end end
@ -257,8 +257,8 @@ class Channel::TWITTER2
article = Ticket::Article.create( article = Ticket::Article.create(
ticket_id: ticket.id, ticket_id: ticket.id,
type_id: Ticket::Article::Type.where( name: @article_type ).first.id, type_id: Ticket::Article::Type.find_by( name: @article_type ).id,
sender_id: Ticket::Article::Sender.where( name: 'Customer' ).first.id, sender_id: Ticket::Article::Sender.find_by( name: 'Customer' ).id,
body: tweet.text, body: tweet.text,
from: sender.name, from: sender.name,
to: to, to: to,
@ -270,7 +270,7 @@ class Channel::TWITTER2
def send(attr, _notification = false) def send(attr, _notification = false)
# Rails.logger.debug('tweeeeettttt!!!!!!') # 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| client = Twitter::REST::Client.new do |config|
config.consumer_key = channel[:options][:consumer_key] config.consumer_key = channel[:options][:consumer_key]

View file

@ -76,7 +76,7 @@ add a new history entry for an object
} }
history_record = nil history_record = nil
if data[:id] if data[:id]
history_record = History.where( id: data[:id] ).first history_record = History.find_by( id: data[:id] )
end end
if history_record if history_record
history_record.update_attributes(record) history_record.update_attributes(record)
@ -98,7 +98,7 @@ remove whole history entries of an object
=end =end
def self.remove( requested_object, requested_object_id ) 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 return if !history_object
History.where( History.where(
history_object_id: history_object.id, history_object_id: history_object.id,

View file

@ -152,7 +152,7 @@ class Link < ApplicationModel
end end
def self.link_type_get(data) def self.link_type_get(data)
linktype = Link::Type.where( name: data[:name] ).first linktype = Link::Type.find_by( name: data[:name] )
if !linktype if !linktype
linktype = Link::Type.create( linktype = Link::Type.create(
name: data[:name] name: data[:name]
@ -162,7 +162,7 @@ class Link < ApplicationModel
end end
def self.link_object_get(data) def self.link_object_get(data)
linkobject = Link::Object.where( name: data[:name] ).first linkobject = Link::Object.find_by( name: data[:name] )
if !linkobject if !linkobject
linkobject = Link::Object.create( linkobject = Link::Object.create(
name: data[:name] name: data[:name]

View file

@ -17,7 +17,7 @@ class Locale < ApplicationModel
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
result.data.each {|locale| result.data.each {|locale|
exists = Locale.where(locale: locale['locale']).first exists = Locale.find_by(locale: locale['locale'])
if exists if exists
exists.update(locale.symbolize_keys!) exists.update(locale.symbolize_keys!)
else else

View file

@ -112,10 +112,10 @@ add a new attribute entry for an object
data.delete(:object) data.delete(:object)
# check newest entry - is needed # check newest entry - is needed
result = ObjectManager::Attribute.where( result = ObjectManager::Attribute.find_by(
object_lookup_id: data[:object_lookup_id], object_lookup_id: data[:object_lookup_id],
name: data[:name], name: data[:name],
).first )
if result if result
# raise "ERROR: attribute #{data[:name]} for #{data[:object]} already exists" # raise "ERROR: attribute #{data[:name]} for #{data[:object]} already exists"
return result.update_attributes(data) 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] ) data[:object_lookup_id] = ObjectLookup.by_name( data[:object] )
end end
ObjectManager::Attribute.where( ObjectManager::Attribute.find_by(
object_lookup_id: data[:object_lookup_id], object_lookup_id: data[:object_lookup_id],
name: data[:name], name: data[:name],
).first )
end end
=begin =begin

View file

@ -17,7 +17,7 @@ class Observer::User::Geo < ActiveRecord::Observer
# check if geo update is needed based on old/new location # check if geo update is needed based on old/new location
if record.id if record.id
current = User.where( id: record.id ).first current = User.find_by( id: record.id )
return if !current return if !current
current_location = {} current_location = {}

View file

@ -195,7 +195,7 @@ class Package < ApplicationModel
} }
# verify if package can get installed # 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 package_db
if !data[:reinstall] if !data[:reinstall]
if Gem::Version.new( package_db.version ) == Gem::Version.new( meta[:version] ) if Gem::Version.new( package_db.version ) == Gem::Version.new( meta[:version] )
@ -253,7 +253,7 @@ class Package < ApplicationModel
# Package.reinstall( package_name ) # Package.reinstall( package_name )
def self.reinstall(package_name) def self.reinstall(package_name)
package = Package.where( name: package_name ).first package = Package.find_by( name: package_name )
if !package if !package
raise "No such package '#{package_name}'" raise "No such package '#{package_name}'"
end end
@ -300,10 +300,10 @@ class Package < ApplicationModel
end end
# delete package # delete package
record = Package.where( record = Package.find_by(
name: meta[:name], name: meta[:name],
version: meta[:version], version: meta[:version],
).first )
record.destroy record.destroy
true true
@ -340,10 +340,10 @@ class Package < ApplicationModel
end end
def self._get_bin( name, version ) def self._get_bin( name, version )
package = Package.where( package = Package.find_by(
name: name, name: name,
version: version, version: version,
).first )
if !package if !package
raise "No such package '#{name}' version '#{version}'" raise "No such package '#{name}' version '#{version}'"
end end
@ -475,20 +475,20 @@ class Package < ApplicationModel
# down # down
if direction == 'reverse' 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 next if !done
logger.info "NOTICE: down package migration '#{migration}'" logger.info "NOTICE: down package migration '#{migration}'"
load "#{location}/#{migration}" load "#{location}/#{migration}"
classname = name.camelcase classname = name.camelcase
Kernel.const_get(classname).down 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 if record
record.destroy record.destroy
end end
# up # up
else else
done = Package::Migration.where( name: package.underscore, version: version ).first done = Package::Migration.find_by( name: package.underscore, version: version )
next if done next if done
logger.info "NOTICE: up package migration '#{migration}'" logger.info "NOTICE: up package migration '#{migration}'"
load "#{location}/#{migration}" load "#{location}/#{migration}"

View file

@ -124,7 +124,7 @@ class Scheduler < ApplicationModel
def self.check( name, time_warning = 10, time_critical = 20 ) def self.check( name, time_warning = 10, time_critical = 20 )
time_warning_time = Time.now - time_warning.minutes time_warning_time = Time.now - time_warning.minutes
time_critical_time = Time.now - time_critical.minutes time_critical_time = Time.now - time_critical.minutes
scheduler = Scheduler.where( name: name ).first scheduler = Scheduler.find_by( name: name )
if !scheduler if !scheduler
puts "CRITICAL - no such scheduler jobs '#{name}'" puts "CRITICAL - no such scheduler jobs '#{name}'"
return true return true

View file

@ -37,7 +37,7 @@ class Setting < ApplicationModel
end end
def self.set(name, value) def self.set(name, value)
setting = Setting.where( name: name ).first setting = Setting.find_by( name: name )
if !setting if !setting
raise "Can't find config setting '#{name}'" raise "Can't find config setting '#{name}'"
end end

View file

@ -140,7 +140,7 @@ returns
end end
def content def content
file = Store::File.where( id: self.store_file_id ).first file = Store::File.find_by( id: self.store_file_id )
if !file if !file
raise "No such file #{ self.store_file_id }!" raise "No such file #{ self.store_file_id }!"
end end
@ -148,7 +148,7 @@ returns
end end
def provider def provider
file = Store::File.where( id: self.store_file_id ).first file = Store::File.find_by( id: self.store_file_id )
if !file if !file
raise "No such file #{ self.store_file_id }!" raise "No such file #{ self.store_file_id }!"
end end

View file

@ -9,7 +9,7 @@ class Store
def self.add(data) def self.add(data)
sha = Digest::SHA256.hexdigest( data ) sha = Digest::SHA256.hexdigest( data )
file = Store::File.where( sha: sha ).first file = Store::File.find_by( sha: sha )
if file.nil? if file.nil?
# load backend based on config # load backend based on config
@ -34,7 +34,7 @@ class Store
c = adapter.get( self.sha ) c = adapter.get( self.sha )
else else
# fallback until migration is done # 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 end
c c
end end

View file

@ -14,7 +14,7 @@ class Store
end end
def self.get(sha) def self.get(sha)
file = Store::Provider::DB.where( sha: sha ).first file = Store::Provider::DB.find_by( sha: sha )
return if !file return if !file
file.data file.data
end end

View file

@ -81,7 +81,7 @@ class Tag < ApplicationModel
return @@cache_item[ name ] if @@cache_item[ name ] return @@cache_item[ name ] if @@cache_item[ name ]
# lookup # lookup
tag_item = Tag::Item.where( name: name ).first tag_item = Tag::Item.find_by( name: name )
if tag_item if tag_item
@@cache_item[ name ] = tag_item.id @@cache_item[ name ] = tag_item.id
return tag_item.id return tag_item.id
@ -112,7 +112,7 @@ class Tag < ApplicationModel
return @@cache_object[ name ] if @@cache_object[ name ] return @@cache_object[ name ] if @@cache_object[ name ]
# lookup # lookup
tag_object = Tag::Object.where( name: name ).first tag_object = Tag::Object.find_by( name: name )
if tag_object if tag_object
@@cache_object[ name ] = tag_object.id @@cache_object[ name ] = tag_object.id
return tag_object.id return tag_object.id

View file

@ -166,7 +166,7 @@ returns
self.state_id = Ticket::State.lookup( name: 'merged' ).id self.state_id = Ticket::State.lookup( name: 'merged' ).id
# rest owner # rest owner
self.owner_id = User.where( login: '-' ).first.id self.owner_id = User.find_by( login: '-' ).id
# save ticket # save ticket
self.save self.save

View file

@ -20,7 +20,7 @@ returns
# generate number # generate number
(1..50_000).each { (1..50_000).each {
number = adapter.generate number = adapter.generate
ticket = Ticket.where( number: number ).first ticket = Ticket.find_by( number: number )
return number if !ticket return number if !ticket
} }
raise "Can't generate new ticket number!" raise "Can't generate new ticket number!"

View file

@ -75,9 +75,9 @@ module Ticket::Number::Date
# probe format # probe format
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,50})/i 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 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 end
ticket ticket
end end

View file

@ -79,9 +79,9 @@ module Ticket::Number::Increment
# probe format # probe format
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,48})/i 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 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 end
ticket ticket
end end

View file

@ -63,7 +63,7 @@ returns
state_ids.push params[:ticket].state.id state_ids.push params[:ticket].state.id
end end
state_types.each {|type| state_types.each {|type|
state_type = Ticket::StateType.where( name: type ).first state_type = Ticket::StateType.find_by( name: type )
next if !state_type next if !state_type

View file

@ -8,7 +8,7 @@ class Token < ActiveRecord::Base
def self.check( data ) def self.check( data )
# fetch token # 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 return if !token
# check if token is still valid # check if token is still valid

View file

@ -184,11 +184,11 @@ returns
return if !password || password == '' return if !password || password == ''
# try to find user based on login # 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 # try second lookup with email
if !user if !user
user = User.where( email: username.downcase, active: true ).first user = User.find_by( email: username.downcase, active: true )
end end
# check failed logins # check failed logins
@ -280,11 +280,11 @@ returns
return if !username || username == '' return if !username || username == ''
# try to find user based on login # 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 # try second lookup with email
if !user if !user
user = User.where( email: username.downcase, active: true ).first user = User.find_by( email: username.downcase, active: true )
end end
# check if email address exists # check if email address exists
@ -377,7 +377,7 @@ returns
user.update_attributes( password: password ) user.update_attributes( password: password )
# delete token # delete token
Token.where( action: 'PasswordReset', name: token ).first.destroy Token.find_by( action: 'PasswordReset', name: token ).destroy
user user
end end
@ -476,7 +476,7 @@ returns
self.login = self.login.downcase self.login = self.login.downcase
check = true check = true
while check while check
exists = User.where( login: self.login ).first exists = User.find_by( login: self.login )
if exists && exists.id != self.id if exists && exists.id != self.id
self.login = self.login + rand(999).to_s self.login = self.login + rand(999).to_s
else else