/
index.php
109 lines (89 loc) · 3.33 KB
/
index.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
<?php
require(dirname(__FILE__) . '/../../includes/prepend.inc.php');
class PublicLoginForm extends ChmsForm {
protected $lblMessage;
protected $txtUsername;
protected $txtPassword;
protected $chkRemember;
protected $btnLogin;
protected $strPageTitle = 'Log In';
protected function Form_Run() {
if (QApplication::$PublicLogin && QApplication::$PublicLogin->Person) {
QApplication::Redirect('/main/');
}
QApplication::PublicLogout(false);
}
protected function Form_Create() {
$this->lblMessage = new QLabel($this);
switch (QApplication::PathInfo(0)) {
case 1:
$this->lblMessage->Text = 'You have successfully logged out.';
break;
case 2:
$this->lblMessage->Text = 'You have requested a page that requires a login. Please log in.';
break;
default:
$this->lblMessage->Text = 'Please Log In';
break;
}
$this->txtUsername = new QTextBox($this);
$this->txtUsername->Name = 'Username';
$this->txtPassword = new QTextBox($this);
$this->txtPassword->Name = 'Password';
$this->txtPassword->TextMode = QTextMode::Password;
$this->txtPassword->Required = true;
$this->txtPassword->CausesValidation = true;
$this->chkRemember = new QCheckBox($this);
$this->chkRemember->Name = 'Remember Login';
$this->chkRemember->Text = 'Check this box to remember your username for two weeks';
$this->btnLogin = new QButton($this);
$this->btnLogin->Text = 'Login';
$this->btnLogin->CausesValidation = true;
$this->txtUsername->AddAction(new QEnterKeyEvent(), new QFocusControlAction($this->txtPassword));
$this->txtUsername->AddAction(new QEnterKeyEvent(), new QTerminateAction());
$this->txtPassword->AddAction(new QEnterKeyEvent(), new QServerAction('btnLogin_Click'));
$this->txtPassword->AddAction(new QEnterKeyEvent(), new QTerminateAction());
$this->btnLogin->AddAction(new QClickEvent(), new QServerAction('btnLogin_Click'));
// Final Setup based on whether or not we are "remembering" the username
if (array_key_exists('username', $_COOKIE)) {
$this->txtUsername->Text = $_COOKIE['username'];
$this->txtPassword->Focus();
$this->chkRemember->Checked = true;
} else {
$this->txtUsername->Focus();
}
}
protected function Form_Validate() {
$blnToReturn = true;
$blnFirst = true;
foreach ($this->GetErrorControls() as $objControl) {
if ($blnFirst) {
$blnFirst = false;
$objControl->Focus();
}
$objControl->Blink();
}
return $blnToReturn;
}
protected function btnLogin_Click($strFormId, $strControlId, $strParameter) {
$objLogin = PublicLogin::LoadByUsernamePassword(trim(strtolower($this->txtUsername->Text)), $this->txtPassword->Text);
if (!$objLogin || !$objLogin->IsAllowedToUseChms()) {
$this->lblMessage->Text = 'Invalid username or password.';
$this->txtUsername->Blink();
$this->txtPassword->Blink();
$this->txtUsername->Focus();
return;
}
if ($this->chkRemember->Checked) {
setcookie('username', $objLogin->Username, time() + 60*60*24*14, '/', null);
} else {
setcookie('username', null, 1, '/', null);
}
QApplication::PublicLogin($objLogin);
if ($objLogin->TemporaryPasswordFlag) {
QApplication::Redirect('/update_password.php');
} else QApplication::RedirectOnPublicLogin();
}
}
PublicLoginForm::Run('PublicLoginForm');
?>