summaryrefslogtreecommitdiffstats
path: root/app/model/auth.mod.php
blob: aa0adf38cec996b4e0980f86d0c7176302143d6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php

require_once "model/common.mod.php";
require_once "class/user.class.php";
require_once "class/form.class.php";

class AuthModel extends CommonModel
{
    /*
     * Default action
     */
    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;

        return true;
    }

    /*
     * Initial signup action
     */
    function initialSignup()
    {
        $this->noaccounts = true;
    }

    /*
     * Signup action
     */
    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() . "/");
    }
}

?>