/
welcome.php
120 lines (107 loc) · 3.5 KB
/
welcome.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
<?php
$p=LPC_Page::getCurrent();
$p->title=_LS('lpcAuthRecoverTitle');
if (LPC_User::getCurrent(true)) {
$p->st();
$p->a(new LPC_HTML_error(_LH('lpcAuthErrAlreadyLoggedOn')));
return;
}
$u=LPC_User::newUser();
$us=$u->search(array($u->user_fields['email'],$u->user_fields['token']),array($_REQUEST['e'],$_REQUEST['t']));
if (!$us || $us[0]->getAttr($u->user_fields['token_date'])<time()) {
$p->a(new LPC_HTML_error(_LH('lpcAuthInvalidToken')));
return;
}
$u=$us[0];
if ($u->getAttr($u->user_fields['password']))
$p->title=_LS('lpcAuthResetPasswordTitle');
else
$p->title=_LS('lpcAuthCreatePasswordTitle');
$p->st();
if (isset($_POST['reset_password']) && $_POST['reset_password']) {
$u->resetToken();
if ($u->save()) {
$p->a(new LPC_HTML_confirm(_LH('lpcAuthDoneCancel')));
return;
}
}
if (isset($_POST['process_password'])) {
if ($error=$u->passwordProblems($_POST['pwd'],$_POST['pwd2'])) {
$p->a(new LPC_HTML_error($error));
} else {
$u->load();
$u->setAttr($u->user_fields['password'],$u->saltPassword($_POST['pwd']));
$u->resetToken();
$u->save();
LPC_User::setCurrent($u);
$p->a(new LPC_HTML_confirm(_LH('lpcAuthDoneResetConfirm',$u->getAttrH($u->user_fields['user']))));
if ($u->includeAfterReset)
include $u->includeAfterReset;
return;
}
}
$form=new LPC_HTML_node('form');
$form->setAttr('method','post');
$form->setAttr('action',$_SERVER['PHP_SELF']);
$p->a($form);
$info=new LPC_HTML_node('div');
if ($u->getAttr($u->user_fields['password'])) {
$info->a(_LH('lpcAuthResetFormInfo',_LS('lpcAuthCancelResetButton')));
$reset="<input type='button' name='reset' value='"._LS('lpcAuthCancelResetButton')."' onClick='document.forms[0].reset_password.value=1; document.forms[0].submit()'>";
$label=_LS('lpcAuthResetPasswordButton');
} else {
$info->a(_LH('lpcAuthCreatePasswordFormInfo'));
$reset=" ";
$label=_LS('lpcAuthCreatePasswordLabel');
}
$info->a(<<<EOINFO
<input type='hidden' name='e' value="{$_REQUEST['e']}">
<input type='hidden' name='t' value="{$_REQUEST['t']}">
<input type='hidden' name='reset_password' value="0">
EOINFO
);
$form->a($info);
$table=new LPC_HTML_node('table');
$table->setAttr('class','default');
$table->setAttr('style','margin-top: 10px');
$form->a($table);
$table->a("
<tr>
<th>"._LH('lpcAuthPassword')."<br><small>"._LH('lpcAuthPasswordFieldExplain')."</small></th>
<td><input type='password' name='pwd' id='pwd'></td>
<td rowspan='3' style='width: 500px; padding: 10px'>
<h2>"._LH('lpcAuthValidConditionsTitle')."</h2>".
validation_conditions().
"
</td>
</tr>
<tr>
<th>"._LH('lpcAuthPasswordConfirm')."<br><small>"._LH('lpcAuthPasswordConfirmExplain')."</small></th>
<td><input type='password' name='pwd2'></td>
</tr>
<tr>
<th style='text-align: center'>$reset</th>
<td style='text-align: center'><input type='submit' name='process_password' value='$label'></td>
</tr>
");
$p->a("<script type='text/javascript'>document.getElementById('pwd').focus();</script>");
function validation_conditions()
{
$u=LPC_User::newUser();
$conds=array();
$conds[]=_LH('lpcAuthValidCondMinLength',$u->password_conditions['min_length']);
if ($u->password_conditions['need_alpha'])
$conds[]=_LH('lpcAuthValidCondAlpha');
if ($u->password_conditions['need_numeric'])
$conds[]=_LH('lpcAuthValidCondNumeric');
return "<ul><li>".implode($conds,"</li><li>")."</li></ul>";
}
function error($message)
{
$e=new LPC_HTML_node('div');
$e->setAttr('class','error');
$e->setAttr('style','font-weight: normal');
$e->a("<big><b>EROARE</b></big><br>");
$e->a($message);
return $e;
}