mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-01-17 13:18:21 +01:00
Add account creation and complete view to the setup
This commit is contained in:
parent
da9de76389
commit
9b139a7d6f
@ -4,8 +4,7 @@ namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
|
||||
class RegisterController extends Controller
|
||||
@ -44,29 +43,21 @@ class RegisterController extends Controller
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
* @return Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
protected function validator(array $data): Validator
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
]);
|
||||
return User::validateRegistration($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \App\Models\User
|
||||
* @return User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
protected function create(array $data): User
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
return User::createUser($data);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,9 @@
|
||||
namespace App\Http\Controllers\Setup;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\View\View;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
|
||||
/**
|
||||
* Class AccountController
|
||||
@ -13,11 +14,25 @@ use Illuminate\View\View;
|
||||
*/
|
||||
class AccountController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
use RegistersUsers;
|
||||
|
||||
protected function redirectTo()
|
||||
{
|
||||
return route('setup.complete');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('setup.account');
|
||||
}
|
||||
|
||||
protected function validator(array $data): Validator
|
||||
{
|
||||
return User::validateRegistration($data);
|
||||
}
|
||||
|
||||
protected function create(array $data): User
|
||||
{
|
||||
return User::createUser($data);
|
||||
}
|
||||
}
|
||||
|
35
app/Http/Controllers/Setup/MetaController.php
Normal file
35
app/Http/Controllers/Setup/MetaController.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Setup;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
/**
|
||||
* Class WelcomeController
|
||||
*
|
||||
* @package App\Http\Controllers\Setup
|
||||
*/
|
||||
class MetaController extends Controller
|
||||
{
|
||||
public function welcome()
|
||||
{
|
||||
return view('setup.welcome');
|
||||
}
|
||||
|
||||
public function complete()
|
||||
{
|
||||
$this->markSetupCompleted();
|
||||
|
||||
return view('setup.complete');
|
||||
}
|
||||
|
||||
protected function markSetupCompleted()
|
||||
{
|
||||
$envContent = File::get(base_path('.env'));
|
||||
|
||||
$envContent = str_replace('SETUP_COMPLETED=false', 'SETUP_COMPLETED=true', $envContent);
|
||||
|
||||
File::put(base_path('.env'), $envContent);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Setup;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* Class WelcomeController
|
||||
*
|
||||
* @package App\Http\Controllers\Setup
|
||||
*/
|
||||
class WelcomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('setup.welcome');
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ class SetupCheckMiddleware
|
||||
|
||||
if (env('SETUP_COMPLETED', false) !== true) {
|
||||
// Start the setup if it was not completed yet
|
||||
return redirect()->route('setup.start');
|
||||
return redirect()->route('setup.welcome');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -4,6 +4,9 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
|
||||
|
||||
/**
|
||||
* Class User
|
||||
@ -43,6 +46,24 @@ class User extends Authenticatable
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
public static function validateRegistration(array $data): ValidatorContract
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:10|confirmed',
|
||||
]);
|
||||
}
|
||||
|
||||
public static function createUser(array $data): self
|
||||
{
|
||||
return self::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
}
|
||||
|
||||
/*
|
||||
| ========================================================================
|
||||
| RELATIONSHIPS
|
||||
|
@ -3,12 +3,14 @@ return [
|
||||
'linkace' => 'LinkAce',
|
||||
|
||||
'user' => 'User',
|
||||
'username' => 'Username',
|
||||
'email' => 'Email',
|
||||
'password' => 'Password',
|
||||
'password_confirm' => 'Confirm the Password',
|
||||
'login' => 'Login',
|
||||
'logout' => 'Logout',
|
||||
'remember_me' => 'Remember me',
|
||||
'go_to_dashboard' => 'Go to the Dashboard',
|
||||
|
||||
'reset_password' => 'Reset Password',
|
||||
'send_reset_email' => 'Send Password Reset Link',
|
||||
|
@ -35,4 +35,14 @@ return [
|
||||
'database.complete_hint' => 'Saving the database configuration and preparing it for using the app may take a few seconds, please be patient.',
|
||||
|
||||
'account_setup' => 'Account Setup',
|
||||
'account_setup.intro' => 'Before you can start you have to create your user account.',
|
||||
'account_setup.name' => 'Enter your name',
|
||||
'account_setup.email' => 'Enter your email address',
|
||||
'account_setup.password' => 'Enter a strong password',
|
||||
'account_setup.password_requirements' => 'Minimum length: 10 characters',
|
||||
'account_setup.password_confirmed' => 'Confirm your password',
|
||||
'account_setup.create' => 'Create account',
|
||||
|
||||
'complete' => 'Setup completed!',
|
||||
'outro' => 'You completed the setup and can now use LinkAce! You are logged in and can start bookmarking right away.',
|
||||
];
|
||||
|
@ -11,6 +11,80 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<p>@lang('setup.account_setup.intro')</p>
|
||||
|
||||
@include('partials.alerts')
|
||||
|
||||
<form action="{{ route('setup.account') }}" method="post">
|
||||
@csrf
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">
|
||||
@lang('setup.account_setup.name')
|
||||
</label>
|
||||
<input type="text" name="name" id="name"
|
||||
class="form-control {{ $errors->has('name') ? 'is-invalid' : '' }}"
|
||||
placeholder="@lang('placeholder.username')" aria-label="@lang('linkace.username')"
|
||||
value="{{ old('name') }}" required autofocus>
|
||||
|
||||
@if ($errors->has('name'))
|
||||
<p class="invalid-feedback" role="alert">
|
||||
{{ $errors->first('name') }}
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">
|
||||
@lang('setup.account_setup.email')
|
||||
</label>
|
||||
<input type="email" name="email" id="email"
|
||||
class="form-control {{ $errors->has('email') ? 'is-invalid' : '' }}"
|
||||
placeholder="@lang('placeholder.email')" aria-label="@lang('linkace.email')"
|
||||
value="{{ old('email') }}" required autofocus>
|
||||
|
||||
@if ($errors->has('email'))
|
||||
<p class="invalid-feedback" role="alert">
|
||||
{{ $errors->first('email') }}
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">
|
||||
@lang('setup.account_setup.password')
|
||||
</label>
|
||||
<input type="password" name="password" id="password"
|
||||
class="form-control {{ $errors->has('password') ? 'is-invalid' : '' }}"
|
||||
value="{{ old('password') }}" aria-label="@lang('linkace.password')">
|
||||
@if ($errors->has('password'))
|
||||
<p class="invalid-feedback" role="alert">
|
||||
{{ $errors->first('password') }}
|
||||
</p>
|
||||
@else
|
||||
<p class="form-text text-muted small">
|
||||
@lang('setup.account_setup.password_requirements')
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password_confirmation">
|
||||
@lang('setup.account_setup.password_confirmed')
|
||||
</label>
|
||||
<input type="password" name="password_confirmation" id="password_confirmation"
|
||||
class="form-control {{ $errors->has('password_confirmation') ? 'is-invalid' : '' }}"
|
||||
value="{{ old('password_confirmation') }}" aria-label="@lang('linkace.password_confirmed')">
|
||||
@if ($errors->has('password_confirmation'))
|
||||
<p class="invalid-feedback" role="alert">
|
||||
{{ $errors->first('password_confirmation') }}
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">@lang('setup.account_setup.create')</button>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
25
resources/views/setup/complete.blade.php
Normal file
25
resources/views/setup/complete.blade.php
Normal file
@ -0,0 +1,25 @@
|
||||
@extends('layouts.setup')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12 col-md-8">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
@lang('setup.completed')
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<p>@lang('setup.outro')</p>
|
||||
|
||||
<a href="{{ route('dashboard') }}" class="btn btn-primary">
|
||||
@lang('linkace.go_to_dashboard')
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
@ -5,11 +5,13 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::get('/', 'FrontController@index')->name('front');
|
||||
|
||||
// Setup routes
|
||||
Route::get('setup/start', 'Setup\WelcomeController@index')->name('setup.start');
|
||||
Route::get('setup/start', 'Setup\MetaController@welcome')->name('setup.welcome');
|
||||
Route::get('setup/requirements', 'Setup\RequirementsController@index')->name('setup.requirements');
|
||||
Route::get('setup/database', 'Setup\DatabaseController@index')->name('setup.database');
|
||||
Route::post('setup/database', 'Setup\DatabaseController@configure')->name('setup.database');
|
||||
Route::get('setup/account', 'Setup\AccountController@index')->name('setup.account');
|
||||
Route::post('setup/account', 'Setup\AccountController@register')->name('setup.account');
|
||||
Route::get('setup/complete', 'Setup\MetaController@complete')->name('setup.complete');
|
||||
|
||||
// Authentication Routes
|
||||
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
|
||||
|
Loading…
x
Reference in New Issue
Block a user