/
index.php
121 lines (67 loc) · 1.98 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
110
111
112
113
114
115
116
117
118
119
120
121
<?php defined('SYSPATH') or die('No direct script access.');
require MODPATH.'admin'.EXT;
require SMARTY.'Smarty.class'.EXT;
require MODPATH.'admin.captcha'.EXT;
$smarty=new Smarty();
session_start();
$route= RouteFactory::intance()->set('');
$error_msg= '';
if (isset($route['action'])){
if ($route['action']=='logout'){
session_destroy();
$home_url = '/admin';
header('Location: '.$home_url);
}
}
if (isset($_SESSION['user'])) {
$template_dir = TEMPLATES.'templates'.DIRECTORY_SEPARATOR.'admin';
$smarty->template_dir = $template_dir;
$smarty->assign(AdminFactory::intance()->getData(''));
$smarty->assign (array(
'links'=>array(),
'scripts'=>array()
));
$smarty->assign(array('caption'=>'后台管理平台'));
$smarty->display('index.tpl');
}
else
{
if ($_POST){
$captcha = trim($_POST['validateCode']);
if (empty($captcha))
$error_msg = '请输入验证码.';
else
{
$isdo= strtoupper($captcha) == strtoupper($_SESSION['captcha']);
if ($isdo){
$user_username = trim($_POST['username']);
$user_password = trim($_POST['password']);
if(!empty($user_username)&&!empty($user_password)){
if (Model_Admin_Login::intance($user_username, $user_password)->login()) {
$_SESSION['user']=$user_username;
unset($_SESSION['captcha']);
$home_url = '/admin';
header('Location: '.$home_url);
}else{
$error_msg = '用户名或密码错误';
}
}else{
$error_msg = '用户名或密码不能为空.';
}
}
else
{
$error_msg = '验证码不正确.';
}
}
}
$template_dir = TEMPLATES.'templates'.DIRECTORY_SEPARATOR.'admin';
$smarty->template_dir = $template_dir;
//$path= file_get_contents(SimpleCaptcha::instance()->CreateImage());
//$path= file_get_contents('./admin/captcha/index');
//$captcha= base64_encode($path);
$smarty->assign(array('error'=>$error_msg));
$smarty->assign(array('caption'=>'login'));
$smarty->display('login.tpl');
}
?>