23 lines
576 B
Plaintext
23 lines
576 B
Plaintext
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
|