/
User.php
191 lines (151 loc) · 6.46 KB
/
User.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
namespace Models;
use Models\Base\User as BaseUser;
use Controllers\Controller as Controller;
/**
* Skeleton subclass for representing a row from the 'users' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class User extends BaseUser
{
public function signInUpdate() {
$this->setSigninCount($this->getSigninCount()+1);
$this->setLastSigninAt(date("U"));
$this->save();
}
public static function checkRegistrationValidity() {
if(preg_match('/[^a-zA-Z0-9]/', $_POST['regPassword'])){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo obsahuje nepovolené znaky nebo mezeru.');
}
if(strlen(utf8_decode($_POST["regPassword"])) < 8){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo je příliš krátké.');
}
if(strlen(utf8_decode($_POST["regPassword"])) > 32){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo je příliš dlouhé.');
}
if(preg_match('/[^a-zA-Z0-9]/', $_POST["regUsername"])){
$popups[] = array('type' => 'danger', 'content' => 'Vaše uživatelské jméno obsahuje nepovolené znaky nebo mezeru.');
}
if(isset($popups)){
foreach($popups as $p){
Controller::addPopup($p["type"], $p["content"]);
}
return false;
}
return true;
}
public static function checkExistingUsernameEmail() {
$existing = UserQuery::create()
->filterByUsername($_POST["regUsername"])
->_or()
->filterByEmail($_POST["regEmail"])
->findOne();
return $existing;
}
public static function checkPasswordChangeValidity() {
if($_POST["new_password1"] != $_POST["new_password2"]) {
$popups[] = array('type' => 'danger', 'content' => 'Nová hesla nejsou stejná.');
}
if($_SESSION["user"]->getPassword() != sha1($_POST["old_password"])) {
$popups[] = array('type' => 'danger', 'content' => 'Špatně zadané původní heslo.');
}
if(preg_match('/[^a-zA-Z0-9]/', $_POST['regPassword'])){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo obsahuje nepovolené znaky nebo mezeru.');
}
if(strlen(utf8_decode($_POST["regPassword"])) < 8){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo je příliš krátké.');
}
if(strlen(utf8_decode($_POST["regPassword"])) > 32){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo je příliš dlouhé.');
}
if(sha1($_POST["new_password1"]) == $_SESSION["user"]->getPassword()) {
$popups[] = array('type' => 'danger', 'content' => 'Toto heslo je již přiřazeno k vašemu účtu.');
}
if(isset($popups)){
foreach($popups as $p){
Controller::addPopup($p["type"], $p["content"]);
}
return false;
}
return true;
}
public static function checkUsernameChangeValidity() {
if($_SESSION["user"]->getUsername() == $_POST["username"]) {
$popups[] = array('type' => 'danger', 'content' => 'Toto jméno je již přiřazeno k vašemu účtu.');
}
if(preg_match('/@/', $_POST["username"])){
$popups[] = array('type' => 'danger', 'content' => 'Vaše uživatelské jméno obsahuje nepovolené znaky.');
}
if(isset($popups)){
foreach($popups as $p){
Controller::addPopup($p["type"], $p["content"]);
}
return false;
}
return true;
}
public static function checkBugReportValidity() {
if(strlen(utf8_decode($_POST["description"])) >= 1000){
$popups[] = array(
'type' => 'danger',
'content' => 'Popis chyby je příliš dlouhý. Popis by měl obsahovat maximálně 1000 znaků.'
);
}
if(strlen(utf8_decode($_POST["location"])) >= 200){
$popups[] = array(
'type' => 'danger',
'content' => 'Lokalizace chyby je příliš dlouhá. Lokalizace by měla obsahovat maximálně 200 znaků.'
);
}
if(isset($_POST["device"])){
if(strlen(utf8_decode($_POST["device"])) >= 200){
$popups[] = array(
'type' => 'danger',
'content' => 'Popis zařízení je příliš dlouhý. Popis zařízení by měl obsahovat maximálně 200 znaků.'
);
}
}
if(isset($_POST["browser"])){
if(strlen(utf8_decode($_POST["browser"])) >= 100){
$popups[] = array(
'type' => 'danger',
'content' => 'Popis prohlížeče je příliš dlouhý. Popis prohlížeče by měl obsahovat maximálně 100 znaků.'
);
}
}
if(isset($popups)){
foreach($popups as $p){
Controller::addPopup($p["type"], $p["content"]);
}
return false;
}
return true;
}
public static function checkPasswordResetValidity() {
if($_POST['password'] != $_POST['password_again']){
$popups[] = array('type' => 'danger', 'content' => 'Hesla se neshodují.');
}
if(preg_match('/[^a-zA-Z0-9]/', $_POST['password'])){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo obsahuje nepovolené znaky nebo mezeru.');
}
if(strlen(utf8_decode($_POST["password"])) < 8){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo je příliš krátké.');
}
if(strlen(utf8_decode($_POST["password"])) > 32){
$popups[] = array('type' => 'danger', 'content' => 'Vaše heslo je příliš dlouhé.');
}
if(isset($popups)){
foreach($popups as $p){
Controller::addPopup($p["type"], $p["content"]);
}
return false;
}
return true;
}
}