Small code improvements.

This commit is contained in:
Martin Edenhofer 2013-02-19 20:04:35 +01:00
parent 1f266e3110
commit 6ea8e8e9ea
4 changed files with 34 additions and 14 deletions

View file

@ -23,7 +23,8 @@ class App.Run extends App.Controller
new App.Content( el: @el.find('#content') ) new App.Content( el: @el.find('#content') )
# start chat # start chat
new App.ChatWidget( el: @el.find('#chat') ) if App.ChatWidget
new App.ChatWidget( el: @el.find('#chat') )
# bind to fill selected text into # bind to fill selected text into
App.ClipBoard.bind( @el ) App.ClipBoard.bind( @el )

View file

@ -4,7 +4,7 @@ class User < ApplicationModel
include Gmaps include Gmaps
before_create :check_name, :check_email, :check_login, :check_image, :check_geo, :check_password before_create :check_name, :check_email, :check_login, :check_image, :check_geo, :check_password
before_update :check_password, :check_image, :check_geo, :check_email, :check_login before_update :check_password, :check_image, :check_geo, :check_email, :check_login_update
has_and_belongs_to_many :groups, :after_add => :cache_update, :after_remove => :cache_update has_and_belongs_to_many :groups, :after_add => :cache_update, :after_remove => :cache_update
has_and_belongs_to_many :roles, :after_add => :cache_update, :after_remove => :cache_update has_and_belongs_to_many :roles, :after_add => :cache_update, :after_remove => :cache_update
@ -449,6 +449,22 @@ Your #{config.product_name} Team
end end
def check_login def check_login
if self.login
self.login = self.login.downcase
check = true
while check
exists = User.where( :login => self.login ).first
if exists
self.login = self.login + rand(99).to_s
else
check = false
end
end
end
end
# FIXME: Remove me later
def check_login_update
if self.login if self.login
self.login = self.login.downcase self.login = self.login.downcase
end end

View file

@ -122,6 +122,13 @@ module Import::OTRS
return return
end end
def self.diff_loop
while true
self.diff
sleep 30
end
end
def self.diff def self.diff
puts 'Start diff...' puts 'Start diff...'

View file

@ -82,17 +82,13 @@ module Session
def self.send( client_id, data ) def self.send( client_id, data )
path = @path + '/' + client_id.to_s + '/' path = @path + '/' + client_id.to_s + '/'
filename = 'send-' + Time.new().to_i.to_s + '-' + rand(99999999).to_s filename = 'send-' + Time.new().to_i.to_s + '-' + rand(99999999).to_s
if File::exists?( path + filename ) check = true
filename = filename + '-1' while check
if File::exists?( path + filename ) if File::exists?( path + filename )
filename = filename + '-1' filename = filename + '-' + rand(99999).to_s
if File::exists?( path + filename ) else
filename = filename + '-1' check = false
if File::exists?( path + filename ) end
filename = filename + '-' + rand(99999999).to_s
end
end
end
end end
return false if !File.directory? path return false if !File.directory? path
File.open( path + 'a-' + filename, 'w' ) { |file| File.open( path + 'a-' + filename, 'w' ) { |file|
@ -101,8 +97,8 @@ module Session
file.flock( File::LOCK_UN ) file.flock( File::LOCK_UN )
file.close file.close
} }
# return false if !File.exists?( path + 'a-' + filename )
FileUtils.mv( path + 'a-' + filename, path + filename) FileUtils.mv( path + 'a-' + filename, path + filename )
return true return true
end end