This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
create_account.php
executable file
·195 lines (180 loc) · 11 KB
/
create_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
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
<?php
/**
* This page serves to create an account for a user and train the system
* to recognize that user's typing patterns.
*
* Note that we display a very different page depending on the contents of the $_POST array.
*/
?>
<!DOCTYPE HTML>
<html>
<?php
$title = "Create an Account";
include( 'components/head.php' );
include_once( 'components/database_fns.php' );
include_once( 'components/site_variables.php' );
include_once( 'components/authentication_wrappers.php' );
?>
<body data-spy="scroll" data-target=".subnav" data-offset="50">
<?php include( 'components/top_menu.php' ); ?>
<div class="container">
<!-- Masthead
================================================== -->
<?php include( 'components/branding.php' ); ?>
<section>
<?php
$totalStepsInTraining = constant( "NUM_TRAINING_EXAMPLES" ) + 1;
// If we don't have all the POST data that indicates the user has
// already typed their info once . . .
if( !( isset($_POST['timingData']) && isset($_POST['nonce']) ) ) {
// If the user is creating an account, we have to first log them out
logout();
// Display the Create Account page
?>
<h2>Create an Account</h2>
<div class="progress">
<div class="bar" style="width: <?php echo (1/$totalStepsInTraining)*100; ?>%;">1 of <?php echo $totalStepsInTraining; ?></div>
</div>
<p>Please choose a user name and password with which we can identify your account.</p>
<form class="form-horizontal" name="formCreate" id="formCreate" action="<?php echo TRAINING_PAGE; ?>" method="post" autocomplete="off">
<div class="control-group">
<label class="control-label" for="userName">User name:</label>
<div class="controls">
<input type="text" id="userName" name="user" placeholder="User name" autocomplete="off">
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">Password:</label>
<div class="controls">
<input type="password" id="password" name="pwd" placeholder="************" autocomplete="off">
</div>
</div>
<div class="control-group">
<label class="control-label" for="passwordRepeat">Repeat password:</label>
<div class="controls">
<input type="password" id="passwordRepeat" name="pwdRepeat" placeholder="************" autocomplete="off">
</div>
</div>
<div class="control-group">
<label class="control-label" for="captcha">Captcha:</label>
<div class="controls">
<?php
$captcha = getCaptcha();
?>
<input type="text" id="captcha" name="captcha" placeholder="Type indicated captcha here" autocomplete="off">
<span class="help-inline" id="captchaHelp">Type <strong><?php echo $captcha ?></strong> here to prove you are a human.</span>
</div>
</div>
<input type="hidden" id="timingData" name="timingData" />
<input type="hidden" id="timingDataCaptcha" name="timingDataCaptcha" />
<?php $nonceType = "create" . strval(time()); ?>
<input type="hidden" id="nonce" name="nonce" value="<?php echo ulNonce::Create($nonceType); ?>">
<input type="hidden" name="nonceType" value="<?php echo $nonceType; ?>">
<input type="hidden" name="captchaNonce" value="<?php echo ulNonce::Create($captcha); ?>">
<input type="hidden" id="iteration" name="iteration" value="2"/>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Create Account</button>
</div>
</div>
</form>
<?php
} else { // We have all the required data
/*if( isset($_POST['timingDataCaptcha']) ) {
echo "<p>Got captcha timing!: " . $_POST['timingDataCaptcha'] . "</p>";
}
if( isset($_POST['timingData'])) {
echo "<p>Got normal timing!: " . $_POST['timingData'] . "</p>";;
}*/
//echo "<pre>", print_r($_POST, true), "</pre>";
// If we haven't already logged the user in, we need to
// create the account in the database and log them in
if( !userIsLoggedIn()
&& strlen($_POST['timingDataCaptcha']) > 0
&& strlen($_POST['timingData']) > 0 ) {
$accountCreationSucceeded = createUser( $ulogin, $_POST['user'], $_POST['pwd'] );
if ( !$accountCreationSucceeded ) {
// Display a failure message
echo '<h2 class="alert-error">Account creation failure.</h2>';
if( userExists($_POST['user']) ) {
echo "<p>Sorry, the user name <strong>",$_POST['user'],"</strong> is already in use.</p>";
} else {
echo "<p>Sorry, there was an internal error.</p>";
}
// @TODO: Not safe to exit here!
exit();
}
}
if( userIsLoggedIn() ) {
// Validate the captcha
if( !captchaIsValid($_POST['captcha']) ) {
echo "<p>Captcha text did not match!</p>";
return false;
}
// Set up our variables
$userName = $_SESSION['username'];
$i = intval(cleanseSQLAndHTML( $_POST['iteration'] ));
// Store previous submission's data in the DB
//echo "<pre>", print_r($_SESSION), "</pre>";
storeTrainingData( $_SESSION['uid'], $_SESSION['username'], $_POST['timingData'] );
storeNegativeTrainingData( getUserID($_POST['captcha']), $_SESSION['uid'], $_POST['captcha'],
$_POST['timingDataCaptcha'] )
?>
<h2>Train our system to recognize you</h2>
<div class="progress">
<div class="bar" style="width: <?php echo ($i/$totalStepsInTraining)*100; ?>%;">Step <?php echo $i; ?> of <?php echo $totalStepsInTraining ?></div>
</div>
<p>You said your key phrase should be <strong><?php echo $userName;?></strong>.</p>
<p>Please type your phrase in the box below.</p>
<?php
// Set up the form variables
$submitTo = $_SERVER['PHP_SELF'];
if( $i >= $totalStepsInTraining ) {
$submitTo = POST_TRAINING_PAGE;
}
?>
<form class="form-horizontal" name="formTrain" id="formTrain" action="<?php echo $submitTo; ?>" method="post">
<div class="control-group">
<label class="control-label" for="userName">User name:</label>
<div class="controls">
<input type="text" id="userName" name="user" placeholder="<?php echo $_SESSION['username']; ?>">
<span class="help-inline" id="userNameHelp">Retype your user name so we can train our identifier.</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="captcha">Captcha:</label>
<div class="controls">
<?php
$captcha = getCaptcha($_SESSION['uid']);
?>
<input type="text" id="captcha" name="captcha" placeholder="Type indicated captcha here" autocomplete="off">
<span class="help-inline" id="captchaHelp">Type <strong><?php echo $captcha ?></strong> here to prove you are a human.</span>
</div>
</div>
<input type="hidden" id="timingData" name="timingData" />
<input type="hidden" id="timingDataCaptcha" name="timingDataCaptcha" />
<?php $nonceType = "train" . strval($i); ?>
<input type="hidden" id="nonce" name="nonce" value="<?php echo ulNonce::Create($nonceType);?>">
<input type="hidden" name="nonceType" value="<?php echo $nonceType; ?>">
<input type="hidden" name="captchaNonce" value="<?php echo ulNonce::Create($captcha); ?>">
<input type="hidden" id="iteration" name="iteration" value="<?php echo intval($i + 1); ?>"/>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary"><?php echo ($i < $totalStepsInTraining ? "Next" : "Finish training"); ?></button>
</div>
</div>
</form>
<?php
} else { // Failed to log the user in; account creation may have failed
echo "<p>Error creating account. Please try again.</p>";
}
}
?>
</section>
<?php
/*echo "<p>User is logged in? ", ( userIsLoggedIn() ? "Yes" : "No" ),"</p>",
"<p>", "User ID: ", $_SESSION['username'],"</p>"; */?>
</div><!-- container -->
<?php include( 'components/footer.php' ); ?>
</body>
</html>