forked from StartupAPI/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthenticationModule.php
More file actions
126 lines (109 loc) · 2.98 KB
/
AuthenticationModule.php
File metadata and controls
126 lines (109 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
interface IAuthenticationModule extends IUserBaseModule
{
public function renderLoginForm($action);
public function renderRegistrationForm($full = false, $action = null, $errors = null, $data = null);
public function processLogin($data, &$remember);
public function processAutoLogin();
public function getAutoLogoutURL($return);
public function renderAutoLogoutForm();
public function processRegistration($data, &$remember);
/**
* This method should return user credentials object
*
* @param User $user User to get credentials for
* @return UserCredentials User credentials object specific to the module
*/
public function getUserCredentials($user);
/**
* This module returns total number of connections with provider
* @return int Number of users who have connections through this provider
* Some modules might allow for multiple connections, but the user is only counted once
*/
public function getTotalConnectedUsers();
}
abstract class AuthenticationModule extends UserBaseModule implements IAuthenticationModule {
public function __construct() {
parent::__construct();
UserConfig::$authentication_modules[] = $this;
}
/**
* Returns authentication module by ID
* @param string $id ID of the module
*/
public static function get($id) {
foreach (UserConfig::$authentication_modules as $module)
{
if ($module->getID() == $id) {
return $module;
}
}
}
/**
* By default, do not auto-login, should be overriden by modules that support auto-login
*/
public function processAutoLogin() {
return null;
}
/**
* By default, modules do not support auto-logout, don't try doing that
*/
public function getAutoLogoutURL($return) {
return null;
}
/**
* By default, modules do not support auto-logout
*/
public function renderAutoLogoutForm() {
return null;
}
}
class InputValidationException extends Exception {
private $errors;
public function __construct($string, $code, $errors)
{
parent::__construct($string, $code);
$this->errors = $errors;
}
public function getErrors()
{
return $this->errors;
}
}
class ExistingUserException extends Exception {
private $errors;
public function __construct($string, $code, $errors)
{
parent::__construct($string, $code);
$this->errors = $errors;
}
public function getErrors()
{
return $this->errors;
}
}
class UserCreationException extends Exception {
private $field;
public function __construct($string, $code, $field)
{
parent::__construct($string, $code);
$this->field = $field;
}
public function getField()
{
return $this->field;
}
}
/*
* Class representing user credentials for particular module
* Must be subclassed and implemented by module
*/
abstract class UserCredentials {
/**
* This method should return HTML representation of user credentials to be included in admin interface
* Usually linking to user's public profile at the source service
*
* @return string HTML representation of user credentials
*/
public abstract function getHTML();
}