/
secret_question.php
53 lines (45 loc) · 1.09 KB
/
secret_question.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
<?php
require_once 'support/config.php';
if(!isLoggedIn()){
toLogin();
die();
}
if(!empty($_POST))
if(empty($_GET['from'])){
$redirect="index.php";
$error_redirect="index.php";
}
else{
switch ($_GET['from']) {
case 'login':
$redirect='index.php';
$error_redirect="first_login.php";
break;
case 'form':
$redirect='change_secret_password.php';
$error_redirect="change_secret_password.php";
break;
}
$inputs=$_POST;
$inputs=array_map('trim', $inputs);
$errors="";
if (empty($inputs['password_question'])){
$errors.="Enter secret question. <br/>";
}
if (empty($inputs['password_answer'])){
$errors.="Enter answer. <br/>";
}
if($errors!=""){
Alert("You have the following errors: <br/>".$errors,"danger");
redirect($error_redirect);
die;
}
else{
$inputs['id']=$_SESSION[WEBAPP]['user']['id'];
$con->myQuery("UPDATE users SET password_answer=:password_answer,password_question=:password_question WHERE id=:id",$inputs);
Alert("Secret question and answer saved.","success");
redirect($redirect);
}
die;
}
?>