From a21e20b7a8db343129aa8713853358bdb77de939 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 2 Jan 2016 13:30:46 -0500 Subject: + Added model for new page master layer ("Common" MVC) --- app/model/common.mod.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/model/common.mod.php (limited to 'app/model') diff --git a/app/model/common.mod.php b/app/model/common.mod.php new file mode 100644 index 0000000..d4270d8 --- /dev/null +++ b/app/model/common.mod.php @@ -0,0 +1,9 @@ + -- cgit v1.2.3 From 735230c9125314e5a185e82c57cac0ad2e11b996 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 3 Jan 2016 12:47:30 -0500 Subject: + Added model for Auth MVC --- app/model/auth.mod.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/model/auth.mod.php (limited to 'app/model') diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php new file mode 100644 index 0000000..9c356e2 --- /dev/null +++ b/app/model/auth.mod.php @@ -0,0 +1,15 @@ + -- cgit v1.2.3 From 9ce26b55017a24f3cae5c20958f2d612273c2f60 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Tue, 26 Jan 2016 21:55:43 -0500 Subject: + Added function to User class to fetch all users from DB * Altered Auth MVC deflt action to return false if no users are found. This way, the Auth controller can automatically present user a page to create an admin account --- app/model/auth.mod.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/model') diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php index 9c356e2..9cd6b7c 100644 --- a/app/model/auth.mod.php +++ b/app/model/auth.mod.php @@ -1,6 +1,7 @@ getAllUsers_orderByName()) == 0) + return false; + + return true; } } -- cgit v1.2.3 From 3a111ed74e89e9634e5baf4375625acc6ad262e6 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 28 Jan 2016 20:39:47 -0500 Subject: Finish signup and initialSignup actions on Auth MVC If no accounts exist no login page will be shown. Instead, the app presents the signup page to allow the administrator to create his account. This is the only case where a new account should be an admin by default. --- app/model/auth.mod.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app/model') diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php index 9cd6b7c..5b655d6 100644 --- a/app/model/auth.mod.php +++ b/app/model/auth.mod.php @@ -20,6 +20,21 @@ class AuthModel extends CommonModel return true; } + + /* + * Initial signup action + */ + function initialSignup() + { + $this->noaccounts = true; + } + + /* + * Signup action + */ + function signup() + { + } } ?> -- cgit v1.2.3 From ed1b89d4aa07393d7a9f75c689c4877acfa38826 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 30 Jan 2016 21:49:42 -0500 Subject: Implement signup_submit action on Auth MVC Submissions to the Auth signup page are now fully handled by either creating a new account (User object in the system) or posting an error message to the page (Auth model) --- app/model/auth.mod.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'app/model') diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php index 5b655d6..aa0adf3 100644 --- a/app/model/auth.mod.php +++ b/app/model/auth.mod.php @@ -2,6 +2,7 @@ require_once "model/common.mod.php"; require_once "class/user.class.php"; +require_once "class/form.class.php"; class AuthModel extends CommonModel { @@ -35,6 +36,39 @@ class AuthModel extends CommonModel function signup() { } + + /* + * Attempt to register a new account + */ + function signupSubmit($input) + { + $form = new Form(); + $form->field_text("username"); + $form->field_text("password", null, false); + $form->field_text("cPassword", null, false); + + if (!$form->populate($input)) + { + $this->logFormErrors($form); + return; + } + + if ($form->password != $form->cPassword) + { + $this->logError("Passwords do not match"); + return; + } + + $user = new User(); + + if (!$user->createNewUser($form->username, $form->password)) + { + $this->logError("Your requested username is already in use"); + return; + } + + $this->redirectTo($this->ap() . "/"); + } } ?> -- cgit v1.2.3 From 1a2cf00b5e1a9c00be823eb655a76f8625bf32b5 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 31 Jan 2016 12:47:04 -0500 Subject: Merge Auth MVC, initial_signup action into signup There was a mistake that caused the page notice about no accounts existing to sometimes not showup in error. This merge resolves that issue as well as tidys up the code a bit. --- app/model/auth.mod.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'app/model') diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php index aa0adf3..cdf416b 100644 --- a/app/model/auth.mod.php +++ b/app/model/auth.mod.php @@ -22,19 +22,15 @@ class AuthModel extends CommonModel return true; } - /* - * Initial signup action - */ - function initialSignup() - { - $this->noaccounts = true; - } - /* * Signup action */ function signup() { + $userTbl = new User(); + + if (count($userTbl->getAllUsers_orderByName()) == 0) + $this->noaccounts = true; } /* -- cgit v1.2.3 From 8640c13c934ff3e6d907b1e335edb83da088a2ca Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 31 Jan 2016 20:33:38 -0500 Subject: Log in on signup success Now, on a successful submission of the signup view form (Auth MVC), the app automatically logs in the newly-created user and redirects to Framework::ap() . "/". Placeholder code has been added to the root controller to simply var_dump() the current logged in user if one exists, otherwise the login view (Auth MVC) is shown --- app/model/auth.mod.php | 1 + 1 file changed, 1 insertion(+) (limited to 'app/model') diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php index cdf416b..9fa67e4 100644 --- a/app/model/auth.mod.php +++ b/app/model/auth.mod.php @@ -63,6 +63,7 @@ class AuthModel extends CommonModel return; } + $this->setCurrentUser($user); $this->redirectTo($this->ap() . "/"); } } -- cgit v1.2.3 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') 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 From b3a31ffef3a6203ec61e745821945b371fff7c22 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 6 Feb 2016 18:18:11 -0500 Subject: Update Auth model to reflect changes in previous commit --- app/model/auth.mod.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'app/model') diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php index 2b61b91..23b8288 100644 --- a/app/model/auth.mod.php +++ b/app/model/auth.mod.php @@ -3,6 +3,7 @@ require_once "model/common.mod.php"; require_once "class/user.class.php"; require_once "class/form.class.php"; +require_once "class/setting.class.php"; class AuthModel extends CommonModel { @@ -11,33 +12,35 @@ class AuthModel extends CommonModel */ function deflt() { - /* Make sure user accounts exist since this is preping the page to login. If there are no accounts in the DB, - * return false to signal controller to display the admin account creation */ - $userTbl = new User(); if (count($userTbl->getAllUsers_orderByName()) == 0) - return false; + { + $this->noaccounts = true; + $this->activeTab['signup'] = "in active"; + $this->tabSwap = false; + } - return true; + else + { + $this->activeTab['login'] = "in active"; + $this->tabSwap = Setting::allowPublicSignup(); + } } /* - * Signup action + * Attempt to register a new account */ - function signup() + function signup($input) { $userTbl = new User(); - if (count($userTbl->getAllUsers_orderByName()) == 0) - $this->noaccounts = true; - } + if (!Setting::allowPublicSignup() && count($userTbl->getAllUsers_orderByName()) > 0) + { + $this->logError("You may not signup at this time"); + return; + } - /* - * Attempt to register a new account - */ - function signupSubmit($input) - { $form = new Form(); $form->field_text("username"); $form->field_text("password", null, false); -- cgit v1.2.3