Login stuff

master
E. Almqvist 3 years ago
parent fdd039857b
commit 3fd9f500c4
  1. 43
      wesweb01/evil_infosite/app.rb
  2. 9
      wesweb01/evil_infosite/views/layout.slim
  3. 10
      wesweb01/evil_infosite/views/login.slim
  4. 55
      wesweb01/evil_infosite/views/person.slim
  5. 6
      wesweb01/evil_infosite/views/register.slim

@ -5,20 +5,49 @@ require "slim"
load "db_parse.rb"
enable :sessions
db_cache = get_db() # get all the parsed data
user_creds = {
admin: "superpassword"
}
get "/" do
slim(:person, locals: {persondata: db_cache})
end
get "/login" do
get "/loginpage" do
slim(:login)
end
get "/userpage" do
userinfo = {
username: params[:username],
password: params[:password]
}
slim(:userpage, locals: {userinfo: userinfo})
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
end

@ -12,6 +12,11 @@ html
body
h1 Evil Info Site
h2 A person registry. No we don't care about GDPR.
.persons-container
== yield
a href="/loginpage" Login
a href="/registerpage" Register
- if(session[:username] != "") then
h1 Hello, #{session[:username]}
- if(session[:msg] != "") then
h1 = session[:msg]
== yield

@ -1,4 +1,6 @@
form action="/userpage" method="get"
input type="text" name="username"
input type="password" name="password"
input type="submit" value="Login"
article
form action="/login" method="post"
input type="text" name="username" placeholder="Username"
input type="password" name="password" placeholder="Password"
input type="submit" value="Login"

@ -1,28 +1,29 @@
- persondata.each do |data|
article.person
img.avatar src="#{data[:avatar_url]}"
.persons-container
- persondata.each do |data|
article.person
img.avatar src="#{data[:avatar_url]}"
.info
h1 #{data[:fname]} #{data[:lname]}
ul
li
label Email:
a href="mailto:#{data[:email]}" = data[:email]
li
label Age:
span #{data[:age]}
li
label IPv4 Address:
a href="https://api.iplocation.net/?ip=#{data[:ipv4]}" target="_blank" = data[:ipv4]
li
label Movie title:
a href="https://www.imdb.com/find?q=#{data[:movie_title]}" target="_blank" = data[:movie_title]
li
label Role:
span #{data[:role]}
li
label Visiting Frequency:
span #{data[:freq]}
li
label Gender:
span #{data[:gender]}
.info
h1 #{data[:fname]} #{data[:lname]}
ul
li
label Email:
a href="mailto:#{data[:email]}" = data[:email]
li
label Age:
span #{data[:age]}
li
label IPv4 Address:
a href="https://api.iplocation.net/?ip=#{data[:ipv4]}" target="_blank" = data[:ipv4]
li
label Movie title:
a href="https://www.imdb.com/find?q=#{data[:movie_title]}" target="_blank" = data[:movie_title]
li
label Role:
span #{data[:role]}
li
label Visiting Frequency:
span #{data[:freq]}
li
label Gender:
span #{data[:gender]}

@ -0,0 +1,6 @@
article
form action="/register" method="post"
input type="text" name="username" placeholder="Username"
input type="password" name="password" placeholder="Password"
input type="submit" value="Register"
Loading…
Cancel
Save