CMS  Version 3.9
user_manager.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8  Copyright (c) 2010 Sonjara, Inc
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use,
14  copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following
17  conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  Except as contained in this notice, the name(s) of the above
23  copyright holders shall not be used in advertising or otherwise
24  to promote the sale, use or other dealings in this Software
25  without prior written authorization.
26 
27  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  OTHER DEALINGS IN THE SOFTWARE.
35 
36 *****************************************************************/
37 
50 {
54  function UserManager()
55  {
56  }
57 
62  function getUsernameField()
63  {
64  return "username";
65  }
66 
71  function getEmailField()
72  {
73  return "email";
74  }
75 
80  function getUserClass()
81  {
82  return SiteUser;
83  }
84 
90  function getUser($user_id)
91  {
92  return new SiteUser($user_id);
93  }
94 
101  function getActiveClause()
102  {
103  return "active=true";
104  }
105 
110  function isActive($user)
111  {
112  return $user->active;
113  }
114 
116  {
117  $usernameField = $this->getUsernameField();
118 
119  $matches = Query::create(SiteUser, "WHERE $usernameField=:username")
120  ->bind(":username", $username)
121  ->execute();
122 
123  return (count($matches) > 0) ? $matches[0] : null;
124  }
125 
126 
128  {
129  $emailField = $this->getEmailField();
130 
131  $matches = Query::create(SiteUser, "WHERE $emailField=:email")
132  ->bind(":email", $email)
133  ->execute();
134 
135  return (count($matches) > 0) ? $matches[0] : null;
136  }
137 
143  {
144  return $user->getFullName();
145  }
146 
153  function validatePassword($username, $password)
154  {
155  $user = querySingle(SiteUser, "WHERE username='{$username}' and active=1");
156 
157  if ($user && crypt($_POST["password"], $user->password) === $user->password)
158  {
159  return $user;
160  }
161  else
162  {
163  return null;
164  }
165  }
166 
172  {
173  }
174 
180  {
181  $page = $this->getLoginRedirect($user);
182  redirect($page);
183  }
189  {
190  global $isAdmin;
191  global $_SESSION;
192 
193  $page = $_SESSION["login_redirect"];
194  unset($_SESSION["login_redirect"]);
195 
196  if (!$page || startsWith($page, "components/login"))
197  {
198  $page = ($isAdmin) ? "/admin/index" : SiteRole::getHomePage($user);
199  }
200 
201  return $page;
202  }
203 
209  {
210  return "/password_reset";
211  }
212 
214  {
215  return "If you have an account on this system, please enter your user name or your user email address and we will email a temporary password to you.";
216  }
217 
219  {
220  return "User name or email";
221  }
222 
223  static function deleteRole($del_role)
224  {
225  $constraint = "WHERE role like '%$del_role%'";
226 
227  $mgr = new UserManager();
228  $class = $mgr->getUserClass();
229  $users = Query::create($class, $constraint)->execute();
230 
232 
233  return $del_role;
234  }
235 
236  static function onInitialize()
237  {
238  global $user;
239  if ($user)
240  {
241  MenuManager::setDisplayFlag('logged_in', true);
242  }
243  else
244  {
245  MenuManager::setDisplayFlag('logged_in', false);
246  }
247  }
248 
249  static function upgradeComponent($version)
250  {
251  $mgr = new UserUpgradeManager();
252  $mgr->upgrade($version);
253  }
254 }?>
$constraint
$user_id
$_POST["owner_id"]
Definition: blog_form.inc:54
$page
Definition: help.inc:39
$username
static setDisplayFlag($name, $value=true)
static deleteRoleFromString(&$items, $del_role, $field="")
static getHomePage($account=null)
Definition: role.inc:102
This class maps the site_user table.
Definition: site_user.inc:43
Provides the interface to the user model for the application.
static deleteRole($del_role)
validatePassword($username, $password)
Validates the user's username and password, returning the matching user.
getUserByEmail($email)
loadDefaultSession($user)
Load any supporting information into the user's session after a valid login.
getLoginRedirect($user)
Redirect the user after a valid login.
static upgradeComponent($version)
UserManager()
Creates a new UserManager object.
loginRedirect($user)
Redirect the user after a valid login.
getUserByName($username)
getUsernameField()
Returns the field name of the username in the user model.
isActive($user)
Determine if the specified user account is active.
getEmailField()
Returns the field name of the email field in the user model.
getPasswordResetPage()
Returns the identifier of the password reset page.
static onInitialize()
getActiveClause()
Return a clause that constrains records on those that are active.
getPasswordHelpUserNameLabel()
getUserFullName($user)
Return the user's full name.
getUser($user_id)
Retrieves the user with the specified id.
getUserClass()
Returns the datamodel class name of the user model.
global $user
$_SESSION["useMobile"]
Definition: override.inc:7