|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xoops\Auth; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Authentication class for Native XOOPS |
|
16
|
|
|
* |
|
17
|
|
|
* @category Xoops |
|
18
|
|
|
* @package Auth |
|
19
|
|
|
* @author Pierre-Eric MENUET <[email protected]> |
|
20
|
|
|
* @copyright 2000-2014 XOOPS Project (http://xoops.org) |
|
21
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
22
|
|
|
* @link http://xoops.org |
|
23
|
|
|
* @since 2.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class AuthAbstract |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var use Xoops\Core\Database\Connection|null |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $dao; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $errors; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $auth_method; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Authentication Service constructor |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Xoops\Core\Database\Connection|null $dao database |
|
46
|
|
|
*/ |
|
47
|
12 |
|
public function __construct($dao) |
|
48
|
|
|
{ |
|
49
|
12 |
|
$this->dao = $dao; |
|
50
|
12 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* authenticate a user |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $uname user name |
|
56
|
|
|
* @param string|null $pwd password |
|
57
|
|
|
* |
|
58
|
|
|
* @return bool true if authenticated, otherwise fales |
|
59
|
|
|
*/ |
|
60
|
|
|
abstract public function authenticate($uname, $pwd = null); |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* setErrors |
|
64
|
|
|
* |
|
65
|
|
|
* @param int $err_no error number |
|
66
|
|
|
* @param string $err_str error message |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
4 |
|
public function setErrors($err_no, $err_str) |
|
71
|
|
|
{ |
|
72
|
4 |
|
$this->errors[$err_no] = trim($err_str); |
|
73
|
4 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* return the errors for this object as an array |
|
77
|
|
|
* |
|
78
|
|
|
* @return array an array of errors |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getErrors() |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->errors; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* return the errors for this object as html |
|
87
|
|
|
* |
|
88
|
|
|
* @return string html listing the errors |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function getHtmlErrors() |
|
91
|
|
|
{ |
|
92
|
1 |
|
$xoops = \Xoops::getInstance(); |
|
93
|
1 |
|
$ret = '<br />'; |
|
94
|
1 |
|
if ($xoops->getConfig('debug_mode') == 1 || $xoops->getConfig('debug_mode') == 2) { |
|
95
|
|
View Code Duplication |
if (!empty($this->errors)) { |
|
96
|
|
|
foreach ($this->errors as $errstr) { |
|
97
|
|
|
$ret .= $errstr . '<br/>'; |
|
98
|
|
|
} |
|
99
|
|
|
} else { |
|
100
|
|
|
$ret .= \XoopsLocale::NONE . '<br />'; |
|
101
|
|
|
} |
|
102
|
|
|
$ret .= sprintf(\XoopsLocale::F_USING_AUTHENTICATION_METHOD, $this->auth_method); |
|
103
|
|
|
} else { |
|
104
|
1 |
|
$ret .= \XoopsLocale::E_INCORRECT_LOGIN; |
|
105
|
|
|
} |
|
106
|
1 |
|
return $ret; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|