Use a before_filter to simplify controller logic
This commit is contained in:
parent
e26f23e0a0
commit
ff4eee25bc
9
app.moon
9
app.moon
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue