mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-14 05:41:00 +00:00
Improve & clean SteamID validation
This commit is contained in:
parent
19e63f5cdc
commit
4d83b2a06d
1 changed files with 5 additions and 4 deletions
9
app/models/user.rb
Normal file → Executable file
9
app/models/user.rb
Normal file → Executable 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
|
||||||
|
|
Loading…
Reference in a new issue