Old high school files. Lessson notes/codes/projects etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
886 B

#!/usr/bin/ruby
require "sinatra"
require "slim"
load "db_parse.rb"
3 years ago
enable :sessions
3 years ago
db_cache = get_db() # get all the parsed data
3 years ago
3 years ago
user_creds = {
admin: "superpassword"
}
3 years ago
get "/" do
3 years ago
slim(:person, locals: {persondata: db_cache})
end
3 years ago
3 years ago
get "/loginpage" do
3 years ago
slim(:login)
end
3 years ago
get "/registerpage" do
slim(:register)
end
post "/register" do
username = params[:username].to_sym
if( user_creds[username] == nil ) then
user_creds[username] = params[:password]
session[:msg] = "Account created."
redirect "/loginpage"
else
session[:msg] = "Username in use."
redirect "/loginpage"
end
end
post "/login" do
username = params[:username]
password = params[:password]
if( user_creds[username.to_sym] == password ) then
session[:username] = username
session[:msg] = "Login success."
redirect "/"
else
session[:msg] = "Login failed."
redirect "/login"
end
3 years ago
end