Skip to content

Commit 6d15d3f

Browse files
committed
Add simple login policy implementation
1 parent 9fc6869 commit 6d15d3f

File tree

2 files changed

+169
-18
lines changed

2 files changed

+169
-18
lines changed

src/LoginPolicy/LoginPolicy.php

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Active Collab Authentication project.
5+
*
6+
* (c) A51 doo <[email protected]>. All rights reserved.
7+
*/
8+
9+
namespace ActiveCollab\Authentication\LoginPolicy;
10+
11+
/**
12+
* @package ActiveCollab\Authentication\LoginPolicy
13+
*/
14+
class LoginPolicy implements LoginPolicyInterface
15+
{
16+
/**
17+
* @var string
18+
*/
19+
private $username_format;
20+
21+
/**
22+
* @var bool
23+
*/
24+
private $remember_extends_session;
25+
26+
/**
27+
* @var bool
28+
*/
29+
private $password_change_enabled;
30+
31+
/**
32+
* @var bool
33+
*/
34+
private $password_recovery_enabled;
35+
36+
/**
37+
* @var string
38+
*/
39+
private $external_login_url;
40+
41+
/**
42+
* @var string
43+
*/
44+
private $external_logout_url;
45+
46+
/**
47+
* @var string
48+
*/
49+
private $external_change_password_url;
50+
51+
/**
52+
* @var string
53+
*/
54+
private $external_update_profile_url;
55+
56+
/**
57+
* LoginPolicy constructor.
58+
*
59+
* @param string $username_format
60+
* @param bool $remember_extends_session
61+
* @param bool $password_change_enabled
62+
* @param bool $password_recovery_enabled
63+
* @param string $external_login_url
64+
* @param string $external_logout_url
65+
* @param string $external_change_password_url
66+
* @param string $external_update_profile_url
67+
*/
68+
public function __construct($username_format, $remember_extends_session, $password_change_enabled, $password_recovery_enabled, $external_login_url, $external_logout_url, $external_change_password_url, $external_update_profile_url)
69+
{
70+
$this->username_format = $username_format;
71+
$this->remember_extends_session = (bool) $remember_extends_session;
72+
$this->password_change_enabled = (bool) $password_change_enabled;
73+
$this->password_recovery_enabled = (bool) $password_recovery_enabled;
74+
$this->external_login_url = $external_login_url;
75+
$this->external_logout_url = $external_logout_url;
76+
$this->external_change_password_url = $external_change_password_url;
77+
$this->external_update_profile_url = $external_update_profile_url;
78+
}
79+
80+
/**
81+
* {@inheritdoc}
82+
*/
83+
public function getUsernameFormat()
84+
{
85+
return $this->username_format;
86+
}
87+
88+
/**
89+
* {@inheritdoc}
90+
*/
91+
public function rememberExtendsSession()
92+
{
93+
return $this->remember_extends_session;
94+
}
95+
96+
/**
97+
* {@inheritdoc}
98+
*/
99+
public function isPasswordChangeEnabled()
100+
{
101+
return $this->password_change_enabled;
102+
}
103+
104+
/**
105+
* {@inheritdoc}
106+
*/
107+
public function isPasswordRecoveryEnabled()
108+
{
109+
return $this->password_recovery_enabled;
110+
}
111+
112+
/**
113+
* {@inheritdoc}
114+
*/
115+
public function getExternalLoginUrl()
116+
{
117+
return $this->external_login_url;
118+
}
119+
120+
/**
121+
* {@inheritdoc}
122+
*/
123+
public function getExternalLogoutUrl()
124+
{
125+
return $this->external_logout_url;
126+
}
127+
128+
/**
129+
* {@inheritdoc}
130+
*/
131+
public function getExternalChangePasswordUrl()
132+
{
133+
return $this->external_change_password_url;
134+
}
135+
136+
/**
137+
* {@inheritdoc}
138+
*/
139+
public function getExternalUpdateProfileUrl()
140+
{
141+
return $this->external_update_profile_url;
142+
}
143+
144+
/**
145+
* {@inheritdoc}
146+
*/
147+
public function jsonSerialize()
148+
{
149+
return [
150+
'username_format' => $this->getUsernameFormat(),
151+
'remember_extends_session' => $this->rememberExtendsSession(),
152+
'password_change_enabled' => $this->isPasswordChangeEnabled(),
153+
'password_recovery_enabled' => $this->isPasswordRecoveryEnabled(),
154+
'external_login_url' => $this->getExternalLoginUrl(),
155+
'external_logout_url' => $this->getExternalLogoutUrl(),
156+
'external_change_password_url' => $this->getExternalChangePasswordUrl(),
157+
'external_update_profile_url' => $this->getExternalUpdateProfileUrl(),
158+
];
159+
}
160+
}

src/Policy/LoginPolicyInterface.php renamed to src/LoginPolicy/LoginPolicyInterface.php

+9-18
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
* (c) A51 doo <[email protected]>. All rights reserved.
77
*/
88

9-
namespace ActiveCollab\Authentication\Policy;
9+
namespace ActiveCollab\Authentication\LoginPolicy;
1010

1111
use JsonSerializable;
1212

13+
/**
14+
* @package ActiveCollab\Authentication\LoginPolicy
15+
*/
1316
interface LoginPolicyInterface extends JsonSerializable
1417
{
1518
const USERNAME_FORMAT_TEXT = 'text';
@@ -23,22 +26,10 @@ interface LoginPolicyInterface extends JsonSerializable
2326
public function getUsernameFormat();
2427

2528
/**
26-
* Check is text username format.
27-
*
28-
* @return bool
29-
*/
30-
public function isUsernameTextFormat();
31-
32-
/**
33-
* Check is email username format.
29+
* Enable Remember Me feature to support extended sessions.
3430
*
3531
* @return bool
3632
*/
37-
public function isUsernameEmailFormat();
38-
39-
/**
40-
* Enable Remember Me feature to support extended sessions.
41-
*/
4233
public function rememberExtendsSession();
4334

4435
/**
@@ -60,26 +51,26 @@ public function isPasswordRecoveryEnabled();
6051
*
6152
* @return string|null
6253
*/
63-
public function getLoginUrl();
54+
public function getExternalLoginUrl();
6455

6556
/**
6657
* Get logout URL.
6758
*
6859
* @return string
6960
*/
70-
public function getLogoutUrl();
61+
public function getExternalLogoutUrl();
7162

7263
/**
7364
* Get change password URL.
7465
*
7566
* @return string|null
7667
*/
77-
public function getChangePasswordUrl();
68+
public function getExternalChangePasswordUrl();
7869

7970
/**
8071
* Get update profile URL.
8172
*
8273
* @return string|null
8374
*/
84-
public function getUpdateProfileUrl();
75+
public function getExternalUpdateProfileUrl();
8576
}

0 commit comments

Comments
 (0)