-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathprofile.php
More file actions
157 lines (149 loc) · 5.77 KB
/
profile.php
File metadata and controls
157 lines (149 loc) · 5.77 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Profile page
*
* PHP version 8
*
* Copyright (C) Ere Maijala 2018-2021
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category MLInvoice
* @package MLInvoice\Base
* @author Ere Maijala <ere@labs.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
require_once 'translator.php';
require_once 'config.php';
require_once 'miscfuncs.php';
require_once 'sessionfuncs.php';
require_once 'version.php';
/**
* Profile page
*
* @category MLInvoice
* @package MLInvoice\Base
* @author Ere Maijala <ere@labs.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
class Profile
{
/**
* View the profile form
*
* @return void
*/
public function launch()
{
$messages = [];
$errors = [];
$user = getUserById($_SESSION['sesUSERID']);
if (getPost('submit')) {
$newData = [];
if (($name = getPost('name')) && $name !== $user['name']) {
$newData['name'] = $name;
}
if (($email = getPost('email')) && $email !== $user['email']) {
$newData['email'] = $email;
}
if ($newData) {
updateUser($_SESSION['sesUSERID'], $newData);
$messages[] = Translator::translate('UserInformationSaved');
}
$oldPassword = getPost('oldpassword', '');
$newPassword = getPost('newpassword', '');
$newPassword2 = getPost('newpassword2', '');
if ($oldPassword && $newPassword && $newPassword2) {
if (!password_verify($oldPassword, $user['passwd'])
&& md5($oldPassword) != $user['passwd']
) {
$errors[] = Translator::translate('CurrentPasswordInvalid');
} else {
if ($newPassword !== $newPassword2) {
$errors[] = Translator::translate('NewPasswordsDontMatch');
} else {
updateUserPassword($_SESSION['sesUSERID'], $newPassword);
$messages[] = Translator::translate('PasswordChanged');
}
}
}
}
$user = getUserById($_SESSION['sesUSERID']);
?>
<div class="pagewrapper profile mb-4">
<div class="form_container profile-form">
<?php foreach ($errors as $message) {?>
<div class="alert alert-danger message">
<?php echo $message?>
</div>
<?php } ?>
<?php foreach ($messages as $message) {?>
<div class="alert alert-success">
<?php echo $message?>
</div>
<?php } ?>
<h3><?php echo $user['name']?></h3>
<form method="POST">
<div class="medium_label">
<?php echo Translator::translate('UserID')?>
</div>
<div class="static-field">
<?php echo htmlentities($user['login'])?>
</div>
<div class="medium_label">
<label for="name"><?php echo Translator::translate('Name')?></label>
</div>
<div class="field">
<input type="text" name="name" id="name" class="form-control medium" value="<?php echo htmlentities($user['name'])?>">
</div>
<div class="medium_label">
<label for="email"><?php echo Translator::translate('Email')?></label>
</div>
<div class="field">
<input type="text" name="email" id="email" class="form-control" value="<?php echo htmlentities($user['email'])?>">
</div>
<div class="field_sep"></div>
<div class="unlimited_label">
<?php echo Translator::translate('PasswordChangeInstructions') ?>
</div>
<div class="medium_label">
<label for="oldpassword"><?php echo Translator::translate('CurrentPassword')?></label>
</div>
<div class="field">
<input type="password" name="oldpassword" id="oldpassword" class="form-control" value="">
</div>
<div class="medium_label">
<label for="newpassword"><?php echo Translator::translate('NewPassword')?></label>
</div>
<div class="field">
<input type="password" name="newpassword" id="newpassword" class="form-control" value="">
</div>
<div class="medium_label">
<label for="newpassword2"><?php echo Translator::translate('ConfirmNewPassword')?></label>
</div>
<div class="field">
<input type="password" name="newpassword2" id="newpassword2" class="form-control" value="">
</div>
<div class="unlimited_label">
<input type="submit" name="submit" class="btn btn-primary" value="<?php echo Translator::translate('Save')?>">
</div>
<div class="clearfix"></div>
</form>
</div>
</div>
<?php
}
}