diff --git a/CHANGELOG.md b/CHANGELOG.md index afa5619..9287162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d6e4b70 --- /dev/null +++ b/Dockerfile @@ -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 + diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index d932b7d..6dc372a 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -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'], ]); } @@ -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(); diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 7a7f48e..68bb3b4 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -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; /** @@ -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); + }); } } diff --git a/app/Support/Authentication/UserProvider.php b/app/Support/Authentication/UserProvider.php new file mode 100644 index 0000000..55be660 --- /dev/null +++ b/app/Support/Authentication/UserProvider.php @@ -0,0 +1,115 @@ +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; + } +} diff --git a/config/auth.php b/config/auth.php index 9a4631a..43e04be 100644 --- a/config/auth.php +++ b/config/auth.php @@ -40,12 +40,12 @@ 'guards' => [ 'web' => [ 'driver' => 'session', - 'provider' => 'users', + 'provider' => 'data-users', ], 'api' => [ 'driver' => 'passport', - 'provider' => 'users', + 'provider' => 'data-users', ], 'activity-instance' => [ @@ -82,6 +82,10 @@ 'model' => ActivityInstance::class ], + 'data-users' => [ + 'driver' => 'data-user-provider', + 'model' => \BristolSU\Support\User\User::class, + ] // 'users' => [ // 'driver' => 'database', diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a2d68be --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/docs/AuthServiceProvider_8php_source.html b/docs/AuthServiceProvider_8php_source.html index 90915d6..761a4c0 100644 --- a/docs/AuthServiceProvider_8php_source.html +++ b/docs/AuthServiceProvider_8php_source.html @@ -66,10 +66,12 @@
+ Bristol SU Playground
+
+ |
+
Go to the source code of this file.
++Classes | |
class | BristolSU\Playground\Support\Authentication\UserProvider |
+Namespaces | |
BristolSU\Playground\Support\Authentication | |
+ Bristol SU Playground
+
+ |
+
Authentication Service Provider
-Definition at line 11 of file AuthServiceProvider.php.
+Definition at line 13 of file AuthServiceProvider.php.
Definition at line 21 of file AuthServiceProvider.php.
+Definition at line 23 of file AuthServiceProvider.php.
+ Bristol SU Playground
+
+ |
+
This is the complete list of members for BristolSU\Playground\Support\Authentication\UserProvider, including all inherited members.
+$userRepository | BristolSU\Playground\Support\Authentication\UserProvider | private |
__construct(UserRepository $userRepository) | BristolSU\Playground\Support\Authentication\UserProvider | |
retrieveByCredentials(array $credentials) | BristolSU\Playground\Support\Authentication\UserProvider | |
retrieveById($email) | BristolSU\Playground\Support\Authentication\UserProvider | |
retrieveByToken($email, $token) | BristolSU\Playground\Support\Authentication\UserProvider | |
updateRememberToken(Authenticatable $user, $token) | BristolSU\Playground\Support\Authentication\UserProvider | |
validateCredentials(Authenticatable $user, array $credentials) | BristolSU\Playground\Support\Authentication\UserProvider |
+ Bristol SU Playground
+
+ |
+
+Public Member Functions | |
__construct (UserRepository $userRepository) | |
retrieveById ($email) | |
retrieveByToken ($email, $token) | |
updateRememberToken (Authenticatable $user, $token) | |
retrieveByCredentials (array $credentials) | |
validateCredentials (Authenticatable $user, array $credentials) | |
+Private Attributes | |
$userRepository | |
Definition at line 12 of file UserProvider.php.
+BristolSU\Playground\Support\Authentication\UserProvider::__construct | +( | +UserRepository | +$userRepository | ) | ++ |
Definition at line 20 of file UserProvider.php.
+ +References BristolSU\Playground\Support\Authentication\UserProvider\$userRepository.
+ +BristolSU\Playground\Support\Authentication\UserProvider::retrieveByCredentials | +( | +array | +$credentials | ) | ++ |
Retrieve a user by the given credentials.
+array | $credentials |
Definition at line 75 of file UserProvider.php.
+ +BristolSU\Playground\Support\Authentication\UserProvider::retrieveById | +( | ++ | ) | ++ |
Retrieve a user by their unique email.
+mixed |
Definition at line 31 of file UserProvider.php.
+ +BristolSU\Playground\Support\Authentication\UserProvider::retrieveByToken | +( | ++ | $email, | +
+ | + | + | $token | +
+ | ) | ++ |
Retrieve a user by their unique email and "remember me" token.
+mixed | ||
string | $token |
Definition at line 46 of file UserProvider.php.
+ +BristolSU\Playground\Support\Authentication\UserProvider::updateRememberToken | +( | +Authenticatable | +$user, | +
+ | + | + | $token | +
+ | ) | ++ |
Update the "remember me" token for the given user in storage.
+Authenticatable | User | $user | |
string | $token |
Definition at line 64 of file UserProvider.php.
+ +BristolSU\Playground\Support\Authentication\UserProvider::validateCredentials | +( | +Authenticatable | +$user, | +
+ | + | array | +$credentials | +
+ | ) | ++ |
Validate a user against the given credentials.
+\Illuminate\Contracts\Auth\Authenticatable | User | $user | |
array | $credentials |
Definition at line 108 of file UserProvider.php.
+ +
+
|
+ +private | +
Definition at line 18 of file UserProvider.php.
+ +Referenced by BristolSU\Playground\Support\Authentication\UserProvider\__construct().
+ +