BMLT Root Server
c_comdef_users.class.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************************/
3 /** \file c_comdef_users.class.php
4  \brief The file for the c_comdef_users class.
5 
6  This file is part of the Basic Meeting List Toolbox (BMLT).
7 
8  Find out more at: https://bmlt.app
9 
10  BMLT is free software: you can redistribute it and/or modify
11  it under the terms of the MIT License.
12 
13  BMLT is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  MIT License for more details.
17 
18  You should have received a copy of the MIT License along with this code.
19  If not, see <https://opensource.org/licenses/MIT>.
20 */
21 defined('BMLT_EXEC') or die('Cannot Execute Directly'); // Makes sure that this file is in the correct context.
22 
23 require_once(dirname(__FILE__)."/c_comdef_user.class.php");
24 
25 /***********************************************************************/
26 /** \class c_comdef_users
27  \brief A class to hold a collection of c_comdef_users objects.
28 
29 ***********************************************************************/
30 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
31 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
33 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
34 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
35 {
36  /// This is the parent (container) object that holds this instance.
37  private $_local_id_parent_obj = null;
38 
39  /*******************************************************************/
40  /** We keep a local copy of the simple array, because we can instantly
41  access it, as opposed to having to instantiate iterators.
42  */
43  private $_local_copy_of_array = null;
44 
45  public function __construct(
46  $in_parent_object, ///< A reference to the object that "owns" this instance.
47  $in_user_object_array ///< An array of references to c_comdef_user objects, to be stored as local references.
48  ) {
49  $this->SetParentObj($in_parent_object);
50 
51  foreach ($in_user_object_array as &$obj) {
52  // Who's yer daddy?
53  $obj->SetParentObj($this);
54  }
55 
56  $this->_local_copy_of_array = $in_user_object_array;
57  }
58 
59  /*******************************************************************/
60  /** \brief Set the parent object of this instance.
61  */
62  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
63  public function SetParentObj(
64  $in_parent_obj ///< A reference to the parent object.
65  ) {
66  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
67  $this->_local_id_parent_obj = null;
68  $this->_local_id_parent_obj = $in_parent_obj;
69  }
70 
71  /*******************************************************************/
72  /** \brief Return a reference to the parent object of this instance.
73 
74  \returns a reference to the parent instance of the object.
75  */
76  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
77  public function GetParentObj()
78  {
79  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
80  return $this->_local_id_parent_obj;
81  }
82 
83  /*******************************************************************/
84  /** \brief Accessor -Get the user object array.
85 
86  \returns a reference to an array of c_comdef_user objects.
87  */
88  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
89  public function &GetUsersArray()
90  {
91  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
92  return $this->_local_copy_of_array;
93  }
94 
95  /*******************************************************************/
96  /** \brief Accessor -Get the user object for one user, given an ID.
97 
98  \returns a reference to a c_comdef_user object. Null if none.
99  */
100  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
101  public function &GetUserByID(
102  $in_user_id ///< An integer -The ID of the user.
103  ) {
104  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
105  $ret = null;
106 
107  foreach ($this->_local_copy_of_array as &$user) {
108  if ($in_user_id == $user->GetID()) {
109  $ret = $user;
110  break;
111  }
112  }
113 
114  return $ret;
115  }
116 
117  /*******************************************************************/
118  /** \brief Given a login and password, looks up the user, and returns
119  an encrypted password for that user.
120 
121  \returns a string, with the encrypted password. Null if none.
122  */
123  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
124  public function &GetEncryptedPW(
125  $in_login, ///< A string. The login ID.
126  $in_password ///< A string. the UNENCRYPTED password for the user.
127  ) {
128  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
129  $ret = null;
130 
131  foreach ($this->_local_copy_of_array as $user) {
132  $previous_password = $user->GetPassword();
133  $login = $user->GetLogin();
134  if (($in_login == $login) && password_verify($in_password, $previous_password)) {
135  $ret = $previous_password;
136  break;
137  }
138  }
139 
140  return $ret;
141  }
142 
143  /*******************************************************************/
144  /** \brief Given a login, looks up the user, and returns
145  a reference to that user object.
146 
147  \returns a reference to a c_comdef_user object. Null if none.
148  */
149  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
150  public function &GetUserByLogin( $in_login ///< A string. The login ID.
151  )
152  {
153  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
154  $ret = null;
155 
156  foreach ($this->_local_copy_of_array as &$user) {
157  if (($in_login == $user->GetLogin())) {
158  $ret = $user;
159  break;
160  }
161  }
162 
163  return $ret;
164  }
165 
166  /*******************************************************************/
167  /** \brief Given a login and password, looks up the user, and returns
168  a reference to that user object.
169 
170  \returns a reference to a c_comdef_user object. Null if none.
171  */
172  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
173  public function &GetUserByLoginCredentials(
174  $in_login, ///< A string. The login ID.
175  $in_password ///< A string. the ENCRYPTED password for the user.
176  ) {
177  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
178  $ret = null;
179 
180  foreach ($this->_local_copy_of_array as &$user) {
181  if (($in_login == $user->GetLogin()) && ($in_password == $user->GetPassword())) {
182  if (($in_login == $user->GetLogin()) && ($in_password == $user->GetPassword())) {
183  $ret = $user;
184  }
185  break;
186  }
187  }
188 
189  return $ret;
190  }
191 
192  /*******************************************************************/
193  /** \brief Accessor -Get the user object for the Server Admin (User ID 1).
194 
195  \returns a reference to a c_comdef_user object for the server admin.
196  */
197  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
198  public function &GetServerAdminObj()
199  {
200  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
201  return $this->_local_copy_of_array[1];
202  }
203 
204  /*******************************************************************/
205  /** \brief Add a user object to the end of the array.
206  */
207  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
208  public function AddUser( &$in_user ///< A reference to the user to be added.
209  )
210  {
211  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
212  if ($in_user instanceof c_comdef_user) {
213  $in_user->SetParentObj($this);
214  array_push($this->_local_copy_of_array, $in_user);
215  }
216  }
217 }
& GetUserByID($in_user_id)
Accessor -Get the user object for one user, given an ID.
& GetServerAdminObj()
Accessor -Get the user object for the Server Admin (User ID 1).
& GetUserByLogin($in_login)
Given a login, looks up the user, and returns a reference to that user object.
__construct($in_parent_object, $in_user_object_array)
This class handles BMLT users. One instance is created for each user on the server.
$ret
Definition: contact.php:226
& GetUsersArray()
Accessor -Get the user object array.
GetParentObj()
Return a reference to the parent object of this instance.
A class to hold a collection of c_comdef_users objects.
& GetEncryptedPW($in_login, $in_password)
Given a login and password, looks up the user, and returns an encrypted password for that user...
Simply declares an interface for having a "container" object.
SetParentObj($in_parent_obj)
Set the parent object of this instance.
defined('BMLT_EXEC') or define('BMLT_EXEC'
Definition: index.php:3
& GetUserByLoginCredentials($in_login, $in_password)
Given a login and password, looks up the user, and returns a reference to that user object...
AddUser(&$in_user)
Add a user object to the end of the array.