From 6594600a0385bdd6e1667a2c7c8eebd60e76d001 Mon Sep 17 00:00:00 2001 From: Sam Dodrill Date: Thu, 8 Jan 2015 13:22:26 -0800 Subject: [PATCH] Simplify a big part of the logic --- controllers/users.moon | 15 +++------------ models/user.moon | 6 +++++- views/index.moon | 4 ++++ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/controllers/users.moon b/controllers/users.moon index 93e4ec3..cd4b583 100644 --- a/controllers/users.moon +++ b/controllers/users.moon @@ -50,20 +50,11 @@ class User extends lapis.Application token: encoding.encode_base64 encoding.hmac_sha1(@params.email, os.time!) } - @title = "Success" + @session.token = encoding.encode_base64 token.token - @html -> - h1 "Success" - p -> - text "Your email is " .. user.email - p -> - text "Your extension is " .. user.extension - p -> - text "Your one-time sip token is " - code token.token - - p "This will not be shown again so please be sure to write this down." + @session.flash = "You are logged in. Your extension is #{user.extension}." + redirect_to: @url_for "index" } [login: "/login"]: capture_errors respond_to { diff --git a/models/user.moon b/models/user.moon index 07e3a66..9d9c26c 100644 --- a/models/user.moon +++ b/models/user.moon @@ -1,4 +1,3 @@ -db = require "lapis.db" import Model from require "lapis.db.model" export class Users extends Model @@ -6,3 +5,8 @@ export class Users extends Model write_session: (r) => r.session.user = @id + + read_session: (r) => + if r.session.user + return @find id: r.session.user + nil diff --git a/views/index.moon b/views/index.moon index a683408..beb4e56 100644 --- a/views/index.moon +++ b/views/index.moon @@ -6,5 +6,9 @@ class Index extends Widget div class: "body", -> text "Welcome to my site!" + if @flash + p class: "flash", -> + text @flash + if @user h2 "I think you are UID #{@user}"