Skip to content

Commit

Permalink
🧑‍💻 Add interface for OAuth Client Creation (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin authored Oct 15, 2022
1 parent a690025 commit 031e8bc
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 0 deletions.
88 changes: 88 additions & 0 deletions app/Http/Controllers/Frontend/DevController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use http\Client;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Laravel\Passport\Http\Controllers\ClientController;
use Laravel\Passport\ClientRepository;

class DevController extends Controller
{
public function renderAppList(): View {
$clients = new ClientRepository();

$userId = request()->user()->getAuthIdentifier();

return view('dev.apps', [
'apps' => $clients->activeForUser($userId),
]);
}

public function renderUpdateApp(int $appId): View {
$clients = new ClientRepository();
$app = $clients->findForUser($appId, auth()->user()->id);

if (!$app) {
abort(404);
}
return view('dev.apps-edit', [
'title' => 'Anwendung bearbeiten', //ToDo Übersetzen
'app' => $app,
]);
}

public function renderCreateApp(): View {
return view('dev.apps-edit', [
'title' => 'Anwendung erstellen', //ToDo Übersetzen
'app' => null
]);
}

public function updateApp(int $appId, Request $request): RedirectResponse {
$validated = $request->validate([
'name' => ['required', 'string'],
'redirect' => ['required', 'string'],
]);

$clients = new ClientRepository();
$app = $clients->findForUser($appId, auth()->user()->id);

if (!$app) {
abort(404);
}

$clients->update($app, $validated['name'], $validated['redirect']);

return redirect(route('dev.apps'))->with('success', __('settings.saved'));
}

public function createApp(Request $request): RedirectResponse {
$validated = $request->validate([
'name' => ['required', 'string'],
'redirect' => ['required', 'string'],
]);

$clients = new ClientRepository();
$clients->create(auth()->user()->id, $validated['name'], $validated['redirect']);

return redirect(route('dev.apps'))->with('success', __('settings.saved'));
}

public function destroyApp(int $appId): RedirectResponse {
$clients = new ClientRepository();
$app = $clients->findForUser($appId, auth()->user()->id);

if (!$app) {
abort(404);
}
$clients->delete($app);

return redirect(route('dev.apps'))->with('success', __('settings.saved'));
}

}
60 changes: 60 additions & 0 deletions resources/views/dev/apps-edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@extends('layouts.settings')

@section('title', request()->is('dev.apps.create') ? 'Anwendung erstellen' : 'Anwendung bearbeiten') <!-- ToDo: Übersetzen -->

@section('content')
<div class="row">
<form enctype="multipart/form-data" method="POST"
@if(Route::currentRouteName() === 'dev.apps.create')
action="{{ route('dev.apps.create.post') }}">
@else
action="{{ route('dev.apps.edit', ['appId' => $app->id]) }}">
<div class="row my-2">
<table class="table table-striped table-dark">
<tr>
<td>Client Id</td>
<td><code>{{ $app->id }}</code></td>
</tr>
<tr>
<td>Client Secret</td>
<td><code>{{ $app->secret }}</code></td>
</tr>
</table>
<hr>
</div>
@endif
@csrf
<div class="form-group row my-1">
<label for="name" class="col-md-4 col-form-label text-md-right">
Name
</label>

<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" placeholder="My Application" required
value="{{ $app ? $app->name : '' }}" autofocus>
</div>
</div>

<div class="form-group row my-1">
<label for="redirect" class="col-md-4 col-form-label text-md-right">
Redirect URL
</label>
<div class="col-md-6">
<input id="redirect" type="text" class="form-control" name="redirect" placeholder="https://example.com/callback" required value="{{ $app ? $app->redirect : ''}}">
</div>
</div>

<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
@if(Route::currentRouteName() === 'dev.apps.create')
Erstellen
@else
Aktualisieren
@endif
</button>
</div>
</div>
</form>
</div>
@endsection
126 changes: 126 additions & 0 deletions resources/views/dev/apps.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
@extends('layouts.settings')

@section('title', 'Deine Anwendungen')

@section('additional-content-end')
<a href="{{ route('dev.apps.create') }}" class="btn btn-outline-primary">Anwendung erstellen</a>
@endsection

@section('content')
<div class="row">
@if($app)
<table class="table table-striped table-dark">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Redirect URL</th>
<th scope="col">&nbsp;</th>
</tr>
</thead>
<tbody>

@foreach($apps as $app)
<tr>
<td><a href="{{route('dev.apps.edit', ['appId' => $app->id])}}">{{ $app->name }}</a></td>
<td>{{ $app->redirect }}</td>
<form action="{{ route('dev.apps.destroy', ['appId' => $app->id]) }}" method="post"
onsubmit="return confirm('Are you sure you want to delete \'{{$app->name}}\'?');">
@csrf
<td>
<button type="submit" class="btn btn-sm btn-link">
<i class="fa fa-times"></i> Löschen
</button>
</td>
</form>
</tr>
@endforeach
</tbody>
</table>
@else
Du hast noch keine Apps angelegt
@endif
<!--
<div class="my-4">
<strong class="mb-0">Security</strong>
<p>Control security alert you will be notified.</p>
<div class="list-group mb-5 shadow">
<div class="list-group-item">
<div class="row align-items-center">
<div class="col">
<strong class="mb-0">Unusual activity notifications</strong>
<p class="text-muted mb-0">Donec in quam sed urna bibendum tincidunt quis mollis mauris.</p>
</div>
<div class="col-auto">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="alert1" checked="" />
<span class="custom-control-label"></span>
</div>
</div>
</div>
</div>
<div class="list-group-item">
<div class="row align-items-center">
<div class="col">
<strong class="mb-0">Unauthorized financial activity</strong>
<p class="text-muted mb-0">Fusce lacinia elementum eros, sed vulputate urna eleifend nec.</p>
</div>
<div class="col-auto">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="alert2" />
<span class="custom-control-label"></span>
</div>
</div>
</div>
</div>
</div>
<hr class="my-4" />
<strong class="mb-0">System</strong>
<p>Please enable system alert you will get.</p>
<div class="list-group mb-5 shadow">
<div class="list-group-item">
<div class="row align-items-center">
<div class="col">
<strong class="mb-0">Notify me about new features and updates</strong>
<p class="text-muted mb-0">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="col-auto">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="alert3" checked="" />
<span class="custom-control-label"></span>
</div>
</div>
</div>
</div>
<div class="list-group-item">
<div class="row align-items-center">
<div class="col">
<strong class="mb-0">Notify me by email for latest news</strong>
<p class="text-muted mb-0">Nulla et tincidunt sapien. Sed eleifend volutpat elementum.</p>
</div>
<div class="col-auto">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="alert4" checked="" />
<span class="custom-control-label"></span>
</div>
</div>
</div>
</div>
<div class="list-group-item">
<div class="row align-items-center">
<div class="col">
<strong class="mb-0">Notify me about tips on using account</strong>
<p class="text-muted mb-0">Donec in quam sed urna bibendum tincidunt quis mollis mauris.</p>
</div>
<div class="col-auto">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="alert5" />
<span class="custom-control-label"></span>
</div>
</div>
</div>
</div>
</div>
</div>
-->
</div>
@endsection
115 changes: 115 additions & 0 deletions resources/views/layouts/settings.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>@yield('title') - {{ config('app.name', 'Träwelling') }}</title>

@include('layouts.includes.meta')

<!-- Scripts -->
<script src="{{ mix('js/app.js') }}"></script>

<!-- Fonts -->
<link href="{{ asset('fonts/Nunito/Nunito.css') }}" rel="stylesheet">

<!-- Styles -->
<link href="{{ mix('css/admin.css') }}" rel="stylesheet">
<link rel="mask-icon" href="{{ asset('images/icons/touch-icon-vector.svg') }}">
<link rel="shortcut favicon" href="{{ asset('images/icons/favicon.ico') }}">
<link rel="shortcut icon" sizes="512x512" href="{{ asset('images/icons/logo512.png') }}">
<link rel="shortcut icon" sizes="128x128" href="{{ asset('images/icons/logo128.png') }}">
<link rel="author" href="/humans.txt">
<link rel="manifest" href="/manifest.json"/>

@yield('head')
</head>
<body>
@include('includes.message-block')
<main class="bg-dark">
<div class="d-flex flex-column col-3 d-none d-md-flex"></div>

<div class="d-flex flex-column flex-shrink-0 p-2 text-white bg-dark" style="max-width: 280px;">
<a href="{{ route('dashboard') }}"
class="justify-content-center mb-3 mx-auto text-white text-decoration-none">
<img src="{{ asset('images/icons/touch-icon-vector.svg') }}" alt="{{ config('app.name') }} Logo"
class="brand-image me-3" style="width: 110px">
</a>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a href="{{ route('dashboard') }}" class="nav-link text-muted">
<i class="fas fa-backward me-2" aria-hidden="true"></i>
<span class="d-none d-lg-inline">Zurück zu Träwelling</span>
</a>
</li>
<!--
<li>
<a href="#"
class="nav-link text-white {{ request()->is('admin') ? 'active' : '' }}">
<i class="fas fa-user me-2" aria-hidden="true"></i>
<span class="d-none d-lg-inline">Profil</span>
</a>
</li>
<li>
<a href="#"
class="nav-link text-white {{ request()->is('admin/events*') ? 'active' : '' }}">
<i class="fas fa-lock me-2" aria-hidden="true"></i>
<span class="d-none d-lg-inline">Privacy</span>
</a>
</li>
<li>
<a href="#"
class="nav-link text-white {{ request()->is('admin/status*') ? 'active' : '' }}">
<i class="fas fa-lock me-2" aria-hidden="true"></i>
<span class="d-none d-lg-inline">Zugänge</span>
</a>
</li>
-->
<li>
<a href="{{ route('dev.apps') }}"
class="nav-link text-white {{ request()->is('settings/applications*') ? 'active' : '' }}">
<i class="fas fa-code me-2" aria-hidden="true"></i>
<span class="d-none d-lg-inline">Develop <span
class="badge text-bg-warning">beta</span></span>
</a>
</li>
<li>
<a href="{{ route('l5-swagger.default.api') }}" target="_blank"
class="nav-link text-white ms-2 {{ request()->is('settings/applications*') ? '' : 'd-none' }}">
<i class="fas fa-flask me-2" aria-hidden="true"></i>
<span class="d-none d-lg-inline">API Docs <span
class="badge text-bg-danger">incomplete</span></span></span>
</a>
</li>
<hr>
<li>
<a href="#"
class="nav-link text-white {{ request()->is('admin/api/usage*') ? 'active' : '' }}">
<i class="fa-solid fa-sign-out-alt me-2" aria-hidden="true"></i>
<span class="d-none d-lg-inline">Logout</span>
</a>
</li>
</ul>
</div>

<div class="container-fluid bg-light px-5 pt-4 bg-light-gray" style="overflow-y: scroll !important;">
<div class="row">
<div class="col-12 col-lg-10 col-xl-8 ">
<div class="my-4">
<span class="float-end">
@yield('additional-content-end')
</span>
<h4 class="mb-0 mt-5">@yield('title')</h4>
<p>@yield('subtitle')</p>

<hr class="my-4"/>
@yield('content')
</div>
</div>
</div>
</div>
</main>
</body>

@include('includes.modals.notifications-board')
@yield('footer')
</html>
Loading

0 comments on commit 031e8bc

Please sign in to comment.