This repository has been archived by the owner on Jun 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.rb
148 lines (123 loc) · 3.66 KB
/
admin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# encoding: utf-8
require 'data_mapper'
require 'slim'
module Assassins
class App < Sinatra::Base
before do
@admin = nil
if session.has_key? :admin_id
@admin = Admin.get session[:admin_id]
if @admin.nil?
session.delete :admin_id
end
end
end
set :is_admin do |val|
condition {[email protected]? == val}
end
get '/admin' do
redirect to('/admin/dashboard')
else
redirect to('/admin/login')
end
end
get '/admin/login' do
if Admin.count == 0
redirect to('/admin/create')
else
slim :'admin/login'
end
end
post '/admin/login' do
user = Admin.first(:username => params['username'])
if (user.nil?)
return slim :'admin/login', :locals => {:errors =>
['Invalid username. Please try again.']}
end
if (user.password != params['password'])
return slim :'admin/login', :locals => {:errors =>
['Incorrect password. Please try again.']}
end
session[:admin_id] = user.id
redirect to('/admin/dashboard')
end
get '/admin/logout' do
session.delete :admin_id
redirect to('/')
end
get '/admin/create' do
if Admin.count == 0 || [email protected]?
slim :'admin/create'
else
redirect to('/admin')
end
end
post '/admin/create' do
if Admin.count != 0 && @admin.nil?
return redirect to('/')
end
if params['password'] != params['password_confirm']
return slim :'admin/create', :locals => {:errors =>
["Passwords don't match"]}
end
admin = Admin.new(:username => params['username'],
:password => params['password'])
if admin.save
session[:admin_id] = admin.id
redirect to('/admin/dashboard')
else
slim :'admin/create', :locals => {:errors => admin.errors.full_messages}
end
end
get '/admin/dashboard', :is_admin => true do
slim :'admin/dashboard'
end
get '/admin/dashboard/details', :is_admin => true do
slim :'admin/details'
end
get '/admin/dashboard/toggle_freeforall', :is_admin => true do
@game.freeforall = [email protected]
@game.save
redirect to('/admin/dashboard')
end
get '/admin/dashboard/shuffle_targets', :is_admin => true do
players = Player.all({:is_verified => true, :is_alive => true})
players.shuffle!
shuffle_time = Time.now
players.each_index do |i|
players[i].set_target_notify(players[(i + 1) % players.length])
players[i].last_activity = shuffle_time
players[i].save!
end
redirect to('/admin/dashboard')
end
post '/admin/dashboard/start_game', :is_admin => true do
players = Player.all({:is_verified => true})
players.shuffle!
start_time = Time.now
@game.start_time = start_time
@game.save
players.each_index do |i|
players[i].set_target_notify(players[(i + 1) % players.length])
players[i].last_activity = start_time
players[i].save!
end
redirect to('/admin/dashboard')
end
post '/admin/dashboard/send_mass_email', :is_admin => true do
Player.send_email_all(params['subject'], params['body'])
redirect to('/admin/dashboard')
end
post '/admin/reinstate/:id', :is_admin => true do |id|
player = Player.first(:netid => id)
tagger = player.tagged_by
player.set_target_notify tagger.target
tagger.set_target_notify player
player.is_alive = true
player.save!
"Success! Player updated."
end
end
end
# vim:set ts=2 sw=2 et: