-
Notifications
You must be signed in to change notification settings - Fork 14
/
student_directory.rb
77 lines (64 loc) · 1.83 KB
/
student_directory.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
require 'rubygems'
require 'sinatra'
# require 'sinatra/reloader'
require 'sqlite3'
require 'rack-flash'
require 'pry'
# Pull in each of our class files
require_relative 'person'
require_relative 'student'
require_relative 'instructor'
enable :sessions
use Rack::Flash
# Now the program actually starts here.
before '/' do
unless params[:password] == "1"
flash[:notice] = "Sorry, wrong password! Try again."
redirect '/login'
end
end
before '/index' do
unless params[:password] == "1"
flash[:notice] = "Sorry, wrong password! Try again."
redirect '/login'
end
end
post '/index' do
erb :index
end
#sends you to the student or instructor page depending on your entry, my case insensitive trick from the ruby clie doesnt work here.
post '/result' do
erb :result
if "#{params[:id]}" == "Student"
@choosen_id = params[:id]
redirect '/student'
elsif "#{params[:id]}" == "Instructor"
@choosen_id = params[:id]
redirect '/instructor'
else
flash[:notice] = "Please enter 'student' or 'instructor!"
end
end
get '/index' do
erb :index
end
get '/instructor' do
erb :instructor
end
get '/student' do
erb :student
end
post '/entry' do
#create an empty array to hold all the data the user entered from the instructor or student .erb page
someonex = []
someonex << [params[:id].to_i, params[:twitter], params[:name], params[:email], params[:reason], params[:iq]]
#we need to convert this from a 2d array to a 1d array, flatten takes care of that
someone = someonex.flatten
#now that we have all the data we can create a new student, execution jumps to person.rb
Student.new(someone)
#make sure to let the user know their data was entered and they will be spammed to death!
flash[:notice] = "Thank you for entering your info, we will begin spamming you shortly"
end
get '/login' do
erb :login
end