-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
171 lines (134 loc) · 5.42 KB
/
Copy pathserver.php
File metadata and controls
171 lines (134 loc) · 5.42 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
session_start();
$errors = array();
include('DBConnection.php');
//
//// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form
$username = $_POST['username'];
$email = $_POST['email'];
$password_1 = $_POST['password_1'];
$password_2 = $_POST['password_2'];
if (empty($username)) {
array_push($errors, "Potrebno je vnositi uporabnisko ime");
}
if (empty($email)) {
array_push($errors, "Potrebno je vnositi uporabnisko email");
}
if (empty($password_1)) {
array_push($errors, "Potrebno je vnositi uporabnisko geslo");
}
if ($password_1 != $password_2)
{
array_push($errors, "The two passwords do not match");
}
//Prvoveruva dali postoi korisnik so isto korisnicko ime i mail
$stat=$db->query("SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1");
$stat->execute();
$stat->setFetchMode(PDO::FETCH_ASSOC);
while ($row = $stat->fetch()) {
if ($row['username']) { // if user exists
if ($row['username'] === $username) {
array_push($errors, "Username already exists");
}
if ($row['email'] === $email) {
array_push($errors, "email already exists");
}
}
}
//Prebrojuva dali imam errors odnosno dali postoi takov korisnik ako ne postoi go kreira akauntot
if (count($errors) == 0) {
$password = md5($password_1);//Go sifrira pasvordot
$stmt = $db->prepare("INSERT INTO users (username, email, password)
VALUES('$username', '$email', '$password')");
/* $stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':password_1', $_POST['password_1']);*/
$stmt->execute();
$_SESSION['username_uporabnik'] = $username;
$_SESSION['success_uporabnik'] = "Prijavljeni";
header('location: index.php');
}
}
//<-----ZA LOGIRANJE NA KORISNIKOT
if (isset($_POST['login_user'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}
$count_checked= @count($_POST['checklist']);
// $selected=(string)$_POST['checklist'];
// echo "selektirani se ".$count_checked." opcii";
if(@$count_checked<1){
array_push($errors,"Prosim izberite eno možnost");
}
elseif(@$count_checked>1){
array_push($errors,"Prosim izberite eno možnost");
}
elseif (@$count_checked==1) {
foreach ($_POST['checklist'] as $selected) {
if ($selected == 'user') {
if (count($errors) == 0) {
$password = md5($password);
$log=$db->prepare("SELECT * FROM users WHERE username='$username' AND password='$password'");
/* $log->bindParam(':username', $_POST['username']);
$log->bindParam(':email', $_POST['email']);
*/
$log->execute(
array(
'username' =>$_POST['username'],
'password' =>$_POST['password']
)
);
$count=$log->rowCount();
if($count>0){
$_SESSION['username_uporabnik'] = $username;
$_SESSION['success_uporabnik'] = "Prijavljen uporabnik:";
header('location: index.php');
}
else{
$msg="Napacno geslo in uporabnisko ime";
}
if(isset($msg)){
echo '<label class="text-danger">'.$msg.'</label>';
}
}
}
elseif($selected=='admin'){
if (count($errors) == 0) {
$log=$db->prepare("SELECT * FROM administrator WHERE IME='$username' AND GESLO='$password'");
/* $log->bindParam(':username', $_POST['username']);
$log->bindParam(':email', $_POST['email']);
*/
$log->execute(
array(
'username' =>$_POST['username'],
'password' =>$_POST['password']
)
);
$count=$log->rowCount();
if($count>0){
$_SESSION['username_admin'] = $username;
$_SESSION['success_admin'] = "Prijavljen admin:";
header('location:index.php');
}
else{
$msg="Napacno geslo in uporabnisko ime";
}
if(isset($msg)){
echo '<label class="text-danger">'.$msg.'</label>';
}
}
}
else{
echo " ";
}
}
}
}
?>