diff options
-rw-r--r-- | model.lisp | 36 | ||||
-rw-r--r-- | new-account.lisp | 5 |
2 files changed, 31 insertions, 10 deletions
@@ -3,17 +3,21 @@ (in-package :vampire) (defclass/bknr keyed () - ((key - :r :std (nuid) - :index-type string-unique-index - :index-reader object-with-key))) + ((key :r :std (nuid) + :index-type string-unique-index + :index-reader object-with-key))) (defclass/bknr user (keyed) ((name :with :index-type string-unique-index :index-reader user-with-name) (playlists :with :std (list)) - (pwsalt pwhash :with))) + (pwsalt :with :std (nuid)) + (pwhash :with))) + +(defclass/bknr invite (keyed) + ((maker :r :std nil) + (uses-remaining :std nil))) (defclass/bknr playlist (keyed) ((title :with :std (default-name "playlist")) @@ -25,7 +29,6 @@ (defmethod initialize-instance :after ((pl playlist) &key) (pushnew pl (user-playlists (playlist-user pl)) :test #'eq)) - (defclass/bknr track (keyed) ((source file title artist album thumb-url duration codec :with) (playlists :with :std (list) :doc "A list of playlists in which this track appears"))) @@ -33,6 +36,15 @@ ;;; MODEL OPERATIONS +(defun invite-by-code (code) + "Returns NIL if CODE is an invalid invite code. Returns the INVITE + instance otherwise" + (when-let (obj (object-with-key code)) + (and (typep obj 'invite) + (or (null (uses-remaining obj)) + (plusp (uses-remaining obj))) + obj))) + (defun user-with-key (key) (when-let (obj (object-with-key key)) (when (typep obj 'user) @@ -70,6 +82,18 @@ (with-transaction () (make-instance 'user :name name))) +(defun use-invite-with-code (code username pw) + (with-transaction () + (when-let (invite (invite-by-code code)) + (when (uses-remaining invite) + (decf (uses-remaining invite)) + (unless (plusp (uses-remaining invite)) + (bknr.datastore:delete-object invite)) + (let ((user (make-instance 'user :name username))) + (setf (user-pwhash user) + (hash-string pw (user-pwsalt user))) + user))))) + (defun append-track (pl tr) (with-transaction () (add-track tr pl))) diff --git a/new-account.lisp b/new-account.lisp index 10311af..93cf122 100644 --- a/new-account.lisp +++ b/new-account.lisp @@ -2,9 +2,6 @@ (in-package :vampire) -(defun valid-invite-code-p (arg) arg) -(defun use-invite-with-code (code username pw)) - (defun new-accout-page (body) (with-clog-create body (div () @@ -32,7 +29,7 @@ invite (thunk* (setf (inner-html invite-status) - (if (valid-invite-code-p (value invite)) + (if (invite-by-code (value invite)) "✔" "Bad Invite Code")))) (set-on-blur |