Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
authentication_ipb.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/system/authentication/authentication/authentication.inc';
19 require_once SQ_PACKAGES_PATH.'/ipb/ipb.inc';
20 require_once SQ_FUDGE_PATH.'/general/www.inc';
21 
34 {
35 
36 
43  function Authentication_IPB($assetid=0)
44  {
45  $this->Authentication($assetid);
46 
47  }//end constructor
48 
49 
62  function &authenticateUser($username, $password)
63  {
64  $user = NULL;
65 
66  $bridges = $GLOBALS['SQ_SYSTEM']->am->getChildren($this->id, 'ipb_bridge', TRUE);
67  foreach ($bridges as $bridgeid => $type_code) {
68 
69  $bridge =& $GLOBALS['SQ_SYSTEM']->am->getAsset($bridgeid);
70  if (is_null($bridge)) continue;
71 
72  // if status is not live then skip this bridge
73  if ($bridge->status != SQ_STATUS_LIVE) continue;
74 
75  $ipb =& $bridge->getIpbConn();
76 
77  $email_login = FALSE;
78  if (valid_email($username)) $email_login = TRUE;
79 
80  if (!$this->attr('allow_banned')) {
81  // check banned group option
82  $result = $ipb->canViewBoard($username);
83  if (empty($result)) return $user;
84  $can_view = intval($result['g_view_board']);
85  if (!$can_view) return $user;
86  }
87  $result = $ipb->authenticateUser($bridge, $username, $password, $email_login);
88  if ($result) {
89  $GLOBALS['SQ_SYSTEM']->am->includeAsset('ipb_user');
90  $data = $ipb->getMemberInfoByName($username);
91  $data['id'] = 'u_'.$data['id'];
92  $user = new Ipb_User($bridge->id, $data);
93  return $user;
94  }
95  }
96 
97  // if we are here, we could not find the user
98  $null = NULL;
99  return $null;
100 
101  }//end authenticateUser()
102 
103 
115  function &authenticateHttpUser($username)
116  {
117  $user = NULL;
118  $bridges = $GLOBALS['SQ_SYSTEM']->am->getChildren($this->id, 'ipb_bridge', TRUE);
119  foreach ($bridges as $bridgeid => $type_code) {
120  $bridge =& $GLOBALS['SQ_SYSTEM']->am->getAsset($bridgeid);
121  if (is_null($bridge)) continue;
122 
123  // if status is not live then skip this bridge
124  if ($bridge->status != SQ_STATUS_LIVE) continue;
125 
126  $ipb =& $bridge->getIpbConn();
127  $data = $ipb->getMemberByName($username);
128  if (empty($data)) continue;
129 
130  $GLOBALS['SQ_SYSTEM']->am->includeAsset('ipb_user');
131  $user = new Ipb_User($bridge->id, $data);
132  break;
133  }
134  return $user;
135 
136  }//end authenticateHttpUser()
137 
138 
147  function _registerInvalidLogin(&$user)
148  {
149  $username = $user->attr('name');
150  if (!isset($_SESSION['user_login_attempts'])) {
151  $_SESSION['user_login_attempts'] = Array();
152  }
153  if (empty($_SESSION['user_login_attempts'][$username])) {
154  $_SESSION['user_login_attempts'][$username] = 1;
155  } else {
156  $_SESSION['user_login_attempts'][$username]++;
157  }
158 
159  if ($_SESSION['user_login_attempts'][$username] >= SQ_CONF_MAX_LOGIN_ATTEMPTS) {
160  if (!is_null($user) && $user->canLogin()) {
161  // log a message so we know someone has tried to log in too many times
162  $ms =& $GLOBALS['SQ_SYSTEM']->getMessagingService();
163  $msg_reps = Array(
164  'asset_name' => $user->name,
165  'user_name' => $username,
166  'num_attempts' => (int)SQ_CONF_MAX_LOGIN_ATTEMPTS,
167  );
168  $log = $ms->newMessage(Array(), 'system.security.login.ipb', $msg_reps);
169  $log->parameters['remote_addr'] = $_SERVER['REMOTE_ADDR'];
170  $log->parameters['sessionid'] = session_id();
171  $log->send();
172  }
173  }
174 
175  }//end _registerInvalidLogin()
176 
177 
185  function _getAllowedLinks()
186  {
187  return Array(
188  SQ_LINK_TYPE_1 => Array(
189  'ipb_bridge' => Array(
190  'card' => 'M',
191  'exclusive' => FALSE,
192  ),
193  ),
194  );
195 
196  }//end _getAllowedLinks()
197 
198 
199 }//end class
200 
201 ?>