Use a before_filter to simplify controller logic

This commit is contained in:
Sam Dodrill 2015-01-08 13:21:26 -08:00
parent e26f23e0a0
commit ff4eee25bc
2 changed files with 10 additions and 5 deletions

View File

@ -1,9 +1,18 @@
lapis = require "lapis"
require "models.user"
class App extends lapis.Application
@include "controllers.users"
@include "controllers.freeswitch"
@before_filter =>
@current_user = Users\read_session @
if @session.flash
@flash = @session.flash
@session.flash = nil
[index: "/"]: =>
@user = @session.user
render: true

View File

@ -10,13 +10,9 @@ require "models.user"
class User extends lapis.Application
[list: "/list"]: =>
if @session.user
if not Users\find id: @session.user
@write redirect_to: @url_for "login"
else
if not @current_user
@write redirect_to: @url_for "login"
user = Users\find id: @session.user
@list = Users\select!
render: true