1: <?php
2: /**
3: * XOOPS Authentification base class
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
13: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14: * @package kernel
15: * @subpackage auth
16: * @since 2.0
17: * @author Pierre-Eric MENUET <pemphp@free.fr>
18: */
19:
20: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
21:
22: /**
23: *
24: * @package kernel
25: * @subpackage auth
26: * @description Authentification base class
27: * @author Pierre-Eric MENUET <pemphp@free.fr>
28: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
29: */
30: class XoopsAuth
31: {
32: public $_dao;
33: public $_errors;
34: public $auth_method;
35:
36: /**
37: * Authentication Service constructor
38: * @param XoopsDatabase $dao
39: */
40: public function __construct(XoopsDatabase $dao = null)
41: {
42: $this->_dao = $dao;
43: }
44:
45: /**
46: * @param string $uname
47: * @abstract need to be written in the derived class
48: */
49: public function authenticate($uname)
50: {
51: $authenticated = false;
52:
53: return $authenticated;
54: }
55:
56: /**
57: * add an error
58: *
59: * @param int $err_no
60: * @param string $err_str error value to add
61: *
62: * @access public
63: */
64: public function setErrors($err_no, $err_str)
65: {
66: $this->_errors[$err_no] = trim($err_str);
67: }
68:
69: /**
70: * return the errors for this object as an array
71: *
72: * @return array an array of errors
73: * @access public
74: */
75: public function getErrors()
76: {
77: return $this->_errors;
78: }
79:
80: /**
81: * return the errors for this object as html
82: *
83: * @return string html listing the errors
84: * @access public
85: */
86: public function getHtmlErrors()
87: {
88: global $xoopsConfig;
89: $ret = '<br>';
90: if ($xoopsConfig['debug_mode'] == 1 || $xoopsConfig['debug_mode'] == 2) {
91: if (!empty($this->_errors)) {
92: foreach ($this->_errors as $errstr) {
93: $ret .= $errstr . '<br>';
94: }
95: } else {
96: $ret .= _NONE . '<br>';
97: }
98: $ret .= sprintf(_AUTH_MSG_AUTH_METHOD, $this->auth_method);
99: } else {
100: $ret .= _US_INCORRECTLOGIN;
101: }
102:
103: return $ret;
104: }
105: }
106: