User: refactor

master
E. Almqvist 3 years ago
parent df80485944
commit 6e670120ee
  1. 12
      src/app.rb
  2. 1
      src/db_models.rb
  3. 5
      src/func.rb
  4. 2
      src/views/user/login.slim
  5. 1
      src/views/user/register.slim

@ -27,15 +27,15 @@ get "/style.css" do
end
get "/" do
slim :index, locals: {data: init_data}
slim :index, locals: {info: init_info}
end
get "/login" do
slim :"user/login", locals: {data: init_data}
slim :"user/login", locals: {info: init_info}
end
get "/register" do
slim :"user/register", locals: {data: init_data}
slim :"user/register", locals: {info: init_info}
end
# API stuff
@ -48,11 +48,11 @@ post "/user" do
password = params[:password]
password_confirm = params[:password_confirm]
status, data = user.register(email, name, password, password_confirm)
status, info = user.register(email, name, password, password_confirm)
if !status then # if something went wrong then return to 0
redirect "/register", locals: {data: init_data(data)}
redirect "/register", locals: {info: init_info(info)}
else # if everything went right then continue
redirect "/login", locals: {data: init_data(data)}
redirect "/login", locals: {info: init_info(info)}
end
end

@ -17,6 +17,7 @@ class User < Table
# Register a new user
# Returns: success?, data
# TODO: input checks & ERRORS!
def register(email, name, password, password_confirm)
check_email = self.find_by_email(email)
if( check_email.length > 0 ) then

@ -3,8 +3,9 @@ def get_random_subtitle
subtitles.sample.chomp
end
def init_data(data={})
def init_info(info={})
g = Hash.new ""
g.merge(data)
info = g.merge(info)
return info
end

@ -1,7 +1,7 @@
.form-container
form action="/user/login" method="post"
h2 Log in
label.error_msg = params[:error]
label.error_msg = info
input type="text" name="email" placeholder="Email"
input type="password" name="password" placeholder="Password"
input type="submit" value="Log in"

@ -1,6 +1,7 @@
.form-container
form action="/user" method="post"
h2 Register Account
label.error_msg = info
input type="text" name="email" placeholder="Email"
input type="text" name="name" placeholder="Name"
input type="password" name="password" placeholder="Password"

Loading…
Cancel
Save