|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
View Code Duplication |
class LinkedinLoginForm extends LoginForm |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
protected $authenticator_class = 'LinkedinAuthenticator'; |
|
6
|
|
|
|
|
7
|
|
|
public function __construct($controller, $method, $fields = null, $actions = null, $checkCurrentUser = true) |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
if (isset($_REQUEST['BackURL'])) { |
|
10
|
|
|
$backURL = $_REQUEST['BackURL']; |
|
11
|
|
|
} else { |
|
12
|
|
|
$backURL = Session::get('BackURL'); |
|
13
|
|
|
} |
|
14
|
|
|
if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) { |
|
15
|
|
|
$fields = new FieldSet( |
|
16
|
|
|
new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this) |
|
|
|
|
|
|
17
|
|
|
); |
|
18
|
|
|
$actions = new FieldSet( |
|
19
|
|
|
new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")) |
|
|
|
|
|
|
20
|
|
|
); |
|
21
|
|
|
} else { |
|
22
|
|
|
if (!$fields) { |
|
23
|
|
|
$fields = new FieldSet( |
|
24
|
|
|
new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this) |
|
|
|
|
|
|
25
|
|
|
); |
|
26
|
|
|
if (Security::$autologin_enabled) { |
|
27
|
|
|
$fields->push(new CheckboxField( |
|
28
|
|
|
"Remember", |
|
|
|
|
|
|
29
|
|
|
_t('Member.REMEMBERME'), |
|
|
|
|
|
|
30
|
|
|
Session::get('SessionForms.LinkedinLoginForm.Remember'), |
|
31
|
|
|
$this |
|
|
|
|
|
|
32
|
|
|
)); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
if (!$actions) { |
|
36
|
|
|
$actions = new FieldSet( |
|
37
|
|
|
new ImageFormAction('dologin', 'Sign in with LinkedIn', 'linkedin/Images/linkedin.png') |
|
|
|
|
|
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
if (!empty($backURL)) { |
|
42
|
|
|
$fields->push(new HiddenField('BackURL', 'BackURL', $backURL)); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
parent::__construct( |
|
45
|
|
|
$controller, |
|
46
|
|
|
$method, |
|
47
|
|
|
$fields, |
|
48
|
|
|
$actions |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function getMessageFromSession() |
|
53
|
|
|
{ |
|
54
|
|
|
parent::getMessageFromSession(); |
|
55
|
|
|
if (($member = Member::currentUser()) && !$this->message) { |
|
56
|
|
|
$this->message = sprintf(_t('Member.LOGGEDINAS'), $member->FirstName); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function dologin($data) |
|
61
|
|
|
{ |
|
62
|
|
|
if (!empty($data['BackURL'])) { |
|
63
|
|
|
Session::set('BackURL', $data['BackURL']); |
|
64
|
|
|
} |
|
65
|
|
|
Session::set('SessionForms.LinkedinLoginForm.Remember', !empty($data['Remember'])); |
|
|
|
|
|
|
66
|
|
|
return LinkedinAuthenticator::authenticate($data, $this); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Log out form handler method |
|
71
|
|
|
* |
|
72
|
|
|
* This method is called when the user clicks on "logout" on the form |
|
73
|
|
|
* created when the parameter <i>$checkCurrentUser</i> of the |
|
74
|
|
|
* {@link __construct constructor} was set to TRUE and the user was |
|
75
|
|
|
* currently logged in. |
|
76
|
|
|
*/ |
|
77
|
|
|
public function logout() |
|
78
|
|
|
{ |
|
79
|
|
|
$s = new Security(); |
|
80
|
|
|
$s->logout(); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.