Skip to content

Commit

Permalink
v1.0.3 (#5)
Browse files Browse the repository at this point in the history
* Update dependencies

* Create jobs table

* Update SDK dependency

* Updates to auth

* Fix auth

* Fix authentication namespace bug

* Update docs
  • Loading branch information
tobytwigger authored Feb 12, 2020
1 parent 57d4323 commit 6143241
Show file tree
Hide file tree
Showing 76 changed files with 943 additions and 95 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.3] - (12/02/2020)

### Changed
- Registration changes to match new SDK
- Set up User Provider
- Update dependencies

## [1.0.2] - (05/02/2020)

### Changed
Expand All @@ -24,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Open and save module instances
- Change settings, permissions and third party connections

[Unreleased]: https://github.com/bristol-su/playground/compare/v1.0.1...HEAD
[Unreleased]: https://github.com/bristol-su/playground/compare/v1.0.3...HEAD
[1.0.3]: https://github.com/bristol-su/playground/compare/v1.0.2...v1.0.3
[1.0.2]: https://github.com/bristol-su/playground/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/bristol-su/playground/compare/v1.0...v1.0.1
[1.0]: https://github.com/bristol-su/playground/releases/tag/v1.0
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Set the base image for subsequent instructions
FROM php:7.2

# Update packages
RUN apt-get update

# Install PHP and composer dependencies
RUN apt-get install -qq git curl libmcrypt-dev libjpeg-dev libpng-dev libfreetype6-dev libbz2-dev

# Clear out the local repository of retrieved package files
RUN apt-get clean

# Install needed extensions
# Here you can install any other extension that you need during the test and deployment process
RUN docker-php-ext-install mcrypt pdo_mysql zip

# Install Composer
RUN curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

5 changes: 3 additions & 2 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function validator(array $data)
return Validator::make($data, [
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:control_data_user'],
'password' => ['required', 'string', 'min:5', 'confirmed'],
]);
}
Expand All @@ -67,12 +67,13 @@ protected function validator(array $data)
*/
protected function create(array $data)
{
$dataUser = app(DataUser::class)->create($data['first_name'], $data['last_name'], $data['email']);
$dataUser = app(DataUser::class)->create($data['first_name'], $data['last_name'], $data['email'], null, $data['first_name'] . ' ' . $data['last_name']);
$controlUser = app(\BristolSU\ControlDB\Contracts\Repositories\User::class)->create($dataUser->id());

$databaseUser = app(UserRepository::class)->create([
'control_id' => $controlUser->id()
]);

$databaseUser->email_verified_at = Carbon::now();
$databaseUser->password = Hash::make($data['password']);
$databaseUser->save();
Expand Down
6 changes: 6 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace BristolSU\Playground\Providers;

use BristolSU\Playground\Support\Authentication\UserProvider;
use BristolSU\Support\Authentication\Contracts\Authentication;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;

/**
Expand All @@ -21,5 +23,9 @@ class AuthServiceProvider extends ServiceProvider
public function boot()
{
$this->app->bind(Authentication::class, \BristolSU\Playground\Support\Authentication\Authentication::class);

Auth::provider('data-user-provider', function($app) {
return $app->make(UserProvider::class);
});
}
}
115 changes: 115 additions & 0 deletions app/Support/Authentication/UserProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace BristolSU\Playground\Support\Authentication;

use BristolSU\ControlDB\Contracts\Repositories\DataUser;
use BristolSU\Support\User\Contracts\UserRepository;
use BristolSU\Support\User\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class UserProvider implements \Illuminate\Contracts\Auth\UserProvider
{

/**
* @var UserRepository
*/
private $userRepository;

public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}

/**
* Retrieve a user by their unique email.
*
* @param mixed $email
* @return User|null
*/
public function retrieveById($email)
{
try {
return $this->userRepository->getById($email);
} catch (ModelNotFoundException $e) {}
return null;
}

/**
* Retrieve a user by their unique email and "remember me" token.
*
* @param mixed $email
* @param string $token
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByToken($email, $token)
{
try {
$user = $this->userRepository->getFromRememberToken($token);
if($user->id === $email) {
return $user;
}
} catch (ModelNotFoundException $e) {}
return null;
}

/**
* Update the "remember me" token for the given user in storage.
*
* @param Authenticatable|User $user
* @param string $token
* @return User|Authenticatable|null
*/
public function updateRememberToken(Authenticatable $user, $token)
{
$this->userRepository->setRememberToken($user->id, $token);
}

