- Remove Risk WPAutoLogin component (is now included in WPAutoLogin component)

- Fix LoginIdComponent usage
This commit is contained in:
Jérémy Munsch 2022-06-13 15:40:33 +02:00
parent c6e15928f1
commit 4441f6d547
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC
12 changed files with 149 additions and 59 deletions

View file

@ -22,15 +22,6 @@ class ProjectsController extends Controller
return view('projects.index', ['projects' => $projects]);
}
public function WpAutoLogin(Request $request)
{
$url = $request->url;
$login = $request->login;
$pwd = $request->pwd;
return view('projects.wp-auto-login', ['url' => $url, 'login' => $login, 'pwd' => $pwd]);
}
public function add(Request $request)
{
$dev_db_server = Servers::where([

View file

@ -7,6 +7,16 @@ use Illuminate\Database\Eloquent\Model;
class Projects extends Model
{
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'dev_login' => 'array',
'prod_login' => 'array'
];
public function getDevWebIpAttribute() {
$value = Servers::find($this->dev_web_server_id);
if ($value)

View file

@ -0,0 +1,77 @@
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\ServiceProvider;
class TranslationServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
foreach ($this->collectLocalesStrings() as $locale) {
// * Suported locales
Cache::rememberForever(sprintf('translations.%s', $locale), function () use ($locale) {
$translations = [
'php' => $this->phpTranslations($locale),
'json' => $this->jsonTranslations($locale),
];
return $translations;
});
}
}
/**
* Gather provided langs checking from files
*
* @return Collection
*/
private function collectLocalesStrings(): Collection
{
return collect(File::allFiles(resource_path('lang/')))->flatMap(function ($file) {
if ($file->getRelativePath()) {
return [$file->getRelativePath() => ''];
}
})->keys();
}
/**
* Gather all php translations
*
* @param string $locale
* @return array
*/
private function phpTranslations(string $locale): array
{
$path = resource_path("lang/$locale");
return collect(File::allFiles($path))->flatMap(function ($file) use ($locale) {
$translation = $file->getBasename('.php');
return [$translation => trans($translation, [], $locale)];
})->all();
}
/**
* Gather json translations
*
* @param string $locale
* @return array
*/
private function jsonTranslations(string $locale): array
{
$path = resource_path("lang/$locale.json");
if (is_string($path) && is_readable($path)) {
return json_decode(file_get_contents($path), true) ?? [];
}
return [];
}
}

View file

@ -174,6 +174,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\TranslationServiceProvider::class,
App\Providers\MailjetSmsServiceProvider::class,
],

View file

@ -31,14 +31,13 @@
></a>
</div>
<div v-if="type === 2" class="col-md-2">
<a
:href="`/projects/wp-auto-login?url=${url}wp-login.php&login=${String(
item.login
)}&pwd=${String(item.pwd)}`"
target="_blank"
class="btn btn-success"
><i class="fa fa-sign-in-alt"></i
></a>
<form ref="login" :action="url" method="POST">
<button class="btn btn-success">
<i class="fa fa-sign-in-alt"></i>
</button>
<input type="hidden" name="log" :value="String(item.login)" />
<input type="hidden" name="pwd" :value="String(item.pwd)" />
</form>
</div>
</div>
</div>

View file

@ -1,36 +0,0 @@
<template>
<form ref="login" :action="url" method="POST">
<input type="hidden" name="log" :value="login" />
<input type="hidden" name="pwd" :value="pwd" />
</form>
</template>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
beforeMount() {
if (!this.$attrs.json) {
throw new Error("this component requires json");
}
},
mounted() {
const json = String(this.$attrs.json ?? ""),
data = JSON.parse(json);
this.login = data.login;
this.url = data.url;
this.pwd = data.pwd;
(this.$refs.login as HTMLFormElement).submit();
},
data(): {
login: string;
url: string;
pwd: string;
} {
return {
login: "",
pwd: "",
url: "",
};
},
});
</script>

View file

@ -35,5 +35,14 @@ declare global {
interface Window {
axios: AxiosStatic;
Swal: Function;
__SYSTEM: {
_asset: string;
_locale: string;
_routes: Record<string, string>;
_translations: {
json: NestedStringList;
php: NestedStringList;
};
};
}
}

View file

@ -78,7 +78,12 @@
<main class="py-4">
@yield('content')
</main>
<script src="{{ mix('js/back.js') }}" defer></script>
@stack('scriptsConstants')
@include('modules.scriptConstants')
<script src="{{ mix('js/back.js') }}"></script>
<script src="{{ mix('js/fontawesome.min.js') }}"></script>
@stack('scripts')
</div>
</body>
</html>

View file

@ -0,0 +1,11 @@
<script @if(isset($nonce)) nonce="{{ $nonce }}" @endif>
if (!window.__SYSTEM) {
window.__SYSTEM = {};
}
window.__SYSTEM._locale = '{{ app()->getLocale() }}';
window.__SYSTEM._translations = @json(cache(sprintf('translations.%s', app()->getLocale())) ?? []);
window.__SYSTEM._asset = '{{ asset('') }}';
if(!window.__SYSTEM._routes) {
window.__SYSTEM._routes = {}
}
</script>

View file

@ -71,10 +71,26 @@
</div>
<div class="row">
<div class="col-md-6">
<login-id name="dev_login" dbdatas="{{ old('dev_login', optional($project)->dev_login ?? '[]') }}"@if($project) url="{{$project->dev_url}}" :type="{{$project->type}}" @endif/>
@php
$data = [
'name' => 'dev_login',
'url' => $project->dev_bo_url ?? '',
'type' => $project->type ?? '',
'dataList' => old('dev_login', optional($project)->dev_login ?? '[]')
];
@endphp
<div class="login-id" data-json='@json($data)'></div>
</div>
<div class="col-md-6">
<login-id name="prod_login" dbdatas="{{ old('prod_login', optional($project)->prod_login ?? '[]') }}" @if($project) url="{{$project->prod_url}}" :type="{{$project->type}}" @endif/>
@php
$data = [
'name' => 'prod_login',
'url' => $project->prod_bo_url ?? '',
'type' => $project->type ?? '',
'dataList' => old('prod_login', optional($project)->prod_login ?? '[]')
];
@endphp
<div class="login-id" data-json='@json($data)'></div>
</div>
</div>
@endif

View file

@ -1,11 +1,19 @@
@extends('layouts.app')
@section('content')
<wp-auto-login url="{{$url}}" login="{{$login}}" pwd="{{$pwd}}"></wp-auto-login>
@php
$data = [
'name' => 'dev_login',
'url' => $url,
'login' => $login,
'pwd' => $pwd
];
@endphp
<div id="wp-auto-login" data-json='@json($data)'></div>
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<h1>Connexion en cours...</h1>
<h1>{{ __('Connexion en cours') }}...</h1>
</div>
</div>
</div>

View file

@ -32,7 +32,6 @@ Route::group(['middleware' => ['auth']], function () {
Route::post('/projects/{uuid}/force-delete', 'ProjectsController@forceDelete');
Route::get('/projects/add', 'ProjectsController@add');
Route::post('/projects/store', 'ProjectsController@store');
Route::get('/projects/wp-auto-login', 'ProjectsController@WpAutoLogin')->name('projects.wp-auto-login');
/* SERVERS */
Route::get('/servers', 'ServersController@index')->name('servers.index');
Route::post('/servers/store', 'ServersController@store')->name('servers.store');