From faa6ca0b2e9430d2f9d689aab583a7f881ed03bf Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Mon, 1 Feb 2016 19:33:57 -0500 Subject: Implement 'login' action on Auth MVC Finished initial functionality for Auth MVC by implementing the login feature --- app/model/auth.mod.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/model/auth.mod.php') diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php index 9fa67e4..2b61b91 100644 --- a/app/model/auth.mod.php +++ b/app/model/auth.mod.php @@ -66,6 +66,33 @@ class AuthModel extends CommonModel $this->setCurrentUser($user); $this->redirectTo($this->ap() . "/"); } + + /* + * Attempt to login + */ + function login($input) + { + $form = new Form(); + $form->field_text("username"); + $form->field_text("password", null, false); + + if (!$form->populate($input)) + { + $this->logFormErrors($form); + return; + } + + $user = new User(); + + if (!($user->initByUsername($form->username) && $user->validatePassword($form->password))) + { + $this->logError("Username or password is incorrect"); + return; + } + + $this->setCurrentUser($user); + $this->redirectTo($this->ap() . "/"); + } } ?> -- cgit v1.2.3