2 require('includes/header.php');
3 update_activity('restore_id');
4 $page_title = 'Restore ID';
5 $onload_javascript = 'focusId(\'memorable_name\')';
7 // If an ID card was uploaded...
8 if(isset($_POST['do_upload']))
10 list($uid, $password) = file($_FILES['id_card']['tmp_name'], FILE_IGNORE_NEW_LINES
);
12 // ... or an ID and password was inputted...
13 else if(!empty($_POST['UID']) && !empty($_POST['password']))
16 $password = $_POST['password'];
18 // ...or a link from a recovery e-mail is being used...
19 else if(!empty($_GET['UID']) && !empty($_GET['password']))
22 $password = $_GET['password'];
24 // ... or a memorable name was inputted ...
25 else if(!empty($_POST['memorable_name']))
27 $stmt = $link->prepare('SELECT user_settings.uid, users.password FROM user_settings INNER JOIN users ON user_settings.uid = users.uid WHERE LOWER(user_settings.memorable_name) = LOWER(?) AND user_settings.memorable_password = ?');
28 $stmt->bind_param('ss', $_POST['memorable_name'], $_POST['memorable_password']);
30 $stmt->bind_result($uid, $password);
36 add_error('Your memorable information was incorrect.');
42 $stmt = $link->prepare('SELECT password FROM users WHERE uid = ?');
43 $stmt->bind_param('s', $uid);
45 $stmt->bind_result($db_password);
49 if(empty($db_password))
51 add_error('There is no such UID.');
53 else if($password != $db_password)
55 add_error('Incorrect password.');
58 $_SESSION['UID'] = $uid;
59 $_SESSION['ID_activated'] = true;
60 setcookie('UID', $uid, $_SERVER['REQUEST_TIME'] +
315569260, '/');
61 setcookie('password', $password, $_SERVER['REQUEST_TIME'] +
315569260, '/');
63 $stmt = $link->prepare('SELECT spoiler_mode, topics_mode, ostrich_mode, snippet_length FROM user_settings WHERE uid = ?');
64 $stmt->bind_param('s', $uid);
66 $stmt->bind_result($user_config['spoiler_mode'], $user_config['topics_mode'], $user_config['ostrich_mode'], $user_config['snippet_length']);
70 foreach($user_config as $key => $value)
74 setcookie($key, $value, $_SERVER['REQUEST_TIME'] +
315569260, '/');
78 $_SESSION['notice'] = 'Welcome back.';
79 header('Location: ' . DOMAIN
);
89 <p
>Your internal ID can be restored in a number of ways
. If none of these work
, you may be able to
<a href
="/recover_ID_by_email">recover your ID by e
-mail
</a
>.
91 <p
>Here are your options
:</p
>
94 <legend
>Input memorable name
and password
</legend
>
96 <p
>Memorable information can be set from the
<a href
="/dashboard">dashboard
</a
></p
>
98 <form action
="" method
="post">
100 <label
for="memorable_name">Memorable name
</label
>
101 <input type
="text" id
="memorable_name" name
="memorable_name" maxlength
="100" />
104 <label
for="memorable_password">Memorable password
</label
>
105 <input type
="password" id
="memorable_password" name
="memorable_password" />
108 <input type
="submit" value
="Restore" />
115 <legend
>Input UID
and password
</legend
>
117 <p
>Your internal ID
and password are automatically set upon creation of your ID
. They are available from the
<a href
="/back_up_ID">back up
</a
> page
.</p
>
119 <form action
="" method
="post">
121 <label
for="UID">Internal ID
</label
>
122 <input type
="text" id
="UID" name
="UID" size
="23" maxlength
="23" />
125 <label
for="password">Internal password
</label
>
126 <input type
="password" id
="password" name
="password" size
="32" maxlength
="32" />
129 <input type
="submit" value
="Restore" />
136 <legend
>Upload ID card
</legend
>
138 <p
>If you have an
<a href
="/generate_ID_card">ID card
</a
>, upload it here
.</p
>
140 <form enctype
="multipart/form-data" action
="" method
="post">
142 <input name
="id_card" type
="file" />
145 <input name
="do_upload" type
="submit" value
="Upload and restore" />
152 require('includes/footer.php');