-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #4
- Loading branch information
Showing
7 changed files
with
49 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
BaseController = require './../base_controller' | ||
|
||
class DashboardController extends BaseController | ||
show: -> | ||
if @isAdmin() | ||
@response.render 'admin/dashboard/show' | ||
module.exports = | ||
show: (req, res) -> | ||
if req.session.administrator_id | ||
res.render 'admin/dashboard/show' | ||
else | ||
@response.redirect '/' | ||
|
||
module.exports = DashboardController | ||
res.redirect '/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
BaseController = require './../base_controller' | ||
{ mongoose } = require '../../../config/database' | ||
Event = mongoose.model('Event') | ||
|
||
class EventsController extends BaseController | ||
index: -> | ||
Event.find({}).exec (error, events) => | ||
@response.render 'admin/events/index', | ||
module.exports = | ||
index: (req, res) -> | ||
Event.find({}).exec (error, events) -> | ||
res.render 'admin/events/index', | ||
events: events | ||
|
||
new: -> | ||
@response.render 'admin/events/new', | ||
new: (req, res) -> | ||
res.render 'admin/events/new', | ||
event: new Event | ||
|
||
create: -> | ||
newEvent = new Event @request.body.event | ||
newEvent.save (error, event) => | ||
create: (req, res) -> | ||
newEvent = new Event req.body.event | ||
newEvent.save (error, event) -> | ||
throw error if error | ||
@request.session.messages = | ||
req.session.messages = | ||
notice: "#{event.name} created" | ||
@response.redirect "admin/events/#{event._id}" | ||
res.redirect "admin/events/#{event._id}" | ||
|
||
show: -> | ||
Event.findOne @request.params.id, (error, event) => | ||
@response.render 'admin/events/show', | ||
show: (req, res) -> | ||
Event.findOne req.params.id, (error, event) -> | ||
res.render 'admin/events/show', | ||
event: event | ||
messages: @request.session.messages | ||
|
||
module.exports = EventsController | ||
messages: req.session.messages |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
BaseController = require './../base_controller' | ||
{ mongoose } = require '../../../config/database' | ||
Administrator = mongoose.model('Administrator') | ||
|
||
class SessionsController extends BaseController | ||
new: -> | ||
@response.render 'admin/sessions/new' | ||
module.exports = | ||
new: (req, res) -> | ||
res.render 'admin/sessions/new' | ||
|
||
create: -> | ||
create: (req, res) -> | ||
params = | ||
username: @request.body.admin.username | ||
password: @request.body.admin.password | ||
username: req.body.admin.username | ||
password: req.body.admin.password | ||
|
||
Administrator.findOne params, (error, administrator) => | ||
Administrator.findOne params, (error, administrator) -> | ||
throw error if error | ||
@request.session.administrator_id = administrator._id | ||
@response.redirect '/' | ||
req.session.administrator_id = administrator._id | ||
res.redirect '/' | ||
|
||
destroy: -> | ||
@request.session.administrator_id = null | ||
@response.redirect '/' | ||
|
||
module.exports = SessionsController | ||
destroy: (req, res) -> | ||
req.session.administrator_id = null | ||
res.redirect '/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
BaseController = require './base_controller' | ||
{ mongoose } = require '../../config/database' | ||
Administrator = mongoose.model('Administrator') | ||
{ mongoose } = require '../../config/database' | ||
Administrator = mongoose.model('Administrator') | ||
|
||
|
||
class HomesController extends BaseController | ||
show: -> | ||
_id = @request.session.administrator_id | ||
module.exports = | ||
show: (req, res) -> | ||
_id = req.session.administrator_id | ||
Administrator.findOne { _id: _id }, (error, administrator) => | ||
throw error if error | ||
@response.render 'homes/show', | ||
res.render 'homes/show', | ||
administrator: administrator | ||
|
||
module.exports = HomesController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,17 @@ | ||
HomesController = require './../app/controllers/homes_controller' | ||
Admin = require './../app/controllers/admin/admin' | ||
Admin = require './../app/controllers/admin' | ||
|
||
module.exports = (app) -> | ||
|
||
app.get '/', (request, response) -> | ||
new HomesController(request, response).show() | ||
app.get '/', HomesController.show | ||
|
||
app.get '/admin/login', (request, response) -> | ||
new Admin.SessionsController(request, response).new() | ||
app.get '/admin/login', Admin.SessionsController.new | ||
app.get '/admin/logout', Admin.SessionsController.destroy | ||
app.post '/admin/sessions/create', Admin.SessionsController.create | ||
|
||
app.get '/admin/logout', (request, response) -> | ||
new Admin.SessionsController(request, response).destroy() | ||
app.get '/admin/dashboard', Admin.DashboardController.show | ||
|
||
app.post '/admin/sessions/create', (request, response) -> | ||
new Admin.SessionsController(request, response).create() | ||
|
||
app.get '/admin/dashboard', (request, response) -> | ||
new Admin.DashboardController(request, response).show() | ||
|
||
app.get '/admin/events', (request, response) -> | ||
new Admin.EventsController(request, response).index() | ||
|
||
app.get '/admin/events/new', (request, response) -> | ||
new Admin.EventsController(request, response).new() | ||
|
||
app.post '/admin/events/create', (request, response) -> | ||
new Admin.EventsController(request, response).create() | ||
|
||
app.get '/admin/events/:id', (request, response) -> | ||
new Admin.EventsController(request, response).show() | ||
app.get '/admin/events', Admin.EventsController.index | ||
app.get '/admin/events/new', Admin.EventsController.new | ||
app.post '/admin/events/create', Admin.EventsController.create | ||
app.get '/admin/events/:id', Admin.EventsController.show |