forked from exflickr/flamework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccount_password.php
82 lines (54 loc) · 1.3 KB
/
account_password.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
<?
#
# $Id$
#
include("include/init.php");
login_ensure_loggedin();
#
# crumb key
#
$crumb_key = 'account_password';
$smarty->assign("crumb_key", $crumb_key);
#
# update?
#
if (post_str('change') && crumb_check($crumb_key)){
$old_pass = trim(post_str('old_password'));
$new_pass1 = trim(post_str('new_password1'));
$new_pass2 = trim(post_str('new_password2'));
$ok = 1;
if (login_encrypt_password($old_pass) !== $GLOBALS['cfg']['user']['password']){
$smarty->assign('error_oldpass_mismatch', 1);
$ok = 0;
}
if ($ok && $new_pass1 !== $new_pass2){
$smarty->assign('error_newpass_mismatch', 1);
$ok = 0;
}
if ($ok && !strlen($new_pass2)){
$smarty->assign('error_newpass_empty', 1);
$ok = 0;
}
if ($ok){
$rsp = users_update_password($GLOBALS['cfg']['user'], $new_pass1);
if (! $rsp['ok']){
$smarty->assign('error_fail', 1);
$ok = 0;
}
}
if ($ok){
#
# Refresh the user so that we pick up the newer password when
# we set new cookies. Should this be a function in lib_users?
# (20101012/asc)
#
$GLOBALS['cfg']['user'] = users_get_by_id($GLOBALS['cfg']['user']['id']);
login_do_login($GLOBALS['cfg']['user'], "/account/?password=1");
exit;
}
}
#
# output
#
$smarty->display("page_account_password.txt");
?>