Index.php
3.43 KB
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
<?php
class IndexController extends QLib_Actions_Login
{
public function indexAction()
{
$this->_sessionNamespace('adminx_profile')->unsetAll();
$this->_assign('refer', $this->_get('refer'));
Adminx_Models_Profile_Client::getRoleByProfile(1);
}
public function loginAction()
{
$this->disableView();
$username = trim($this->_post('username'));
$inputPassword = trim($this->_post('password'));
$refer = trim($this->_post('refer'));
if (empty($username) || empty($inputPassword)) {
$this->helpLocation('账号和密码不能为空.', '/');
}
$profile = Adminx_Models_Profile_Client::getProfileByUsername($username);
if (empty($profile)) {
$this->helpLocation('账号不存在或者被禁用.', '/');
}
if ((int)$profile['status'] === 0) {
$this->helpLocation('账号已关闭.', '/');
}
$loginExpires = QLibConfigs_GlobalConfig::$login_expires_day * 86400;
if ((int)$profile['login_time'] + $loginExpires < time()) {
$this->helpLocation('你的账号已经 ' . QLibConfigs_GlobalConfig::$login_expires_day . ' 天未登录,账号被冻结,请联系管理员.', '/');
}
if ($profile['is_lock'] == 'Y') {
$this->helpLocation('账号已锁定请联系管理员.', '/');
}
if ((int)$profile['expires'] < time()) {
$this->helpLocation('账号已过期请联系管理员.', '/');
}
#############################################
$cache = Q_Cache::factory('Memcached')->setPrefix('adminx' . '.' . 'profile');
#############################################
$logKey = 'adminx_login_' . $profile['pid'];
$password = $profile['password'];
$authPass = Q_Utils_AuthCode::authPassword(QLibConfigs_GlobalConfig::confusionPassword($inputPassword), $password);
if (empty($authPass)) {
$cache->increment($logKey) == false ? $cache->set($logKey, 1) : true;
if ($cache->get($logKey) > 3) {
Adminx_Models_Profile_Client::updateProfileLockByPid($profile['pid']);
}
$this->helpLocation('密码错误.', '/');
}
################################### BEGIN SET COOKIE ###############################################
$profile['signin_time'] = time();
$profile['token'] = uniqid();
Adminx_Models_Profile_Client::updateLoginTime($profile['pid']);
$cookieDataKey = Q_Utils_AuthCode::encode(json_encode($profile), QLibConfigs_GlobalConfig::$cookie_key);
Q_Core_Cookie::setCookie(QLibConfigs_GlobalConfig::$cookie_name, QLibConfigs_GlobalConfig::$domain, $cookieDataKey, 0, '/', true, false);
################################### END SET COOKIE #################################################
################################### BEGIN SET SESSION ##############################################
$this->_sessionNamespace('adminx_profile')->unsetAll();
$this->_sessionNamespace('adminx_profile')->__set(QLibConfigs_GlobalConfig::$session_name, $profile);
$this->_sessionNamespace('adminx_profile')->__set(QLibConfigs_GlobalConfig::$token_name, $profile['token']);
################################### END SET SESSION ################################################
$this->helpGo(empty($refer) ? '/console.html' : $refer);
}
}