Improve & clean SteamID validation

This commit is contained in:
Prommah 2015-09-24 07:23:05 +01:00
parent 19e63f5cdc
commit 4d83b2a06d

9
app/models/user.rb Normal file → Executable file
View file

@ -243,13 +243,14 @@ class User < ActiveRecord::Base
end end
def validate_steamid def validate_steamid
if !(self.steamid.nil? || (m = self.steamid.match(/\A([01]):([01]):(\d{1,10})\Z/) and accid = (m[3].to_i<<1)+m[2].to_i and accid > 0 and accid <= 4294967295)) errors.add :steamid unless self.steamid.nil? ||
errors.add :steamid (m = self.steamid.match(/\A([01]):([01]):(\d{1,10})\Z/)) &&
end (id = m[3].to_i) &&
id >= 1 && id <= 2147483647
end end
def correct_steamid_universe def correct_steamid_universe
if self.steamid if self.steamid.present?
self.steamid[0] = "0" self.steamid[0] = "0"
end end
end end