-
Notifications
You must be signed in to change notification settings - Fork 2
/
controller.php
153 lines (142 loc) · 4.15 KB
/
controller.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
<?php
/* WEB INTERFACE
*/////////////////////////////////////////////////////
function ctr_homepage(){
if( !empty($_SESSION['username']) ) :
echo 'logged in as '.$_SESSION['username'].'<br/>';
echo '<a href="profile">profile</a>';
else : echo '<a href="login">login</a>';
endif;
}
function ctr_profile( $mysqli ){
$results=array();
if( $_POST['email']&&$_POST['email']!=$_SESSION['email']
|| $_POST['username']&&$_POST['username']!=$_SESSION['username']
|| $_POST['name']&&$_POST['name']!=$_SESSION['name'] )
$results = user_update( $mysqli,
$_SESSION['id'],
$_POST['email'],
$_POST['username'],
$_POST['name']);
if($_POST['old']
||$_POST['new']
||$_POST['re-type'])
$results = user_change_password_via_profile( $mysqli,
$_SESSION['id'],
$_POST['old'],
$_POST['new'],
$_POST['re-type']);
include "../view/profile.inc";
}
function ctr_register( $mysqli ){
if($_POST['name']
||$_POST['email']
||$_POST['username']
||$_POST['password']
||$_POST['re-type'])
$results = user_register( $mysqli,
$_POST['name'],
$_POST['email'],
$_POST['username'],
$_POST['password'],
$_POST['re-type']);
else $results=array("");
if(empty($results)) : echo 'das good';
else : include "../view/register.inc";
endif;
}
function ctr_login( $mysqli ){
if($_POST['email']
||$_POST['password']) :
if( user_login( $mysqli,
$_POST['email'],
$_POST['password']) ) :
echo 'welcome '.$_SESSION['username'];
return;
else : $result = 'invalid credentials';
endif;
endif;
include "../view/login.inc";
}
function ctr_forgot_password(){
if($_POST['email']) :
send_user_request_new_password_email( $_POST['email'], $_POST['k']);
echo 'an email has been sent with instructions on how to change your password';
else : include "../view/forgot-password.inc";
endif;
}
function ctr_change_password( $mysqli, $uri, $uri_seg ){
if($_POST['key']
||$_POST['username']
||$_POST['password']
||$_POST['re-type']) :
$uri_seg = decode_uri($_POST['uri']);
$results = user_change_password_via_email( $mysqli,
$uri_seg[1],
$uri_seg[2],
$uri_seg[3],
$_POST['key'],
$_POST['username'],
$_POST['password'],
$_POST['re-type']);
else : $results=array("");
endif;
if($results[0]=='password changed') :
echo 'password changed successfully';
$_SESSION['pass_change_attempts'] = 0;
else :
if(empty($_SESSION['pass_change_attempts']))
$_SESSION['pass_change_attempts'] = 1;
else $_SESSION['pass_change_attempts']++;
if( $_SESSION['pass_change_attempts'] > 3)
sleep($_SESSION['pass_change_attempts']-2);
include "../view/change-password.inc";
endif;
}
function ctr_activate_user( $mysqli, $uri_seg ){
if( user_activate($mysqli, 0, $uri_seg[1],
$uri_seg[2], $uri_seg[3],
substr($uri_seg[4],0,$uri_seg[5])) )
echo 'activation successful, welcome '.$uri_seg[1];
else echo 'account already active';
}
function ctr_change_password_uri($uri){
$results=array("");
include "../view/change-password.inc";
}
/* MOBILE INTERFACE
*/////////////////////////////////////////////////////
function ctr_get_user_data( $mysqli, $credentials ){
if( user_login($mysqli, $credentials[0], $credentials[1]) == "OK" )
echo $_SESSION['role']."/".$_SESSION['banned']."/".$_SESSION['username']."/"
.$_SESSION['name']."/".$_SESSION['created'];
else echo 'NO';
}
function ctr_remote_register( $mysqli, $data ){
$results = user_register( $mysqli,
$data[1],$data[0], $data[2],
$data[3],$data[3] );
if(empty($results)) echo 'OK';
else echo encode_remote_response($results);
}
function ctr_remote_forgot_password( $data ){
if(send_user_request_new_password_email($data[0],$data[1]))
echo "OK";
else echo 'The email submission'.$GLOBALS['FAILURE'];
}
function ctr_remote_password_change( $mysqli, $data ){
$results = user_change_password_via_profile(
$mysqli, $_SESSION['id'], $data[0],
$data[1], $data[2]);
if( $results[0] == "password changed" )
echo 'OK';
else echo encode_remote_response($results);
}
function ctr_remote_edit( $mysqli, $data ){
$results = user_update( $mysqli, $_SESSION['id'],
$data[0],$data[1],$data[2]);
if( $results[0] == 'profile updated' )
echo 'OK';
else echo encode_remote_response($results);
}
?>