XOOPS  2.6.0
checklogin.php
Go to the documentation of this file.
1 <?php
21 
23 
25 
26 // from $_POST we use keys: uname, pass, rememberme, xoops_redirect
28  'post',
29  array(
30  array('uname','string', '', true),
31  array('pass','string', '', true),
32  array('rememberme', 'boolean', 0, false),
33  array('xoops_redirect', 'weburl', '', true),
34  )
35 );
36 
37 $uname = $clean_input['uname'];
38 $pass = $clean_input['pass'];
39 if ($uname == '' || $pass == '') {
40  $xoops->redirect($xoops_url . '/user.php', 1, XoopsLocale::E_INCORRECT_LOGIN);
41  exit();
42 }
43 
44 $member_handler = $xoops->getHandlerMember();
45 
46 $xoopsAuth = \Xoops\Auth\Factory::getAuthConnection($uname);
47 $user = $xoopsAuth->authenticate($uname, $pass);
48 
49 if (false != $user) {
50  /* @var $user XoopsUser */
51  if (0 == $user->getVar('level')) {
53  exit();
54  }
55  if ($xoops->getConfig('closesite') == 1) {
56  $allowed = false;
57  foreach ($user->getGroups() as $group) {
58  if (in_array($group, $xoops->getConfig('closesite_okgrp')) || FixedGroups::ADMIN == $group) {
59  $allowed = true;
60  break;
61  }
62  }
63  if (!$allowed) {
64  $xoops->redirect($xoops_url . '/index.php', 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
65  exit();
66  }
67  }
68  $user->setVar('last_login', time());
69  if (!$member_handler->insertUser($user)) {
70  }
71 
72  $xoops->session()->user()->recordUserLogin($user->getVar('uid'), $clean_input["rememberme"]);
73  $user_theme = $user->getVar('theme');
74  if (in_array($user_theme, $xoops->getConfig('theme_set_allowed'))) {
75  $_SESSION['xoopsUserTheme'] = $user_theme;
76  }
77 
78  $xoops->events()->triggerEvent('core.include.checklogin.success');
79 
80  if (!empty($clean_input['xoops_redirect']) && !strpos($clean_input['xoops_redirect'], 'register')) {
81  $xoops_redirect = rawurldecode($clean_input['xoops_redirect']);
82  $parsed = parse_url($xoops_url);
83  $url = isset($parsed['scheme']) ? $parsed['scheme'] . '://' : 'http://';
84  if (isset($parsed['host'])) {
85  $url .= $parsed['host'];
86  if (isset($parsed['port'])) {
87  $url .= ':' . $parsed['port'];
88  }
89  } else {
90  $url .= $_SERVER['HTTP_HOST'];
91  }
92  if (@$parsed['path']) {
93  if (strncmp($parsed['path'], $xoops_redirect, strlen($parsed['path']))) {
94  $url .= $parsed['path'];
95  }
96  }
97  $url .= $xoops_redirect;
98  } else {
99  $url = $xoops_url . '/index.php';
100  }
101 
102  $xoops->redirect($url, 1, sprintf(XoopsLocale::SF_THANK_YOU_FOR_LOGGING_IN, $user->getVar('uname')), false);
103 } else {
104  $xoops->events()->triggerEvent('core.include.checklogin.failed');
105  if (empty($clean_input['xoops_redirect'])) {
106  $xoops->redirect($xoops_url . '/user.php', 5, $xoopsAuth->getHtmlErrors());
107  } else {
108  $xoops->redirect(
109  $xoops_url . '/user.php?xoops_redirect=' . urlencode($clean_input['xoops_redirect']),
110  5,
111  $xoopsAuth->getHtmlErrors(),
112  false
113  );
114  }
115 }
116 exit();
const E_INCORRECT_LOGIN
Definition: en_US.php:332
$_SESSION['RF']["verify"]
Definition: dialog.php:4
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
$xoops_url
Definition: checklogin.php:24
$xoops
Definition: checklogin.php:22
static getInstance()
Definition: Xoops.php:160
const E_SELECTED_USER_DEACTIVATED_OR_NOT_ACTIVE
Definition: en_US.php:364
$clean_input
Definition: checklogin.php:27
$user
Definition: checklogin.php:47
$_SERVER['REQUEST_URI']
static gather($source, $input_map, $require=false)
$xoopsAuth
Definition: checklogin.php:46
exit
Definition: browse.php:104
$allowed
Definition: site-closed.php:26
static get($name)
if($xoops->isActiveModule('images')) return false
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$url
Definition: register.php:72
$uname
Definition: checklogin.php:37
$pass
Definition: checklogin.php:38
const SF_THANK_YOU_FOR_LOGGING_IN
Definition: en_US.php:998