Skip to content

Commit

Permalink
Merge pull request #31 from codebar-ag/feature-updates
Browse files Browse the repository at this point in the history
Feature Updates
  • Loading branch information
StanBarrows authored Oct 20, 2023
2 parents 8cb4b79 + a7d7c2e commit ca7bae7
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 64 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ return [
|
*/
'providers' => [
'disabled' => [
// ProviderEnum::MICROSOFT_OFFICE_365(),
],
ProviderEnum::MICROSOFT_OFFICE_365(),
],


Expand All @@ -311,6 +309,8 @@ return [
|
*/
'features' => [
'basic' => true,
'sso' => true,
'password_reset' => true,
'email_verification' => true,
],
Expand Down
10 changes: 5 additions & 5 deletions config/laravel-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@
|--------------------------------------------------------------------------
| Provider Settings
|--------------------------------------------------------------------------
| By default, all providers are enabled.
| You may disable a provider by adding it to the disabled array.
| Add the providers you want to use here.
| e.g ProviderEnum::MICROSOFT_OFFICE_365(),
|
*/
'providers' => [
'disabled' => [
ProviderEnum::MICROSOFT_OFFICE_365(),
],
ProviderEnum::MICROSOFT_OFFICE_365(),
],

/*
Expand All @@ -104,6 +102,8 @@
|
*/
'features' => [
'basic' => true,
'sso' => true,
'password_reset' => true,
'email_verification' => true,
],
Expand Down
2 changes: 1 addition & 1 deletion resources/dist/authcss.css

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions resources/views/components/flash-message.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@props(['message', 'status'])

<div x-data="{ show: true }" x-show="show" x-init="setTimeout(() => show = false, {{ config('laravel-auth.toast_fade_time_in_milliseconds') }})"
<div x-data="{ show: true }" x-show="show"
{{--<div x-data="{ show: true }" x-show="show" x-init="setTimeout(() => show = false, {{ config('laravel-auth.toast_fade_time_in_milliseconds') }})"--}}
x-transition:enter="transform ease-out duration-3000 transition"
x-transition:enter-start="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
x-transition:enter-end="translate-y-0 opacity-100 sm:translate-x-0"
Expand All @@ -13,13 +14,13 @@
<div class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5">
<div class="p-4">
<div class="flex items-center">
<div class="flex w-0 flex-1 justify-between items-center">
<div class="flex w-0 flex-1 justify-between items-center space-x-4">
@if($status == 'success')
<svg class="w-4 h-4 text-green-500 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<svg class="w-8 h-8 text-green-500 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm13.36-1.814a.75.75 0 10-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.14-.094l3.75-5.25z" clip-rule="evenodd"/>
</svg>
@else
<svg class="w-4 h-4 text-red-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<svg class="w-8 h-8nrb text-red-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M12 2.25c-5.385 0-9.75 4.365-9.75 9.75s4.365 9.75 9.75 9.75 9.75-4.365 9.75-9.75S17.385 2.25 12 2.25zm-1.72 6.97a.75.75 0 10-1.06 1.06L10.94 12l-1.72 1.72a.75.75 0 101.06 1.06L12 13.06l1.72 1.72a.75.75 0 101.06-1.06L13.06 12l1.72-1.72a.75.75 0 10-1.06-1.06L12 10.94l-1.72-1.72z" clip-rule="evenodd"/>
</svg>
@endif
Expand Down
3 changes: 1 addition & 2 deletions resources/views/components/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">

<link rel="stylesheet" href="{{ asset('vendor/auth/authcss.css') }}">

<title>{{ config('app.name') }}</title>

<link rel="stylesheet" href="{{ asset('vendor/auth/authcss.css') }}">
<script src="{{ asset('vendor/auth/authjs.js') }}" defer></script>
</head>

Expand Down
92 changes: 49 additions & 43 deletions resources/views/login.blade.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
<x-auth::layout>
<h2 class="mt-6 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">{{ __('auth::translations.login') }}</h2>

<form class="mt-8 space-y-4" action="{{ route('auth.login.store') }}" method="POST">
@csrf
@honeypot
@if(config('laravel-auth.features.basic'))
<form class="mt-8 space-y-4" action="{{ route('auth.login.store') }}" method="POST">
@csrf
@honeypot

<x-auth::form.input
type="email"
name="email"
:label="__('auth::translations.email')"
:placeholder="__('auth::translations.email')"
autocomplete="email"
:required="true"
:required-badge="false"
:autofocus="true"
/>

<x-auth::form.password
name="password"
:label="__('auth::translations.password')"
:placeholder="__('auth::translations.password')"
autocomplete="password"
:required="true"
:required-badge="false"
/>
<x-auth::form.input
type="email"
name="email"
:label="__('auth::translations.email')"
:placeholder="__('auth::translations.email')"
autocomplete="email"
:required="true"
:required-badge="false"
:autofocus="true"
/>

<div class="flex items-center justify-between">
<x-auth::form.checkbox
name="remember"
:label="__('auth::translations.remember-me')"
<x-auth::form.password
name="password"
:label="__('auth::translations.password')"
:placeholder="__('auth::translations.password')"
autocomplete="password"
:required="true"
:required-badge="false"
/>

@if(config('laravel-auth.features.password_reset'))
<div class="flex items-center">
<a href="{{ route('auth.request-password') }}"
class="block text-sm text-gray-900 hover:text-gray-500 underline">{{ __('auth::translations.forgot-password') }}</a>
</div>
@endif
</div>
<div class="flex items-center justify-between">
<x-auth::form.checkbox
name="remember"
:label="__('auth::translations.remember-me')"
/>

<div class="space-y-4">
<x-auth::form.button.button>
{{ __('auth::translations.sign-in') }}
</x-auth::form.button.button>
@if(config('laravel-auth.features.password_reset'))
<div class="flex items-center">
<a href="{{ route('auth.request-password') }}" class="block text-sm text-gray-900 hover:text-gray-500 underline">
{{ __('auth::translations.forgot-password') }}
</a>
</div>
@endif
</div>

@if(! in_array(\CodebarAg\LaravelAuth\Enums\ProviderEnum::MICROSOFT_OFFICE_365(), config('laravel-auth.providers.disabled')))
<div class="space-y-4">
<x-auth::form.button.button>
{{ __('auth::translations.sign-in') }}
</x-auth::form.button.button>
</div>
</form>
@endif

<div class="space-y-4">
@if(config('laravel-auth.features.sso'))
@if(in_array(\CodebarAg\LaravelAuth\Enums\ProviderEnum::MICROSOFT_OFFICE_365(), config('laravel-auth.providers')))
<x-auth::form.button.ahref
:href="route('auth.provider', \CodebarAg\LaravelAuth\Enums\ProviderEnum::MICROSOFT_OFFICE_365())"
class="bg-gray-500 hover:bg-gray-400"
:href="route('auth.provider', \CodebarAg\LaravelAuth\Enums\ProviderEnum::MICROSOFT_OFFICE_365())"
class="bg-gray-500 hover:bg-gray-400"
>
<svg class="fill-white w-4 h-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 278050 333334" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd" clip-rule="evenodd"><path fill="currentColor" d="M278050 305556l-29-16V28627L178807 0 448 66971l-448 87 22 200227 60865-23821V80555l117920-28193-17 239519L122 267285l178668 65976v73l99231-27462v-316z"/></svg>
<span>{{ __('auth::translations.sign-in-with-microsoft') }}</span>
</x-auth::form.button.ahref>
@endif
</div>

</form>
@endif
</div>
</x-auth::layout>
8 changes: 5 additions & 3 deletions routes/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
Route::get('/')->uses([LoginController::class, 'index'])
->name('login');

Route::post('/store')->uses([LoginController::class, 'store'])
->middleware(ProtectAgainstSpam::class)
->name('login.store');
if (config('laravel-auth.features.basic')) {
Route::post('/store')->uses([LoginController::class, 'store'])
->middleware(ProtectAgainstSpam::class)
->name('login.store');
}
});

