summaryrefslogtreecommitdiffstats
path: root/app/model/common.mod.php
blob: a0bf6aecc1a53952e6afa3817c8cf55443f63ba5 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php

require_once "model/master.mod.php";
require_once "class/form.class.php";
require_once "class/setting.class.php";

class CommonModel extends MasterModel
{
    /*
     * Get the glyphicon to use for the logged in user (user or admin)
     */
    function getCurrentUserGlyphicon()
    {
        if (!$this->getCurrentUser())
            return "";

        if ($this->getCurrentUser()->admin == 1)
            return "glyphicon glyphicon-sunglasses";
        else
            return "glyphicon glyphicon-user";
    }

    /*
     * Default action
     */
    function common_deflt()
    {
        global $_SCROTT;

        /* Admin settings tab */
        if ($_SCROTT['settSSL'] != "neither")
        {
            $this->common_settingAdminSettSSLChecked[$_SCROTT['settSSL']] = "checked";
            $this->common_settingAdminSettSSLDisabled = "disabled";
        }
        else
            $this->common_settingAdminSettSSLChecked[Setting::settSSL()] = "checked";

        if (Setting::allowPublicSignup())
            $this->common_settingAdminAllowPublicSignupChecked = "checked";
    }

    /*
     * Handle form submissions from common views
     */
    function common_handleFormSubmissions($input)
    {
        switch ($input['action'])
        {
            case "common-setting-user": $this->saveSettingUser($input); break;
        }
    }

    /*
     * Save changes to user account settings
     */
    function saveSettingUser($input)
    {
        $form = new Form();
        $form->field_bool("setPasswd");
        $form->field_text("curPasswd", null, false);
        $form->field_text("newPasswd", null, false);
        $form->field_text("confPasswd", null, false);
        $form->field_text("alias", "", false);
        $form->field_text("email", "", false);
        $form->field_text("emailConfKey", null, false);

        if (!$form->populate($input))
        {
            $this->logFormErrors($form);
            return;
        }

        $user = $this->getCurrentUser();

        if (!$user)
        {
            $this->logError("Not logged in");
            return;
        }

        if ($form->setPasswd == "true")
        {
            if ($user->validatePassword($form->curPasswd))
            {
                if ($form->newPasswd == $form->confPasswd)
                {
                    $user->setPassword($form->newPasswd);
                    $this->logNotice("Password updated successfully");
                }
                else
                    $this->logWarning("Password not changed -- Passwords did not match");
            }

            else
                $this->logWarning("Password not changed -- Current password was incorrect");
        }

        $user->alias = $form->alias;

        if ($form->email != $user->email)
            $user->setEmail($form->email);

        else if ($form->emailConfKey != "")
        {
            if (!$user->confirmEmailKey($form->emailConfKey))
                $this->logWarning("Email not confirmed -- Key was incorrect");
        }

        $user->saveObj();
    }
}

?>