Config & register progress

master
E. Almqvist 3 years ago
parent 6e670120ee
commit 6db13f193e
  1. 1
      src/app.rb
  2. 16
      src/config.rb
  3. 15
      src/db_models.rb

@ -49,6 +49,7 @@ post "/user" do
password_confirm = params[:password_confirm] password_confirm = params[:password_confirm]
status, info = user.register(email, name, password, password_confirm) status, info = user.register(email, name, password, password_confirm)
Console::debug "STATUS: #{status}", info
if !status then # if something went wrong then return to 0 if !status then # if something went wrong then return to 0
redirect "/register", locals: {info: init_info(info)} redirect "/register", locals: {info: init_info(info)}
else # if everything went right then continue else # if everything went right then continue

@ -0,0 +1,16 @@
# Register stuff
MIN_PASSWORD_LEN = 8
MIN_NAME_LEN = 2
EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
REGISTER_ERRORS = {
pass_len: "Password length must be at least #{MIN_PASSWORD_LEN}",
pass_notequals: "Password mismatch",
name_len: "Name length must be at least #{MIN_NAME_LEN}",
email_dupe: "Email already in use",
email_fake: "Use a real email"
}

@ -15,6 +15,19 @@ class User < Table
resp = self.get("*", "email = ?", email) resp = self.get("*", "email = ?", email)
end end
private def validate_credentials(email, name, password, password_confirm)
# Check email
check_email_dupe = self.find_by_email(email).length <= 0
check_email_valid = email.match(EMAIL_REGEX) != nil
# Name
check_name_len = name.length >= MIN_NAME_LEN
# Password
check_pass_equals = password == password_confirm
check_pass_len = password.length >= MIN_PASSWORD_LEN
end
# Register a new user # Register a new user
# Returns: success?, data # Returns: success?, data
# TODO: input checks & ERRORS! # TODO: input checks & ERRORS!
@ -33,7 +46,7 @@ class User < Table
} }
resp = self.insert(data) # insert into the db resp = self.insert(data) # insert into the db
return true, {resp: resp} return true, resp
else else
return false, {error_msg: "Password mismatch!"} return false, {error_msg: "Password mismatch!"}
end end

Loading…
Cancel
Save