1<?php
2
3/*
4 +-------------------------------------------------------------------------+
5 | Copyright 2010-2021, Davide Franco			                           |
6 |                                                                         |
7 | This program is free software; you can redistribute it and/or           |
8 | modify it under the terms of the GNU General Public License             |
9 | as published by the Free Software Foundation; either version 2          |
10 | of the License, or (at your option) any later version.                  |
11 |                                                                         |
12 | This program is distributed in the hope that it will be useful,         |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
15 | GNU General Public License for more details.                            |
16 +-------------------------------------------------------------------------+
17*/
18
19class UserSettingsView extends CView
20{
21    protected $userauth;
22    protected $username;
23
24    public function __construct()
25    {
26        parent::__construct();
27
28        $this->templateName = 'usersettings.tpl';
29        $this->name = 'User settings';
30        $this->title = '';
31        $this->username = '';
32        $this->userauth = new UserAuth();
33    }
34
35    public function prepare()
36    {
37        $this->username = $_SESSION['username'];
38        $this->assign('username', $this->username);
39
40        $user = $this->userauth->getData($this->username);
41        $this->assign('email', $user['email']);
42
43        // Check if password reset have been requested
44        if (isset($_REQUEST['action'])) {
45            switch ($_REQUEST['action']) {
46            case 'passwordreset':
47                // Check if provided current password is correct
48                if ($this->userauth->authUser($_SESSION['username'], $_POST['oldpassword']) == 'yes') {
49
50                    // Update user password with new one
51                    if ($this->userauth->setPassword($_SESSION['username'], $_POST['newpassword'])) {
52                        $this->userAlert = 'Password successfuly updated';
53                        $this->userAlertType = 'success';
54                    }
55                } else {
56                    $this->userAlert = 'Current password do not match';
57                    $this->userAlertType = 'danger';
58                }
59                break;
60            }
61        }
62    }
63} // end of class
64