public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / admin / login.php
100644 196 lines (175 sloc) 5.936 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
$CMS_ADMIN_PAGE=1;
 
require_once("../include.php");
require_once("../lib/classes/class.user.inc.php");
 
$error = "";
 
if (isset($_SESSION['logout_user_now']))
  {
    debug_buffer("Logging out. Clearning cookies and session variables.");
    unset($_SESSION['logout_user_now']);
    unset($_SESSION['cms_admin_user_id']);
    setcookie('cms_admin_user_id', '', time() - 3600);
    setcookie('cms_passhash', '', time() - 3600);
  }
 else
   {
     $no_redirect = true;
     $is_logged_in = check_login($no_redirect);
     if (true == $is_logged_in)
       {
   redirect($gCms->config['root_url'].'/'.$config['admin_dir'].'/index.php');
       }
   }
if (isset($_POST["logincancel"]))
{
  debug_buffer("Login cancelled. Returning to content.");
  redirect($config["root_url"].'/index.php', true);
}
 
if (isset($_POST["username"]) && isset($_POST["password"])) {
 
  $username = "";
  if (isset($_POST["username"])) $username = cleanValue($_POST["username"]);
 
  $password = "";
  if (isset($_POST["password"])) $password = $_POST["password"];
 
  $oneuser = UserOperations::LoadUserByUsername($username, $password, true, true);
  
  debug_buffer("Got user by username");
  debug_buffer($oneuser);
 
  if ($username != "" && $password != "" && isset($oneuser) && $oneuser == true && isset($_POST["loginsubmit"]))
  {
    debug_buffer("Starting login procedure. Setting userid so that other pages will pick it up and set a cookie.");
    #generate_user_object($oneuser->id);
    $_SESSION['login_user_id'] = $oneuser->id;
    $default_cms_lang = get_preference($oneuser->id, 'default_cms_language');
    if ($default_cms_lang != '')
    {
      #setcookie('cms_language', $default_cms_lang);
      $_SESSION['login_cms_language'] = $default_cms_lang;
    }
    audit(-1, '', 'User Login');
 
    #Perform the login_post callback TODO: Remove me
    foreach($gCms->modules as $key=>$value)
    {
      if ($gCms->modules[$key]['installed'] == true &&
        $gCms->modules[$key]['active'] == true)
      {
        $gCms->modules[$key]['object']->LoginPost($oneuser);
      }
    }
    
    #Now call the event
    Events::SendEvent('Core', 'LoginPost', array('user' => &$oneuser));
 
    // redirect to upgrade if db_schema it's old
    $current_version = $CMS_SCHEMA_VERSION;
  
    $query = "SELECT version from ".cms_db_prefix()."version";
    $row = $db->GetRow($query);
    if ($row) $current_version = $row["version"];
 
    if ($current_version < $CMS_SCHEMA_VERSION)
    {
      redirect($gCms->config['root_url'] . "/install/upgrade.php");
    }
    // end of version check
 
    if (isset($_SESSION["redirect_url"]))
    {
      if (isset($gCms->config) and $gCms->config['debug'] == true)
      {
        echo "Debug is on. Redirecting disabled... Please click this link to continue.<br />";
        echo "<a href=\"".$_SESSION["redirect_url"]."\">".$_SESSION["redirect_url"]."</a><br />";
        global $sql_queries;
        if (isset($sql_queries))
        {
          echo $sql_queries;
        }
        foreach ($gCms->errors as $globalerror)
        {
          echo $globalerror;
        }
      }
      else
      {
        #echo ('<html><head><title>Logging in... please wait</title><meta http-equiv="refresh" content="1; url='.$_SESSION["redirect_url"].'"></head><body>Logging in and redirecting to <a href="'.$_SESSION["redirect_url"].'">'.$_SESSION["redirect_url"].'</a>, one moment please...</body></html>');
        $tmp = $_SESSION["redirect_url"];
        unset($_SESSION["redirect_url"]);
        redirect($tmp);
      }
      unset($_SESSION["redirect_url"]);
    }
    else
    {
      if (isset($config) and $config['debug'] == true)
      {
        echo "Debug is on. Redirecting disabled... Please click this link to continue.<br />";
        echo "<a href=\"index.php\">index.php</a><br />";
        global $sql_queries;
        if (isset($sql_queries))
        {
          echo $sql_queries;
        }
        foreach ($gCms->errors as $globalerror)
        {
          echo $globalerror;
        }
      }
      else
      {
        #echo ('<html><head><title>Logging in... please wait</title><meta http-equiv="refresh" content="1; url=./index.php"></head><body>Logging in and redirecting to <a href="./index.php">index.php</a>, one moment please...</body></html>');
        redirect("index.php");
      }
    }
    return;
    #redirect("index.php");
  }
  else if (isset($_POST['loginsubmit'])) { //No error if changing languages
    $error .= lang('usernameincorrect');
    debug_buffer("Login failed. Error is: " . $error);
  }
  else
  {
    debug_buffer($_POST["loginsubmit"]);
  }
 
}
 
// Language shizzle
//header("Content-Encoding: " . get_encoding());
header("Content-Language: " . $current_language);
header("Content-Type: text/html; charset=" . get_encoding());
 
//CHANGED
$theme=get_site_preference('logintheme', 'default');
//echo "theme:$theme";
debug_buffer('debug is:' . $error);
if (file_exists(dirname(__FILE__)."/themes/$theme/login.php")) {
  include(dirname(__FILE__)."/themes/$theme/login.php");
} else {
  include(dirname(__FILE__)."/themes/default/login.php");
}
//STOP
?>
 
<?php
  if (isset($gCms->config) and $gCms->config['debug'] == true)
  {
    global $sql_queries;
    if (isset($sql_queries))
    {
      echo $sql_queries;
    }
    foreach ($gCms->errors as $globalerror)
    {
      echo $globalerror;
    }
  }
# vim:ts=4 sw=4 noet
?>