Skip to content

Commit

Permalink
Clean Up
Browse files Browse the repository at this point in the history
closes #4
  • Loading branch information
jonstorer committed Sep 13, 2012
1 parent b4f0be1 commit 29ea6a4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 76 deletions.
14 changes: 5 additions & 9 deletions app/controllers/admin/dashboard_controller.coffee
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 '/'
33 changes: 15 additions & 18 deletions app/controllers/admin/events_controller.coffee
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.
27 changes: 12 additions & 15 deletions app/controllers/admin/sessions_controller.coffee
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 '/'
16 changes: 6 additions & 10 deletions app/controllers/homes_controller.coffee
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
1 change: 1 addition & 0 deletions config/application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = (app) ->
app.set 'view engine', 'jade'
app.use express.favicon()
app.use express.bodyParser()
app.use express.logger('dev')
app.use express.methodOverride()
app.use express.cookieParser('2ee27441d3ee4a527de019325dc7e8ddee6039cc7cad9801181c6fd68204129bdf3225cafabb3f6d0324a7bd851dabbd0bd3')
app.use express.session()
Expand Down
34 changes: 10 additions & 24 deletions config/routes.coffee
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

0 comments on commit 29ea6a4

Please sign in to comment.