diff options
author | Malf Furious <m@lfurio.us> | 2018-02-09 00:56:45 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2018-02-09 00:56:45 -0500 |
commit | 3561ed3caec4754758a0b90e631dfed746b0c4fb (patch) | |
tree | 23aff51d3bfe646e195cbbb76ceecfbf5175a941 /app/model/login.php | |
parent | 47049c317f5d2a79de4ce5fa50b010467243a037 (diff) | |
download | scrott-3561ed3caec4754758a0b90e631dfed746b0c4fb.tar.gz scrott-3561ed3caec4754758a0b90e631dfed746b0c4fb.zip |
Add login model
Diffstat (limited to 'app/model/login.php')
-rw-r--r-- | app/model/login.php | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/app/model/login.php b/app/model/login.php new file mode 100644 index 0000000..af4a5b3 --- /dev/null +++ b/app/model/login.php @@ -0,0 +1,92 @@ +<?php + +/* + * SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * For more information, please refer to UNLICENSE + */ + +require_once "class/form.class.php"; +require_once "class/user.class.php"; +require_once "class/settings.class.php"; + +/* + * Action: login - Attempt to authenticate new user + */ +if (isAction("login")) +{ + $form = new form(); + $form->text("uname"); + $form->text("passwd", false); + + if (!$form->populate(input())) + goto prep; + + if (!(($user = user::getByUname($form->uname)) && + $user->validatePasswd($form->passwd))) + { + logError(ERROR, "Username or password is incorrect"); + goto prep; + } + + user::setCurrent($user); + location("/"); +} + +/* + * Action: signup - Attempt to register a new account + */ +if (isAction("signup")) +{ + if (!settings::allowPublicSignup() && + count(user::getAll_ordByUname()) > 0) + { + logError(ERROR, "You may not signup at this time"); + goto prep; + } + + $form = new form(); + $form->text("uname"); + $form->text("passwd", false); + $form->text("cpasswd", false); + + if (!$form->populate(input())) + goto prep; + + if ($form->passwd != $form->cpasswd) + { + logError(ERROR, "Passwords do not match"); + goto prep; + } + + if (!($user = user::initNew($form->uname, $form->passwd))) + { + logError(ERROR, "Your requested username is already in use"); + goto prep; + } + + user::setCurrent($user); + location("/"); +} + +prep: + + if (count(user::getAll_ordByUname()) == 0) + { + $noaccounts = true; + $activeTab['signup'] = "in active"; + $tabSwap = false; + } + else + { + $activeTab['login'] = "in active"; + $tabSwap = settings::allowPublicSignup(); + } + +?> |