if (config('laravel-auth.features.password_reset')) {
Expand Down
10 changes: 8 additions & 2 deletions src/Controllers/ProviderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function serviceRedirect($service)

protected function allowed($provider)
{
if (in_array($provider->value, config('laravel-auth.providers.disabled'))) {
if (! in_array($provider->value, config('laravel-auth.providers'))) {
abort(503);
}
}
Expand All @@ -47,7 +47,13 @@ public function microsoft()

public function microsoftRedirect()
{
$socialiteUser = Socialite::driver(ProviderEnum::MICROSOFT_OFFICE_365()->value)->user();
try {
$socialiteUser = Socialite::driver(ProviderEnum::MICROSOFT_OFFICE_365()->value)->user();
} catch (\Exception $e) {
flash(__('Authentication Error.'), 'warning');

return redirect()->route('auth.login');
}

$provider = AuthProvider::updateOrCreate(
[
Expand Down
3 changes: 2 additions & 1 deletion src/Models/AuthProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class AuthProvider extends Model
'provider_id',
'name',
'email',
'token',
'refresh_token',
];

protected $casts = [
Expand All @@ -36,6 +38,5 @@ public function __construct(array $attributes = [])
public function user(): BelongsTo
{
return $this->belongsTo(config('laravel-auth.model.user'));

}
}

0 comments on commit ca7bae7

Please sign in to comment.