simplex2/models/Keys.moon

23 lines
576 B
Plaintext
Raw Normal View History

2018-03-13 09:15:38 +00:00
import Model from require "lapis.db.model"
import autoload, locate from require "locator"
import settings from autoload "utility"
import random from locate "calc"
uuid = ->
fn = ->
r = random(16) - 1
r = (x == "x") and (r + 1) or (r % 4) + 9
return ("0123456789abcdef")\sub r, r
return ("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx")\gsub "[xy]", fn
class Keys extends Model
@primary_key: "user_id"
@timestamp: true
@create: (values, opts) =>
while true
values.uuid = uuid!
if Keys\find uuid: values.uuid
break
super values, opts