Skip to content

Commit

Permalink
Creates admin page and model.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed Aug 5, 2014
1 parent 72ac0dd commit 39a56e5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class AdminController < ApplicationController
def index
logger.debug "current_user:"
logger.debug current_user
return if admin_only!

@admin = admin_info
end

def update
logger.debug session
logger.debug "current_user:"
logger.debug current_user
return if admin_only!

admin_info.multiuser = (params["multiuser"] == "on")
admin_info.save

redirect_to root_path
end
end
12 changes: 12 additions & 0 deletions app/models/admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# The Admin model contains system settings.

class Admin
include MongoMapper::Document

# Whether or not user accounts can be created
key :multiuser, Boolean

def can_create_user?
return !(User.count > 0 && !self.multiuser)
end
end
18 changes: 18 additions & 0 deletions app/views/admin/index.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- title("Admin")
- content_for :title do
= "Admin"

%h1
Administration

%h2
User Accounts

= form_for @admin, :url => "/admin", :html => {:name => "admin_form", :id => "admin-form", :class => "admin-form"} do |f|
%label{:for => :multiuser}
Allow New Accounts
%input{:type => :checkbox, :name => :multiuser, :id => :multiuser, :checked => @admin.multiuser}

%br

%input{:type => :submit, :value => :save}

0 comments on commit 39a56e5

Please sign in to comment.