/
login.php
276 lines (245 loc) · 9.7 KB
/
login.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
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
<?php
require_once("models/config.php");
//REDIRECT USERS THAT ARE ALREADY LOGGED IN TO THE PORTAL PAGE
if(isUserLoggedIn()) {
$destination = (isUserActive() ? $websiteUrl . "dashboard/index.php" : $websiteUrl . "consent.php");
header("Location: " . $destination);
exit;
}
if(isset($_GET["session_clear"])){
unset($_SESSION[$_CFG->SESSION_NAME]['login_attempts']);
header("Location: " . $websiteUrl . "login.php");
}
unset($_SESSION[SESSION_NAME]['login_attempts']);
$attempts_remaining = (isset($_SESSION[$_CFG->SESSION_NAME]['login_attempts']) ? $_SESSION[$_CFG->SESSION_NAME]['login_attempts'] : 4);
$username_label = "";
$badlogin = "";
//--------------------------------------------------------------------
// Login Posted
if( !empty($_POST) && isset($_POST['new_login']) ) {
$errors = array();
$username = trim($_POST["username"]);
$password = trim($_POST["password"]);
$badlogin = $username;
$use_lang = $_POST["use_lang"];
//Perform some basic validation
if($username == "") $errors[] = lang("ACCOUNT_SPECIFY_USERNAME");
if($password == "") $errors[] = lang("ACCOUNT_SPECIFY_PASSWORD");
if(empty($_POST["username"]) && empty($_POST["password"]) && !empty($_POST["participant_id"])){
array_pop($errors);
array_pop($errors);
$participant_id = trim($_POST["participant_id"]);
$user = getUsernameByParticipantID($participant_id);
$username = $user->username;
$password = md5("somelongthingsurewhynot" + $username);
//use participant ID to get the username
//then use the username and the salt to do the password
//then sign in
}
//End data validation
if(count($errors) == 0) {
// Continue with authentication
$auth = new RedcapAuth($username,$password);
// Valid credentials
if($auth->authenticated_user_id != Null) {
// Log user in
$loggedInUser = new RedcapPortalUser($auth->authenticated_user_id);
//ADD IN LANGUAGE OPTION TO SESSION
$data[] = array(
"record" => $loggedInUser->id,
"field_name" => 'portal_lang',
"value" => $use_lang
);
$projects = SurveysConfig::$projects;
$API_TOKEN = $projects["REDCAP_PORTAL"]["TOKEN"];
$API_URL = $projects["REDCAP_PORTAL"]["URL"];
$result = RC::writeToApi($data, array("overwriteBehavior" => "overwite", "type" => "eav"), $API_URL, $API_TOKEN);
$_SESSION["REDCAP_PORTAL"]['user']->lang = $use_lang;
//CHECK THIS ON EVERY LOGIN? SURE
$supp_proj = SurveysConfig::$projects;
foreach($supp_proj as $proj_name => $project){
if($proj_name == $_CFG->SESSION_NAME){
continue;
}
$supp_id = linkSupplementalProject($project, $loggedInUser);
$loggedInUser->{$proj_name} = $supp_id;
}
unset($_SESSION[SESSION_NAME]['login_attempts']);
setSessionUser($loggedInUser);
//CHECK IF USER AGREED TO CONSENT YET
if(!$loggedInUser->active){
$destination = "consent.php";
}else{
$destination = getSessionRedirectOr($websiteUrl.'dashboard/index.php');
}
header("Location: $destination");
} else { // Invalid credentials
//IF NOT A REGISTERED USER - KEEP EMAIL AND PREFILL ON REGISTER FORM
$attempts_remaining--;
$_SESSION[SESSION_NAME]['login_attempts'] = $attempts_remaining;
if($attempts_remaining < 1){
$errors[] = lang("FORGOTPASS_SUGGEST");
}else{
$errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID") . "<br> ". $lang["ACCOUNT_ERROR_TRY_AGAIN"] . $attempts_remaining . " " . ($attempts_remaining > 1 ? $lang["ACCOUNT_ERROR_ATTEMPTS"] : $lang["ACCOUNT_ERROR_ATTEMPT"]);
}
}
}
// Add errors messages to session
foreach ($errors as $error) {
addSessionAlert($error);
}
}
$disabled = ($attempts_remaining < 1 ? "disabled=disabled" : null);
$username_validation = $portal_config['useEmailAsUsername'] ? "required: true, email: true" : "required: true";
$pg_title = "Login : " .$_CFG->WEBSITE["Name"];
$body_classes = "login";
include("models/inc/gl_header.php");
?>
<div id="content" class="container" role="main" tabindex="0">
<div class="row">
<div id="main-content" class="col-md-8 col-md-offset-2 logpass" role="main">
<?php
include("models/inc/language_select.php");
?>
<div class="well row">
<form id="loginForm" name="loginForm" class="form-horizontal loginForm col-md-6 " action="login.php" method="post" novalidate="novalidate">
<input type="hidden" name="use_lang" value="<?php echo $_SESSION["use_lang"] ?>"/>
<h2><?php echo lang("ACCOUNT_LOGIN_CONTINUE") ?></h2>
<div class="form-group">
<label for="username" class="control-label"><?php echo lang("ACCOUNT_EMAIL_ADDRESS_OR_USERNAME") ?></label>
<input <?php echo $disabled?> type="text" class="form-control" name="username" id="username" placeholder="<?php echo lang("ACCOUNT_EMAIL_ADDRESS_OR_USERNAME") ?>" autofocus="true" aria-required="true" aria-invalid="true" aria-describedby="username-error" value="<?php echo $badlogin?>">
</div>
<div class="form-group">
<label for="password" class="control-label"><?php echo lang("ACCOUNT_PASSWORD") ?></label>
<input <?php echo $disabled?> type="password" class="form-control" name="password" id="password" placeholder="<?php echo lang("ACCOUNT_PASSWORD") ?>" autocomplete="off" >
</div>
<!-- <div class="form-group">
<h3 class="or">OR</h3>
<label for="participant_id" class="control-label"><?php echo lang("ACCOUNT_PARTICIPANT_ID") ?></label>
<input <?php echo $disabled?> type="text" class="form-control" name="participant_id" id="participant_id" placeholder="Login with Participant ID" autofocus="true" aria-required="true" aria-invalid="true" aria-describedby="username-error" value="<?php echo $badlogin?>">
</div> -->
<div class="form-group">
<div class="pull-left">
<a class="showrecover" href="#"><?php echo lang("FORGOTPASS") ?></a> <br>
<a class="showregister" href="register.php"><?php echo lang("REGISTER_STUDY") ?></a>
</div>
<div class="pull-right">
<input <?php echo $disabled?> type="submit" class="btn btn-success" name="new_login" id="newfeedform" value="<?php echo lang("ACCOUNT_LOGIN_NOW") ?>"/>
<span></span>
</div>
</div>
</form>
<form id="pwresetForm" name="newLostPass" class="form-horizontal lostPass col-md-6 " action="forgot_password.php" method="post">
<aside class="stepone">
<h2><?php echo lang("FORGOTPASS_BEGIN_RESET") ?></h2>
<div class="form-group">
<label for="username" class="control-label"><?php echo lang("ACCOUNT_EMAIL_ADDRESS") ?></label>
<input type="text" class="form-control" name="forgotemail" id="forgotemail" placeholder="<?php echo lang("ACCOUNT_EMAIL_ADDRESS") ?>" autofocus value="<?php echo $badlogin?>"/>
</div>
<div class="form-group">
<a class="showlogin pull-left" href="#"><?php echo lang("ACCOUNT_LOGIN_NOW") ?></a>
<button type='submit' class="btn btn-success pull-right nextstep" title="Forgot Password" ><?php echo lang("ACCOUNT_NEXT_STEP") ?></button>
</div>
</aside>
<aside class="steptwo">
<h2><?php echo lang("FORGOTPASS_RECOVERY_METHOD") ?></h2>
<div class="form-group">
<label for="emailme" class="control-label">
<input type="radio" name="resetlink" id="emailme" checked value="emailme"/>
<?php echo lang("FORGOTPASS_EMAIL_ME") ?>
</label>
</div>
<div class="form-group">
<label for="secquestions" class="control-label">
<input type="radio" name="resetlink" id="secquestions" value="secquestions"/>
<?php echo lang("FORGOTPASS_ANSWER_QS") ?>
</label>
</div>
<div class="form-group">
<a class="showlogin pull-left" href="#"><?php echo lang("ACCOUNT_LOGIN_NOW") ?></a>
<input type="submit" class="btn btn-success pull-right " name="new_pass_reset_request" id="newfeedform" value="<?php echo lang("FORGOTPASS") ?>" />
</div>
</aside>
</form>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("#loginForm").submit(function(){
$("input[name='new_login']").addClass("loading");
});
$(".showrecover, .showlogin").click(function(e){
$(".logpass form").hide();
$("#forgotemail").val( $("#username").val() );
if($(this).hasClass("showrecover")){
$(".lostPass").fadeIn("medium");
}else{
$(".loginForm").fadeIn("medium");
}
return false;
});
$(".nextstep").click(function(){
if($("#forgotemail").val()){
$(".logpass form").hide();
$(".stepone").hide();
$(".steptwo").show();
$(".lostPass").fadeIn("medium");
}else{
$("#forgotemail").closest('.form-group').addClass('has-error');
}
return false;
});
$('#pwresetForm').validate({
rules: {
forgotemail: {
required: true
}
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
$('#loginForm').validate({
rules: {
username: {
required: false
},
password: {
required: false
}
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
});
</script>
<?php
include("models/inc/gl_footer.php");
?>