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"
|
lapis = require "lapis"
|
||||||
|
|
||||||
|
require "models.user"
|
||||||
|
|
||||||
class App extends lapis.Application
|
class App extends lapis.Application
|
||||||
@include "controllers.users"
|
@include "controllers.users"
|
||||||
@include "controllers.freeswitch"
|
@include "controllers.freeswitch"
|
||||||
|
|
||||||
|
@before_filter =>
|
||||||
|
@current_user = Users\read_session @
|
||||||
|
|
||||||
|
if @session.flash
|
||||||
|
@flash = @session.flash
|
||||||
|
@session.flash = nil
|
||||||
|
|
||||||
[index: "/"]: =>
|
[index: "/"]: =>
|
||||||
@user = @session.user
|
@user = @session.user
|
||||||
render: true
|
render: true
|
||||||
|
|
|
@ -10,13 +10,9 @@ require "models.user"
|
||||||
|
|
||||||
class User extends lapis.Application
|
class User extends lapis.Application
|
||||||
[list: "/list"]: =>
|
[list: "/list"]: =>
|
||||||
if @session.user
|
if not @current_user
|
||||||
if not Users\find id: @session.user
|
|
||||||
@write redirect_to: @url_for "login"
|
|
||||||
else
|
|
||||||
@write redirect_to: @url_for "login"
|
@write redirect_to: @url_for "login"
|
||||||
|
|
||||||
user = Users\find id: @session.user
|
|
||||||
@list = Users\select!
|
@list = Users\select!
|
||||||
render: true
|
render: true
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue