Skip to content

Commit e68c47a

Browse files
committed
Merge branch 'master' into role-status-log
# Conflicts: # app/Providers/RepositoryServiceProvider.php
2 parents 2d21118 + 5e7c87f commit e68c47a

32 files changed

+937
-380
lines changed

Vagrantfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
1010
# please see the online documentation at vagrantup.com.
1111

1212
# Every Vagrant virtual environment requires a box to build off of.
13-
config.vm.box = "debian/contrib-jessie64"
13+
config.vm.box = "NottingHack/hms2"
1414
config.vm.hostname = "hmsdev.nottingtest.org.uk"
15-
config.vm.provision :shell, path: "dev/vagrant-config/scripts/bootstrap.sh"
15+
16+
config.vm.provider :virtualbox do |vb|
17+
vb.customize ['modifyvm', :id, '--memory', '2048']
18+
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
19+
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
20+
end
21+
1622
config.vm.provision :shell, path: "dev/vagrant-config/scripts/nginx.sh"
17-
config.vm.provision :shell, path: "dev/vagrant-config/scripts/database.sh"
18-
config.vm.provision :shell, path: "dev/vagrant-config/scripts/php.sh"
19-
config.vm.provision :shell, path: "dev/vagrant-config/scripts/kerberos.sh"
20-
config.vm.provision :shell, path: "dev/vagrant-config/scripts/node.sh"
2123
config.vm.provision :shell, path: "dev/vagrant-config/scripts/laravel.sh"
2224
config.vm.provision :shell, path: "dev/vagrant-config/scripts/mix.sh", privileged: false
2325
config.vm.provision :shell, path: "dev/vagrant-config/scripts/finish.sh"

app/HMS/Entities/User.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace HMS\Entities;
44

55
use HMS\Entities\Banking\Account;
6+
use Laravel\Passport\HasApiTokens;
67
use HMS\Traits\Entities\SoftDeletable;
78
use HMS\Traits\Entities\Timestampable;
89
use LaravelDoctrine\ACL\Roles\HasRoles;
@@ -19,7 +20,7 @@
1920

2021
class User implements AuthenticatableContract, CanResetPasswordContract, HasRoleContract, HasPermissionsContract, AuthorizableContract
2122
{
22-
use CanResetPassword, Notifiable, HasRoles, HasPermissions, SoftDeletable, Timestampable, Authorizable;
23+
use CanResetPassword, Notifiable, HasRoles, HasPermissions, SoftDeletable, Timestampable, Authorizable, HasApiTokens;
2324

2425
const MIN_PASSWORD_LENGTH = 3;
2526

@@ -247,4 +248,13 @@ public function setAccount(?Account $account): User
247248

248249
return $this;
249250
}
251+
252+
/**
253+
* use by passport.
254+
* @return int
255+
*/
256+
public function getKey()
257+
{
258+
return $this->getAuthIdentifier();
259+
}
250260
}

app/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Kernel extends HttpKernel
3434
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
3535
\App\Http\Middleware\VerifyCsrfToken::class,
3636
\App\Http\Middleware\SubstituteEntityBindings::class,
37+
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
3738
],
3839

3940
'api' => [

app/Providers/AppServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Providers;
44

55
use HMS\Auth\PasswordStore;
6+
use Laravel\Passport\Passport;
67
use Faker\Factory as FakerFactory;
78
use HMS\Auth\PasswordStoreManager;
89
use Faker\Generator as FakerGenerator;
@@ -36,5 +37,8 @@ public function register()
3637
$this->app->singleton(FakerGenerator::class, function () {
3738
return FakerFactory::create('en_GB');
3839
});
40+
41+
// Don't need the passport migrations as we have custom laravel-doctrine ones.
42+
Passport::ignoreMigrations();
3943
}
4044
}

app/Providers/AuthServiceProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace App\Providers;
44

5+
use Carbon\Carbon;
56
use HMS\Auth\PasswordStore;
67
use HMS\Auth\HmsUserProvider;
8+
use Laravel\Passport\Passport;
79
use Illuminate\Support\Facades\Auth;
810
use Doctrine\ORM\EntityManagerInterface;
911
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
@@ -31,5 +33,10 @@ public function boot(EntityManagerInterface $em, PasswordStore $passwordStore)
3133
Auth::provider('hms', function ($app, array $config) use ($em, $passwordStore) {
3234
return new HmsUserProvider($app['hash'], $em, $config['model'], $passwordStore);
3335
});
36+
37+
// Passport bits.
38+
Passport::routes();
39+
Passport::tokensExpireIn(Carbon::now()->addDays(env('PASSPORT_TOKEN_EXPIRE_DAYS', 15)));
40+
Passport::refreshTokensExpireIn(Carbon::now()->addDays(env('PASSPORT_REFRESH_TOKEN_EXPIRE_DAYS', 30)));
3441
}
3542
}

app/Providers/RepositoryServiceProvider.php

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,10 @@
22

