|
@@ -4,10 +4,8 @@ require 'digest/sha2'
|
|
|
require 'organization'
|
|
|
|
|
|
class User < ApplicationModel
|
|
|
- include Gmaps
|
|
|
-
|
|
|
- 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_update
|
|
|
+ before_create :check_name, :check_email, :check_login, :check_image, :check_password
|
|
|
+ before_update :check_password, :check_image, :check_email, :check_login_update
|
|
|
after_create :notify_clients_after_create
|
|
|
after_update :notify_clients_after_update
|
|
|
after_destroy :notify_clients_after_destroy
|
|
@@ -380,73 +378,12 @@ class User < ApplicationModel
|
|
|
return user
|
|
|
end
|
|
|
|
|
|
-
|
|
|
- def self.geo_update_all
|
|
|
- User.all.each { |user|
|
|
|
- user.geo_update
|
|
|
- user.save
|
|
|
- }
|
|
|
- end
|
|
|
-
|
|
|
-
|
|
|
- def geo_update
|
|
|
- address = ''
|
|
|
- location = ['street', 'zip', 'city', 'country']
|
|
|
- location.each { |item|
|
|
|
- if self[item] && self[item] != ''
|
|
|
- address = address + ',' + self[item]
|
|
|
- end
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return if address == ''
|
|
|
-
|
|
|
-
|
|
|
- latlng = Gmaps.geocode(address)
|
|
|
- if latlng
|
|
|
- self.preferences['lat'] = latlng[0]
|
|
|
- self.preferences['lng'] = latlng[1]
|
|
|
- end
|
|
|
- end
|
|
|
-
|
|
|
def update_last_login
|
|
|
self.last_login = Time.now
|
|
|
self.save
|
|
|
end
|
|
|
|
|
|
private
|
|
|
- def check_geo
|
|
|
-
|
|
|
-
|
|
|
- if !self.id
|
|
|
- self.geo_update
|
|
|
- return
|
|
|
- end
|
|
|
-
|
|
|
- location = ['street', 'zip', 'city', 'country']
|
|
|
-
|
|
|
-
|
|
|
- current = User.where( :id => self.id ).first
|
|
|
- return if !current
|
|
|
-
|
|
|
-
|
|
|
- current_location = {}
|
|
|
- location.each { |item|
|
|
|
- current_location[item] = current[item]
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- next_location = {}
|
|
|
- location.each { |item|
|
|
|
- next_location[item] = self[item]
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return if ( current_location == next_location ) && ( self.preferences['lat'] && self.preferences['lng'] )
|
|
|
-
|
|
|
-
|
|
|
- self.geo_update
|
|
|
- end
|
|
|
|
|
|
def check_name
|
|
|
|