move to discrete model

This commit is contained in:
Sam Dodrill 2015-01-05 14:51:12 -08:00
parent 2ce7821ef1
commit 1fe65001c5
2 changed files with 19 additions and 3 deletions

View File

@ -7,9 +7,7 @@ import capture_errors from require "lapis.application"
import assert_valid from require "lapis.validate"
import respond_to from require "lapis.application"
import Model from require "lapis.db.model"
class Users extends Model
require "models.user"
class App extends lapis.Application
"/": =>
@ -38,6 +36,7 @@ class App extends lapis.Application
return "User with that email already exists"
user = Users\create @params
user\write_session @
"Hi " .. user.name
}
@ -55,4 +54,13 @@ class App extends lapis.Application
}
user = Users\find email: @params.email
cmppass = encoding.encode_base64 encoding.hmac_sha1("ninjas", @params.password)
if user.password == cmppass
user\write_session @
return "Hi " .. user.name
else
return status: 500, "bad password"
}

8
models/user.moon Normal file
View File

@ -0,0 +1,8 @@
db = require "lapis.db"
import Model from require "lapis.db.model"
export class Users extends Model
@timestamp: true
write_session: (r) =>
r.session.user = @id