forked from GeniXCMS/GeniXCMS
/
login.php
167 lines (153 loc) · 4.23 KB
/
login.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* GeniXCMS - Content Management System
*
* PHP Based Content Management System and Framework
*
* @package GeniXCMS
* @since 0.0.1 build date 20140928
* @version 0.0.6
* @link https://github.com/semplon/GeniXCMS
* @link http://genixcms.org
* @author Puguh Wijayanto (www.metalgenix.com)
* @copyright 2014-2015 Puguh Wijayanto
* @license http://www.opensource.org/licenses/mit-license.php MIT
*
*/
define('GX_PATH', realpath(__DIR__ . '/'));
define('GX_LIB', GX_PATH.'/inc/lib/');
define('GX_MOD', GX_PATH.'/inc/mod/');
define('GX_THEME', GX_PATH.'/inc/themes/');
define('GX_ASSET', GX_PATH.'/assets/');
require("autoload.php");
try {
new System();
} catch (Exception $e) {
echo $e->getMessage();
}
Session::start();
System::gZip();
if(isset($_POST['login']))
{
if (!isset($_POST['token']) || !Token::isExist($_POST['token'])) {
// VALIDATE ALL
$alertred[] = TOKEN_NOT_EXIST;
}
if (Xaptcha::isEnable()) {
if (!isset($_POST['g-recaptcha-response']) || $_POST['g-recaptcha-response'] == '' ) {
$alertred[] = "Please insert the Captcha";
}
if (!Xaptcha::verify($_POST['g-recaptcha-response'])) {
$alertred[] = "Your Captcha is not correct.";
}
}
if (!isset($alertred)) {
# code...
/*check if username is exist or not */
$username = Typo::cleanX(Typo::strip($_POST['username']));
$sql = sprintf("SELECT `userid`,`status`,`activation` FROM `user` WHERE `userid` = '%s'", $username);
$usr = Db::result($sql);
$c = Db::$num_rows;
//echo $c;
//print_r($usr);
if($c == "1"){
//$alertgreen = "";
// check if user is active
if($usr[0]->status == '1') {
/* get user password */
$pass = User::randpass($_POST['password']);
$sql = "SELECT `pass`,`group` FROM `user` WHERE `userid` = '{$username}'";
$l = Db::result($sql);
$c = Db::$num_rows;
foreach ($l as $v) {
# code...
//print_r($v);
$p = $v->pass;
$g = $v->group;
}
//echo $p;
if($p == $pass){
$vars = array(
'username' => $username,
'loggedin' => true,
'group' => $g
);
Session::set_session($vars);
/*
$_SESSION['username'] = $_POST['username'];
$_SESSION['login'] = "true";
$_SESSION['group'] = $group;
*/
//print_r($_SESSION);
$alertgreen = MSG_USER_LOGGED_IN;
echo Hooks::run('user_login_action');
}elseif($p != $pass){
$alertred[] = PASS_NOT_MATCH;
}
}else{
if($usr[0]->activation != ''){
$alertred[] = ACOUNT_NOT_ACTIVE;
}else{
$alertred[] = ACOUNT_NOT_ACTIVE_BLOCK;
}
}
}elseif($c == "0"){
$alertred[] = NO_USER;
}
}
}
Theme::theme('header');
echo "<div class=\"container\">";
if(isset($alertred)) {
echo "
<div class=\"alert alert-danger\">
<ul>
";
foreach($alertred as $alert)
{
echo "<li>".$alert."</li>";
}
echo"</ul>
</div>";
}
if(isset($alertgreen)) {
echo "
<div class=\"alert alert-success\">
{$alertgreen}
</div>";
}
if(!User::is_loggedin()){
?>
<div style="max-width: 302px; margin-left: auto; margin-right: auto; margin-top: 20px; margin-bottom: 60px ">
<form class="form-signin" role="form" method="post">
<h2 class="form-signin-heading"><?=LOGIN_TITLE;?></h2>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" name="username" class="form-control" placeholder="<?=USERNAME;?>" required autofocus>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-key"></i></span>
<input type="password" name="password" class="form-control" placeholder="<?=PASSWORD;?>" required>
</div>
</div>
<?=Xaptcha::html();?>
<label class="checkbox">
<a href="forgotpassword.php"><?=FORGOT_PASS;?></a>
</label>
<input type="hidden" name="token" value="<?=TOKEN;?>">
<button class="btn btn-lg btn-success btn-block" name="login" type="submit">
<i class="fa fa-sign-in"></i> <?=SIGN_IN;?>
</button>
</form>
</div>
<?php
}else {
echo"<div class=\"alert alert-info\">".MSG_USER_ALREADY_LOGGED."<br /><a href=\"logout.php\">".LOGOUT."</a></div>";
}
echo "</div>";
Theme::theme('footer');
System::Zipped();
?>