-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
executable file
·317 lines (285 loc) · 9.45 KB
/
process.php
File metadata and controls
executable file
·317 lines (285 loc) · 9.45 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?
/**
* Process.php
*
* The Process class is meant to simplify the task of processing
* user submitted forms, redirecting the user to the correct
* pages if errors are found, or if form is successful, either
* way. Also handles the logout procedure.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 19, 2004
*/
include("include/session.php");
class Process
{
/* Class constructor */
function Process(){
global $session;
/* User submitted login form */
if(isset($_POST['sublogin'])){
$this->procLogin();
}
/* User submitted registration form */
else if(isset($_POST['subjoin'])){
$this->procRegister();
}
/* User submitted forgot password form */
else if(isset($_POST['subforgot'])){
$this->procForgotPass();
}
/* User submitted edit account form */
else if(isset($_POST['subedit'])){
$this->procEditAccount();
}
else if(isset($_POST['subfeedback'])){
$this->procFeedback();
}
/**
* The only other reason user should be directed here
* is if he wants to logout, which means user is
* logged in currently.
*/
else if($session->logged_in){
$this->procLogout();
}
/**
* Should not get here, which means user is viewing this page
* by mistake and therefore is redirected.
*/
else{
header("Location: main.php");
}
}
/**
* procLogin - Processes the user submitted login form, if errors
* are found, the user is redirected to correct the information,
* if not, the user is effectively logged in to the system.
*/
function procLogin(){
global $session, $form;
/* Login attempt */
$retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
/*if( $retval ){
echo 'login was successful';
echo $_SESSION['sessid'];
}
if( $session->logged_in ){
echo 'logged in';
}
else{
echo 'session says not logged in';
}
return;*/
/* Login successful */
if($retval){
/*
if( isset( $_POST['returl']) ){
$returnurl = $_POST['returl'];
header("Location: $returnurl" );
}
else{
header("Location: ".$session->referrer);
}*/
header("Location: copyright.php");
}
/* Login failed */
else{
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
}
/**
* procFeedback - Process and submit the user's
* feedback
*/
function procFeedback(){
global $session, $form;
if(isset($_POST['yvonneused'])){
$usedYvonne = $_POST['yvonneused'];
$yvonnehelpful = "";
if($usedYvonne == 'yes'){
$yvonneuseful = $_POST['yvonneuseful'];
$usedYvonneBool = true;
}
else{//usedYvonne equals 'No'
$usedYvonneBool = false;
$yvonneuseful = "";
}
$retval = $session->feedback( $_POST['vidused'], $_POST['dates'], $_POST['goal'], $_POST['location'],
$_POST['audience'], $_POST['time'], $_POST['length'], $_POST['vidrole'], $_POST['vidhelpful'], $usedYvonneBool, $yvonneuseful,
$_POST['continue']);
}
else{
$form->setError("yvonneused", "* this field is required.");
$retval = 1;
}
/* Registration Successful */
if($retval == 0){
$_SESSION['fbsuccess'] = true;
header("Location: ".$session->referrer);
}
/* Error found with form */
else if($retval == 1){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Registration attempt failed */
else if($retval == 2){
$_SESSION['fbsuccess'] = false;
header("Location: ".$session->referrer);
}
}
/**
* procLogout - Simply attempts to log the user out of the system
* given that there is no logout form to process.
*/
function procLogout(){
global $session;
$retval = $session->logout();
header("Location: main.php");
}
/**
* procRegister - Processes the user submitted registration form,
* if errors are found, the user is redirected to correct the
* information, if not, the user is effectively registered with
* the system and an email is (optionally) sent to the newly
* created user.
*/
function procRegister(){
global $session, $form;
/* Convert username to all lowercase (by option) */
if(ALL_LOWERCASE){
$_POST['user'] = strtolower($_POST['user']);
}
/*iterate through checkbox lists, combining them into one comma separated string */
$subproffull = "";
if( isset( $_POST['prof'] ) ){
$subprof = $_POST['prof'];
//if the checkboxlist isn't null
if(!is_null($subprof)) {
for($i=0; $i < count($subprof); $i++)
{
// add "other" boxes if they were selected
if( $subprof[$i] == "othr" ){
$subproffull .= $_POST["otherexp"].",";
}
else{
$subproffull .= $subprof[$i].",";
}
}
}
}
/* Registration attempt. Calls the register function in include/session.php */
/* Each $_POST value is a normal input except for schtype, prof, and purpose. */
/* Each one of those is an array of checkboxes */
$retval = $session->register($_POST['user'], $_POST['password'], $_POST['passworddup'], $_POST['email'],
$_POST['firstname'], $_POST['lastname'],
$_POST['institutionname'], $_POST['institutioncity'], $_POST['institutionstate'], $subproffull);
/* Registration Successful */
if($retval == 0){
$_SESSION['reguname'] = $_POST['user'];
$_SESSION['regsuccess'] = true;
header("Location: ".$session->referrer);
}
/* Error found with form */
else if($retval == 1){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Registration attempt failed */
else if($retval == 2){
$_SESSION['reguname'] = $_POST['user'];
$_SESSION['regsuccess'] = false;
header("Location: ".$session->referrer);
}
}
/**
* procForgotPass - Validates the given username then if
* everything is fine, a new password is generated and
* emailed to the address the user gave on sign up.
*/
function procForgotPass(){
global $database, $session, $mailer, $form;
/* Username error checking */
$subuser = $_POST['user'];
$field = "user"; //Use field name for username
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, "* Username not entered<br>");
}
else{
/* Make sure username is in database */
$subuser = stripslashes($subuser);
if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
!eregi("^([0-9a-z])+$", $subuser) ||
(!$database->usernameTaken($subuser))){
$form->setError($field, "* Username does not exist<br>");
}
}
/* Errors exist, have user correct them */
if($form->num_errors > 0){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
}
/* Generate new password and email it to user */
else{
/* Generate new password */
$newpass = $session->generateRandStr(8);
/* Get email of user */
$usrinf = $database->getUserInfo($subuser);
$email = $usrinf['email'];
/* Attempt to send the email with new password */
if($mailer->sendNewPass($subuser,$email,$newpass)){
/* Email sent, update database */
$database->updateUserField($subuser, "password", md5($newpass));
$_SESSION['forgotpass'] = true;
}
/* Email failure, do not change password */
else{
$_SESSION['forgotpass'] = false;
}
}
header("Location: ".$session->referrer);
}
/**
* procEditAccount - Attempts to edit the user's account
* information, including the password, which must be verified
* before a change is made.
*/
function procEditAccount(){
global $session, $form;
/* Account edit attempt */
/*iterate through school checkbox list, combining them into one comma separated string */
$subschtypefull = "";
if( isset($_POST['schtype']) ){
$subschtype = $_POST['schtype'];
//if the checkboxlist isn't null
if(!is_null($subschtype)) {
for($i=0; $i < count($subschtype); $i++)
{
$subschtypefull .= $subschtype[$i].",";
}
}
}
$retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['newpassconfirm'],
$_POST['email'], $_POST['firstname'], $_POST['lastname'], $_POST['homecity'], $_POST['homestate'],
$_POST['homezip'], $_POST['workname'], $subschtypefull, $_POST['workcity'], $_POST['workstate'], $_POST['workzip']);
/* Account edit successful */
if($retval){
$_SESSION['useredit'] = true;
header("Location: ".$session->referrer);
}
/* Error found with form */
else{
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
}
};
/* Initialize process */
$process = new Process;
?>