Skip to content

Commit 181ff95

Browse files
committed
Allow whitelisted users to be an array
1 parent 1fc8347 commit 181ff95

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

config/stagefront.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
/**
5858
* When using the database, you can limit access to specific users.
59-
* Enter a string of comma separated logins, or null to allow all users.
59+
* Enter aan array or string of comma separated logins, or null to allow all users.
6060
* For example: 'john@doe.io,jane@doe.io'
6161
*
6262
* Default: null
@@ -96,4 +96,5 @@
9696
* Default: []
9797
*/
9898
'ignore_urls' => [],
99+
99100
];

src/Authenticators/DatabaseAuthenticator.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,15 @@ protected function loginIsAllowed($login)
7777
*/
7878
protected function getWhitelist()
7979
{
80-
$whitelist = config('stagefront.database_whitelist', '');
81-
$logins = explode(',', $whitelist) ?: [];
80+
$whitelist = config('stagefront.database_whitelist', []);
81+
82+
if ( ! is_array($whitelist)) {
83+
$whitelist = explode(',', $whitelist) ?: [];
84+
}
8285

8386
$logins = array_map(function ($login) {
8487
return trim($login);
85-
}, $logins);
88+
}, $whitelist);
8689

8790
return array_filter($logins);
8891
}

tests/StageFrontTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function the_users_in_the_database_can_be_used_for_logging_in()
139139
}
140140

141141
/** @test */
142-
public function you_can_limit_which_database_users_have_access()
142+
public function you_can_limit_which_database_users_have_access_using_a_comma_separated_string()
143143
{
144144
$this->loadLaravelMigrations(['--database' => 'testing']);
145145

@@ -183,6 +183,51 @@ public function you_can_limit_which_database_users_have_access()
183183
])->assertRedirect($this->url)->assertSessionHasErrors('password');
184184
}
185185

186+
/** @test */
187+
public function you_can_limit_which_database_users_have_access_using_an_array()
188+
{
189+
$this->loadLaravelMigrations(['--database' => 'testing']);
190+
191+
User::create([
192+
'name' => 'John Doe',
193+
'email' => 'john@doe.io',
194+
'password' => bcrypt('str0ng p4ssw0rd'),
195+
]);
196+
User::create([
197+
'name' => 'Jane Doe',
198+
'email' => 'jane@doe.io',
199+
'password' => bcrypt('str0ng p4ssw0rd'),
200+
]);
201+
User::create([
202+
'name' => 'Mr. Smith',
203+
'email' => 'mr@smith.io',
204+
'password' => bcrypt('str0ng p4ssw0rd'),
205+
]);
206+
207+
config()->set('stagefront.database', true);
208+
config()->set('stagefront.database_whitelist', ['john@doe.io', ' jane@doe.io ']);
209+
config()->set('stagefront.database_table', 'users');
210+
config()->set('stagefront.database_login_field', 'email');
211+
config()->set('stagefront.database_password_field', 'password');
212+
213+
$this->enableStageFront();
214+
215+
$this->setIntendedUrl('/page')->submitForm([
216+
'login' => 'john@doe.io',
217+
'password' => 'str0ng p4ssw0rd',
218+
])->assertRedirect('/page');
219+
220+
$this->setIntendedUrl('/page')->submitForm([
221+
'login' => 'jane@doe.io',
222+
'password' => 'str0ng p4ssw0rd',
223+
])->assertRedirect('/page');
224+
225+
$this->setIntendedUrl('/page')->submitForm([
226+
'login' => 'mr@smith.io',
227+
'password' => 'str0ng p4ssw0rd',
228+
])->assertRedirect($this->url)->assertSessionHasErrors('password');
229+
}
230+
186231
/** @test */
187232
public function urls_can_be_ignored_so_access_is_not_denied_by_stagefront()
188233
{

0 commit comments

Comments
 (0)