forked from exflickr/flamework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset.php
81 lines (54 loc) · 1.37 KB
/
reset.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
<?
#
# $Id$
#
include("include/init.php");
login_ensure_loggedout();
if (! $GLOBALS['cfg']['enable_feature_password_retrieval']){
error_404();
}
$reset_code = post_str('reset');
if (! $reset_code){
$reset_code = get_str('reset');
}
if (! $reset_code){
# seriously, go away...
header("location: /");
exit();
}
$user = users_get_by_password_reset_code($reset_code);
if (! $user){
$GLOBALS['error']['nouser'] = 1;
$smarty->display('page_reset.txt');
exit();
}
$new_reset_code = users_generate_password_reset_code($user);
$smarty->assign('reset_code', $new_reset_code);
if (post_str('reset')){
$new_password1 = post_str('new_password1');
$new_password2 = post_str('new_password2');
if ((! $new_password1) || (! $new_password2)){
$GLOBALS['error']['missing_password'] = 1;
$smarty->display('page_reset.txt');
exit();
}
if ($new_password1 !== $new_password2){
$GLOBALS['error']['password_mismatch'] = 1;
$smarty->display('page_reset.txt');
exit();
}
if (! users_update_password($user, $new_password1)){
$GLOBALS['error']['update_failed'] = 1;
$smarty->display('page_reset.txt');
exit();
}
users_purge_password_reset_codes($user);
$user = users_get_by_id($user['user_id']);
login_do_login($user, "/account/?password=1");
exit();
}
#
# output
#
$smarty->display('page_reset.txt');
?>