File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313use Symfony \Component \HttpFoundation \Exception \SuspiciousOperationException ;
1414use System \Classes \PluginBase ;
1515use Vdlp \BasicAuthentication \Classes \Helper \AuthorizationHelper ;
16+ use Vdlp \BasicAuthentication \Console \CreateCredentialsCommand ;
1617use Vdlp \BasicAuthentication \Models \Credential ;
1718use Vdlp \BasicAuthentication \ServiceProviders \BasicAuthenticationServiceProvider ;
1819
@@ -42,6 +43,8 @@ public function pluginDetails(): array
4243 public function register (): void
4344 {
4445 $ this ->app ->register (BasicAuthenticationServiceProvider::class);
46+
47+ $ this ->registerConsoleCommand (CreateCredentialsCommand::class, CreateCredentialsCommand::class);
4548 }
4649
4750 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Vdlp \BasicAuthentication \Console ;
6+
7+ use Illuminate \Console \Command ;
8+ use Throwable ;
9+ use Vdlp \BasicAuthentication \Models \Credential ;
10+
11+ final class CreateCredentialsCommand extends Command
12+ {
13+ public function __construct ()
14+ {
15+ $ this ->signature = 'vdlp:basicauthentication:create-credentials {hostname} {realm} {username} {password} ' ;
16+ $ this ->description = 'Create Basic Authentication credentials. ' ;
17+
18+ parent ::__construct ();
19+ }
20+
21+ public function handle (): void
22+ {
23+ try {
24+ Credential::query ()
25+ ->updateOrInsert ([
26+ 'hostname ' => $ this ->argument ('hostname ' ),
27+ ], [
28+ 'realm ' => $ this ->argument ('realm ' ),
29+ 'username ' => $ this ->argument ('username ' ),
30+ 'password ' => $ this ->argument ('password ' ),
31+ 'is_enabled ' => true ,
32+ 'updated_at ' => now (),
33+ 'created_at ' => now (),
34+ ]);
35+
36+ $ this ->info ('Basic Authentication credentials have been added to the database. ' );
37+ } catch (Throwable $ e ) {
38+ $ this ->error ('Could not create Basic Authentication credentials: ' . $ e ->getMessage ());
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change 44
55namespace Vdlp \BasicAuthentication \Models ;
66
7- use Eloquent ;
87use October \Rain \Database \Model ;
98
10- /** @noinspection ClassOverridesFieldOfSuperClassInspection */
11- /** @noinspection LongInheritanceChainInspection */
12-
139/**
1410 * Class Credential
1511 *
1612 * @package Vdlp\BasicAuthentication\Models
17- * @mixin Eloquent
1813 */
1914class Credential extends Model
2015{
Original file line number Diff line number Diff line change 44
55namespace Vdlp \BasicAuthentication \Models ;
66
7- use Eloquent ;
87use October \Rain \Database \Model ;
98
10- /** @noinspection ClassOverridesFieldOfSuperClassInspection */
11- /** @noinspection LongInheritanceChainInspection */
12-
139/**
1410 * Class ExcludedUrl
1511 *
1612 * @package Vdlp\BasicAuthentication\Models
17- * @mixin Eloquent
1813 */
1914class ExcludedUrl extends Model
2015{
You can’t perform that action at this time.
0 commit comments