From 04d30cfe16e11140c8efb22afd61f2386c35cd87 Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Tue, 20 Jul 2021 17:25:03 -0600 Subject: Handle input validation in abstract Form class --- signin.php | 61 +++++++++++++++++++------------------------------------------ 1 file changed, 19 insertions(+), 42 deletions(-) (limited to 'signin.php') diff --git a/signin.php b/signin.php index c2ee5a6..4f76d13 100755 --- a/signin.php +++ b/signin.php @@ -16,52 +16,29 @@ validate_username($_POST['user_name']); + $password = $form->validate_password($_POST['user_pass']); - if (!empty($errors)) { - $errstr = 'Please check the following problems: '; - trigger_error($errstr); - } else { - $user = new User(); - $user->get_by_name($user_name); + $form->on_success(function () use ($username, $password) { + $user = new User(); + $user->get_by_name($username); - if (!$user->has_value()) { - trigger_error('There is no user with that name. Did you mean to create a new account?'); - } else { - if (!password_verify($user_pass, $user->password)) { - echo 'Password does not match!'; - } else { - Session::get()->sign_in($user); - header("Location: index.php"); - } - } - } + if (!$user->has_value()) { + trigger_error('There is no user with that name. Did you mean to create a new account?'); + } else { + if (!password_verify($password, $user->password)) { + echo 'Password does not match!'; + } else { + Session::get()->sign_in($user); + header("Location: /"); + } + } + }); } ?> -- cgit v1.2.3