-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathaccount.php
136 lines (114 loc) · 4.44 KB
/
account.php
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
<?php
/**
* fruithost | OpenSource Hosting
*
* @author Adrian Preuß
* @version 1.0.0
* @license MIT
*/
use fruithost\Accounting\Auth;
use fruithost\Localization\I18N;
use fruithost\Security\Encryption;
use fruithost\Storage\Database;
if(isset($_POST['action']) && $_POST['action'] === 'save') {
switch($tab) {
case 'password':
if(empty($_POST['password_current'])) {
$template->assign('error', I18N::get('Please enter your current password.'));
return;
}
if(empty($_POST['password_new'])) {
$template->assign('error', I18N::get('Please enter your new password.'));
return;
}
if(empty($_POST['password_repeated'])) {
$template->assign('error', I18N::get('Please repeat your new password.'));
return;
}
$result = Database::single('SELECT `password` FROM `' . DATABASE_PREFIX . 'users` WHERE `id`=:user_id LIMIT 1', [
'user_id' => Auth::getID()
]);
if(strtoupper(hash('sha512', sprintf('%s%s%s', Auth::getID(), MYSQL_PASSWORTD_SALT, $_POST['password_current']))) !== $result->password) {
$template->assign('error', I18N::get('Your current password is not correct!'));
return;
}
if(strlen($_POST['password_new']) < 8) {
$template->assign('error', I18N::get('The new password must contain the minimum number of 8 characters.'));
return;
}
if($_POST['password_new'] !== $_POST['password_repeated']) {
$template->assign('error', I18N::get('Your password and confirmation password do not match.'));
return;
}
Database::update(DATABASE_PREFIX . 'users', 'id', [
'id' => Auth::getID(),
'password' => strtoupper(hash('sha512', sprintf('%s%s%s', Auth::getID(), MYSQL_PASSWORTD_SALT, $_POST['password_new']))),
'lost_enabled' => 'NO',
'lost_token' => NULL
]);
$template->assign('success', I18N::get('Your password has been updated.'));
break;
default:
if(empty($_POST['email'])) {
$template->assign('error', I18N::get('Please enter your E-Mail address.'));
return;
}
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$template->assign('error', I18N::get('Please enter a valid E-Mail address.'));
return;
}
if(empty($_POST['name_first'])) {
$template->assign('error', I18N::get('Please enter your first name.'));
return;
}
if(empty($_POST['name_last'])) {
$template->assign('error', I18N::get('Please enter your last name.'));
return;
}
if(empty($_POST['phone'])) {
$template->assign('error', I18N::get('Please enter your phone number.'));
return;
}
if(empty($_POST['address'])) {
$template->assign('error', I18N::get('Please enter your address.'));
return;
}
if(Database::exists('SELECT `id` FROM `' . DATABASE_PREFIX . 'users_data` WHERE `user_id`=:user_id LIMIT 1', [
'user_id' => Auth::getID()
])) {
Database::update(DATABASE_PREFIX . 'users_data', 'user_id', [
'user_id' => Auth::getID(),
'phone_number' => Encryption::encrypt($_POST['phone'], ENCRYPTION_SALT),
'address' => Encryption::encrypt($_POST['address'], ENCRYPTION_SALT),
'name_first' => Encryption::encrypt($_POST['name_first'], ENCRYPTION_SALT),
'name_last' => Encryption::encrypt($_POST['name_last'], ENCRYPTION_SALT)
]);
} else {
Database::insert(DATABASE_PREFIX . 'users_data', [
'id' => NULL,
'user_id' => Auth::getID(),
'phone_number' => Encryption::encrypt($_POST['phone'], ENCRYPTION_SALT),
'address' => Encryption::encrypt($_POST['address'], ENCRYPTION_SALT),
'name_first' => Encryption::encrypt($_POST['name_first'], ENCRYPTION_SALT),
'name_last' => Encryption::encrypt($_POST['name_last'], ENCRYPTION_SALT)
]);
}
$data = Database::single('SELECT * FROM `' . DATABASE_PREFIX . 'users_data` WHERE `user_id`=:user_id LIMIT 1', [
'user_id' => Auth::getID()
]);
Database::update(DATABASE_PREFIX . 'users', 'id', [
'id' => Auth::getID(),
'email' => $_POST['email']
]);
foreach($data AS $index => $entry) {
if(in_array($index, [ 'id', 'user_id' ])) {
continue;
}
$data->{$index} = Encryption::decrypt($entry, ENCRYPTION_SALT);
}
$template->assign('data', $data);
$template->assign('success', I18N::get('Your personal data has been updated.'));
break;
}
}
?>