lib/africompta/entities/users.rb in africompta-1.9.10 vs lib/africompta/entities/users.rb in africompta-1.9.11

- old
+ new

@@ -12,31 +12,38 @@ value_int :account_index # The last movement_index that got transmitted value_int :movement_index end + def init + user = Users.create('local', Digest::MD5.hexdigest((rand 2**128).to_s).to_s, + rand(2 ** 128).to_s) + user.account_index, user.movement_index = 0, 0 + dputs(1) { "Created local user #{user}" } + user + end + def load super if Users.search_by_name('local').count == 0 - user = Users.create('local', Digest::MD5.hexdigest((rand 2**128).to_s).to_s, - rand(2 ** 128).to_s) - dputs(1) { "Created local user #{user}" } + dputs(0) { 'User init not here' } + init end end def migration_1(u) - u.account_index ||= 0 - u.movement_index ||= 0 + u.account_index ||= -1 + u.movement_index ||= -1 end def create(name, full = nil, pass = nil) if not full or not pass dputs(2) { "Creating with hash: #{name.inspect}" } name, full, pass = name[:name], name[:full], name[:pass] end new_user = super(:name => name, :full => full, :pass => pass) - new_user.account_index, new_user.movement_index = 0, 0 + new_user.account_index, new_user.movement_index = -1, -1 new_user end end class User < Entity @@ -50,6 +57,11 @@ def update_all update_movement_index update_account_index end + + def reset_id + self.full = Digest::MD5.hexdigest((rand 2**128).to_s).to_s + end + end