1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class SAMLLoginForm |
4
|
|
|
* |
5
|
|
|
* This not very interesting in itself. It's pretty much boiler-plate code to access the authenticator. |
6
|
|
|
*/ |
7
|
|
|
class SAMLLoginForm extends LoginForm |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* This field is used in the "You are logged in as %s" message |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
public $loggedInAsField = 'FirstName'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $authenticator_class = 'SAMLAuthenticator'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor |
22
|
|
|
* |
23
|
|
|
* @param Controller $controller |
24
|
|
|
* @param string $name method on the $controller |
25
|
|
|
* @param FieldList $fields |
26
|
|
|
* @param FieldList $actions |
27
|
|
|
* @param bool $checkCurrentUser - show logout button if logged in |
28
|
|
|
*/ |
29
|
|
|
public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$backURL = Session::get('BackURL'); |
32
|
|
|
|
33
|
|
|
if (isset($_REQUEST['BackURL'])) { |
34
|
|
|
$backURL = $_REQUEST['BackURL']; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ($checkCurrentUser && $this->shouldShowLogoutFields()) { |
38
|
|
|
$fields = new FieldList([ |
39
|
|
|
new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this) |
|
|
|
|
40
|
|
|
]); |
41
|
|
|
$actions = new FieldList([ |
42
|
|
|
new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")) |
43
|
|
|
]); |
44
|
|
|
} else { |
45
|
|
|
if (!$fields) { |
46
|
|
|
$fields = new FieldList([ |
47
|
|
|
new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this) |
|
|
|
|
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
if (!$actions) { |
51
|
|
|
$actions = new FieldList([ |
52
|
|
|
new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in")) |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($backURL) { |
58
|
|
|
$fields->push(new HiddenField('BackURL', 'BackURL', $backURL)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->setFormMethod('POST', true); |
62
|
|
|
|
63
|
|
|
parent::__construct($controller, $name, $fields, $actions); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
protected function shouldShowLogoutFields() |
73
|
|
|
{ |
74
|
|
|
if (!Member::currentUser()) { |
75
|
|
|
return false; |
76
|
|
|
} |
77
|
|
|
if (!Member::logged_in_session_exists()) { |
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
return true; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get message from session |
85
|
|
|
*/ |
86
|
|
|
protected function getMessageFromSession() |
87
|
|
|
{ |
88
|
|
|
// The "MemberLoginForm.force_message session" is set in Security#permissionFailure() |
89
|
|
|
// and displays messages like "You don't have access to this page" |
90
|
|
|
// if force isn't set, it will just display "You're logged in as {name}" |
91
|
|
|
if (($member = Member::currentUser()) && !Session::get('MemberLoginForm.force_message')) { |
92
|
|
|
$this->message = _t( |
93
|
|
|
'Member.LOGGEDINAS', |
94
|
|
|
"You're logged in as {name}.", |
95
|
|
|
['name' => $member->{$this->loggedInAsField}] |
|
|
|
|
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
Session::set('MemberLoginForm.force_message', false); |
|
|
|
|
99
|
|
|
parent::getMessageFromSession(); |
100
|
|
|
return $this->message; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Login form handler method |
106
|
|
|
* |
107
|
|
|
* This method is called when the user clicks on "Log in" |
108
|
|
|
* |
109
|
|
|
* @param array $data Submitted data |
110
|
|
|
*/ |
111
|
|
|
public function dologin($data) |
112
|
|
|
{ |
113
|
|
|
call_user_func_array([$this->authenticator_class, 'authenticate'], [$data, $this]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Log out form handler method |
119
|
|
|
* |
120
|
|
|
* This method is called when the user clicks on "logout" on the form |
121
|
|
|
* created when the parameter <i>$checkCurrentUser</i> of the |
122
|
|
|
* {@link __construct constructor} was set to TRUE and the user was |
123
|
|
|
* currently logged in. |
124
|
|
|
*/ |
125
|
|
|
public function logout() |
126
|
|
|
{ |
127
|
|
|
$s = new Security(); |
128
|
|
|
$s->logout(false); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.