summaryrefslogtreecommitdiffstats
path: root/app/model/settings.php
blob: 3262dec669d43a39f7b4f61cd551ca1ea076f88f (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
<?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";

/*
 * Action: settings-user - Modify user settings
 */
if (isAction("settings-user"))
{
    $form = new form();
    $form->text("guid");
    $form->flag("setpasswd");
    $form->text("curpasswd", false);
    $form->text("passwd", false);
    $form->text("cpasswd", false);
    $form->text("alias", false);
    $form->text("email", false);
    $form->text("emailVer", false);

    if (!$form->populate(input()))
        return;

    $user = new user($form->guid);

    /* permissions */
    if (!($cu = user::getCurrent()) || !$cu->canModify($user))
    {
        logError(ERROR, "You do not have permission to modify the selected user");
        return;
    }

    /* image file removal */
    if (isset(input()['rmImg-head']))
    {
        if ($user->rmHeadImg())
            logError(NOTICE, "User image removed");
        else
            logError(ERROR, "Error removing user image");
        return;
    }

    if (isset(input()['rmImg-bg']))
    {
        if ($user->rmBgImg())
            logError(NOTICE, "Background image removed");
        else
            logError(ERROR, "Error removing background image");
        return;
    }

    /* image file set */
    if ($user->setHeadImg("img-head"))
        logError(NOTICE, "User image updated");

    if ($user->setBgImg("img-bg"))
        logError(NOTICE, "Background image updated");

    /* modify object */
    if ($form->setpasswd)
    {
        if ($user->validatePasswd($form->curpasswd))
        {
            if ($form->passwd == $form->cpasswd)
            {
                $user->setPasswd($form->passwd);
                logError(NOTICE, "Password updated successfully");
            }
            else
                logError(WARNING, "Password not changed, passwords did not match");
        }
        else
            logError(WARNING, "Password not changed, current password was incorrect");
    }

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

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

    else if ($form->emailVer != "" && $user->emailConf == 0)
    {
        if (!$user->verifyEmail($form->emailVer))
            logError(WARNING, "Email not verified, key was incorrect");
    }

    $user->saveObj();
}

?>