/**
* Retrieve a user by the given credentials.
*
* @param array $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
{

try {
$dataUser = app(DataUser::class)->getWhere([
'email' => $credentials['email']
]);
} catch (ModelNotFoundException $e) {
return null;
}

try {
$controlUser = app(\BristolSU\ControlDB\Contracts\Repositories\User::class)->getByDataProviderId($dataUser->id());
} catch (ModelNotFoundException $e) {
return null;
}

try {
$user = $this->userRepository->getFromControlId($controlUser->id());
} catch (ModelNotFoundException $e) {
return null;
}

return $user;
}

/**
* Validate a user against the given credentials.
*
* @param \Illuminate\Contracts\Auth\Authenticatable|User $user
* @param array $credentials
* @return bool
*/
public function validateCredentials(Authenticatable $user, array $credentials)
{
if(app(Hasher::class)->check($credentials['password'], $user->password)) {
return true;
}
return false;
}
}
8 changes: 6 additions & 2 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
'provider' => 'data-users',
],

'api' => [
'driver' => 'passport',
'provider' => 'users',
'provider' => 'data-users',
],

'activity-instance' => [
Expand Down Expand Up @@ -82,6 +82,10 @@
'model' => ActivityInstance::class
],

'data-users' => [
'driver' => 'data-user-provider',
'model' => \BristolSU\Support\User\User::class,
]