33
namespace App\Providers;
44

5-
use HMS\Entities\Link;
6-
use HMS\Entities\Meta;
7-
use HMS\Entities\Role;
8-
use HMS\Entities\User;
9-
use HMS\Entities\Invite;
10-
use HMS\Entities\Profile;
11-
use HMS\Entities\RoleUpdate;
12-
use HMS\Entities\Banking\Account;
13-
use HMS\Repositories\LinkRepository;
14-
use HMS\Repositories\MetaRepository;
15-
use HMS\Repositories\RoleRepository;
16-
use HMS\Repositories\UserRepository;
17-
use HMS\Repositories\InviteRepository;
18-
use HMS\Repositories\ProfileRepository;
195
use Illuminate\Support\ServiceProvider;
206
use HMS\Repositories\PermissionRepository;
21-
use HMS\Repositories\RoleUpdateRepository;
22-
use HMS\Repositories\Banking\AccountRepository;
237
use LaravelDoctrine\ACL\Permissions\Permission;
24-
use HMS\Repositories\Doctrine\DoctrineLinkRepository;
25-
use HMS\Repositories\Doctrine\DoctrineMetaRepository;
26-
use HMS\Repositories\Doctrine\DoctrineRoleRepository;
27-
use HMS\Repositories\Doctrine\DoctrineUserRepository;
28-
use HMS\Repositories\Doctrine\DoctrineInviteRepository;
29-
use HMS\Repositories\Doctrine\DoctrineProfileRepository;
308
use HMS\Repositories\Doctrine\DoctrinePermissionRepository;
31-
use HMS\Repositories\Doctrine\DoctrineRoleUpdateRepository;
32-
use HMS\Repositories\Banking\Doctrine\DoctrineAccountRepository;
339

3410
class RepositoryServiceProvider extends ServiceProvider
3511
{
@@ -50,40 +26,23 @@ public function boot()
5026
*/
5127
public function register()
5228
{
53-
$this->app->singleton(LinkRepository::class, function ($app) {
54-
return new DoctrineLinkRepository($app['em'], $app['em']->getClassMetaData(Link::class));
55-
});
56-
57-
$this->app->singleton(MetaRepository::class, function ($app) {
58-
return new DoctrineMetaRepository($app['em'], $app['em']->getClassMetaData(Meta::class));
59-
});
60-
61-
$this->app->singleton(InviteRepository::class, function ($app) {
62-
return new DoctrineInviteRepository($app['em'], $app['em']->getClassMetaData(Invite::class));
63-
});
64-
65-
$this->app->singleton(RoleRepository::class, function ($app) {
66-
return new DoctrineRoleRepository($app['em'], $app['em']->getClassMetaData(Role::class));
67-
});
68-
69-
$this->app->singleton(UserRepository::class, function ($app) {
70-
return new DoctrineUserRepository($app['em'], $app['em']->getClassMetaData(User::class));
71-
});
72-
73-
$this->app->singleton(ProfileRepository::class, function ($app) {
74-
return new DoctrineProfileRepository($app['em'], $app['em']->getClassMetaData(Profile::class));
75-
});
76-
29+
foreach (config('repositories.repositories') as $repository) {
30+
$entity = config('repositories.entity_namespace') . '\\' . $repository;
31+
$interface = config('repositories.repositoriy_namespace') . '\\' . $repository . 'Repository';
32+
$implmentation = config('repositories.repositoriy_namespace') . '\\' .
33+
(strpos($repository, '\\') ? explode('\\', $repository)[0] . '\\' : '') .
34+
'Doctrine\\Doctrine' .
35+
(strpos($repository, '\\') ? explode('\\', $repository)[1] : $repository) .
36+
'Repository';
37+
38+
$this->app->singleton($interface, function ($app) use ($implmentation, $entity) {
39+
return new $implmentation($app['em'], $app['em']->getClassMetaData($entity));
40+
});
41+
}
42+
43+
// Special case so do this one by hand
7744
$this->app->singleton(PermissionRepository::class, function ($app) {
7845
return new DoctrinePermissionRepository($app['em'], $app['em']->getClassMetaData(Permission::class));
7946
});
80-
81-
$this->app->singleton(AccountRepository::class, function ($app) {
82-
return new DoctrineAccountRepository($app['em'], $app['em']->getClassMetaData(Account::class));
83-
});
84-
85-
$this->app->singleton(RoleUpdateRepository::class, function ($app) {
86-
return new DoctrineRoleUpdateRepository($app['em'], $app['em']->getClassMetaData(RoleUpdate::class));
87-
});
8847
}
8948
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"laravel-doctrine/migrations": "1.1.*",
1616
"laravel-doctrine/orm": "1.3.*",
1717
"laravel/framework": "5.4.*",
18+
"laravel/passport": "^2.0",
1819
"laravel/tinker": "~1.0",
1920
"spatie/laravel-cookie-consent": "^1.6"
2021
},

0 commit comments

Comments
 (0)