// 'users' => [
// 'driver' => 'database',
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.4"
services:
app:
image: php:alpine
volumes:
- "./:/app"
working_dir: /app
command: "php artisan serve --host=0.0.0.0 --port=8000"
ports:
- 8888:8000
8 changes: 5 additions & 3 deletions docs/AuthServiceProvider_8php_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@
<div class="title">AuthServiceProvider.php</div> </div>
</div><!--header-->
<div class="contents">
<a href="AuthServiceProvider_8php.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;&lt;?php</div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;</div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceBristolSU_1_1Playground_1_1Providers.html">BristolSU\Playground\Providers</a>;</div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;</div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;use <a class="code" href="namespaceBristolSU_1_1Support_1_1Authentication_1_1Contracts_1_1Authentication.html">BristolSU\Support\Authentication\Contracts\Authentication</a>;</div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;use <a class="code" href="namespaceIlluminate_1_1Support_1_1ServiceProvider.html">Illuminate\Support\ServiceProvider</a>;</div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;</div><div class="line"><a name="l00011"></a><span class="lineno"><a class="line" href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html"> 11</a></span>&#160;<span class="keyword">class </span><a class="code" href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html">AuthServiceProvider</a> <span class="keyword">extends</span> ServiceProvider</div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;{</div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;</div><div class="line"><a name="l00021"></a><span class="lineno"><a class="line" href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html#aaf089101848c895f1c1c16151cec3ce4"> 21</a></span>&#160; <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html#aaf089101848c895f1c1c16151cec3ce4">boot</a>()</div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160; {</div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160; $this-&gt;app-&gt;bind(Authentication::class, \<a class="code" href="namespaceBristolSU.html">BristolSU</a>\Playground\Support\Authentication\Authentication::class);</div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160; }</div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;}</div><div class="ttc" id="namespaceBristolSU_html"><div class="ttname"><a href="namespaceBristolSU.html">BristolSU</a></div></div>
<div class="ttc" id="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider_html_aaf089101848c895f1c1c16151cec3ce4"><div class="ttname"><a href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html#aaf089101848c895f1c1c16151cec3ce4">BristolSU\Playground\Providers\AuthServiceProvider\boot</a></div><div class="ttdeci">boot()</div><div class="ttdef"><b>Definition:</b> <a href="AuthServiceProvider_8php_source.html#l00021">AuthServiceProvider.php:21</a></div></div>
<a href="AuthServiceProvider_8php.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;&lt;?php</div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;</div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceBristolSU_1_1Playground_1_1Providers.html">BristolSU\Playground\Providers</a>;</div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;</div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;use <a class="code" href="namespaceBristolSU_1_1Playground_1_1Support_1_1Authentication_1_1UserProvider.html">BristolSU\Playground\Support\Authentication\UserProvider</a>;</div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;use <a class="code" href="namespaceBristolSU_1_1Support_1_1Authentication_1_1Contracts_1_1Authentication.html">BristolSU\Support\Authentication\Contracts\Authentication</a>;</div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;use <a class="code" href="namespaceIlluminate_1_1Support_1_1Facades_1_1Auth.html">Illuminate\Support\Facades\Auth</a>;</div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;use <a class="code" href="namespaceIlluminate_1_1Support_1_1ServiceProvider.html">Illuminate\Support\ServiceProvider</a>;</div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;</div><div class="line"><a name="l00013"></a><span class="lineno"><a class="line" href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html"> 13</a></span>&#160;<span class="keyword">class </span><a class="code" href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html">AuthServiceProvider</a> <span class="keyword">extends</span> ServiceProvider</div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;{</div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;</div><div class="line"><a name="l00023"></a><span class="lineno"><a class="line" href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html#aaf089101848c895f1c1c16151cec3ce4"> 23</a></span>&#160; <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html#aaf089101848c895f1c1c16151cec3ce4">boot</a>()</div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160; {</div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160; $this-&gt;app-&gt;bind(Authentication::class, \<a class="code" href="namespaceBristolSU.html">BristolSU</a>\Playground\Support\Authentication\Authentication::class);</div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;</div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160; Auth::provider(<span class="stringliteral">&#39;data-user-provider&#39;</span>, <span class="keyword">function</span>($app) {</div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160; <span class="keywordflow">return</span> $app-&gt;make(UserProvider::class);</div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160; });</div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160; }</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160;}</div><div class="ttc" id="namespaceBristolSU_html"><div class="ttname"><a href="namespaceBristolSU.html">BristolSU</a></div></div>
<div class="ttc" id="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider_html_aaf089101848c895f1c1c16151cec3ce4"><div class="ttname"><a href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html#aaf089101848c895f1c1c16151cec3ce4">BristolSU\Playground\Providers\AuthServiceProvider\boot</a></div><div class="ttdeci">boot()</div><div class="ttdef"><b>Definition:</b> <a href="AuthServiceProvider_8php_source.html#l00023">AuthServiceProvider.php:23</a></div></div>
<div class="ttc" id="namespaceIlluminate_1_1Support_1_1ServiceProvider_html"><div class="ttname"><a href="namespaceIlluminate_1_1Support_1_1ServiceProvider.html">ServiceProvider</a></div></div>
<div class="ttc" id="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider_html"><div class="ttname"><a href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html">BristolSU\Playground\Providers\AuthServiceProvider</a></div><div class="ttdef"><b>Definition:</b> <a href="AuthServiceProvider_8php_source.html#l00011">AuthServiceProvider.php:11</a></div></div>
<div class="ttc" id="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider_html"><div class="ttname"><a href="classBristolSU_1_1Playground_1_1Providers_1_1AuthServiceProvider.html">BristolSU\Playground\Providers\AuthServiceProvider</a></div><div class="ttdef"><b>Definition:</b> <a href="AuthServiceProvider_8php_source.html#l00013">AuthServiceProvider.php:13</a></div></div>
<div class="ttc" id="namespaceBristolSU_1_1Playground_1_1Support_1_1Authentication_1_1UserProvider_html"><div class="ttname"><a href="namespaceBristolSU_1_1Playground_1_1Support_1_1Authentication_1_1UserProvider.html">UserProvider</a></div></div>
<div class="ttc" id="namespaceIlluminate_1_1Support_1_1Facades_1_1Auth_html"><div class="ttname"><a href="namespaceIlluminate_1_1Support_1_1Facades_1_1Auth.html">Auth</a></div></div>
<div class="ttc" id="namespaceBristolSU_1_1Support_1_1Authentication_1_1Contracts_1_1Authentication_html"><div class="ttname"><a href="namespaceBristolSU_1_1Support_1_1Authentication_1_1Contracts_1_1Authentication.html">Authentication</a></div></div>
<div class="ttc" id="namespaceBristolSU_1_1Playground_1_1Providers_html"><div class="ttname"><a href="namespaceBristolSU_1_1Playground_1_1Providers.html">BristolSU\Playground\Providers</a></div><div class="ttdef"><b>Definition:</b> <a href="AppServiceProvider_8php_source.html#l00003">AppServiceProvider.php:3</a></div></div>
</div><!-- fragment --></div><!-- contents -->
Expand Down
Loading

0 comments on commit 6143241

Please sign in to comment.