collective login

This commit is contained in:
Marley Rae 2022-04-23 11:39:07 -07:00
parent 45fbf0f378
commit 13c390c5af
16 changed files with 209 additions and 15 deletions

View file

@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreCollectiveRequest;
use App\Http\Requests\UpdateCollectiveRequest;
use App\Models\Collective;
class CollectiveController extends Controller
{
public function dashboard()
{
return view('admin.dashboard');
}
public function create()
{
return view('admin.install');
}
public function store(StoreCollectiveRequest $request)
{
$validated = $request->safe()->only([
'title',
'name',
'email',
'password',
]);
$collective = Collective::store($validated);
auth()->login($collective);
return redirect()->route('dashboard')->with('success', 'Fanatic installed!');
}
public function show(Collective $collective)
{
//
}
public function edit(Collective $collective)
{
//
}
public function update(UpdateCollectiveRequest $request, Collective $collective)
{
//
}
public function destroy(Collective $collective)
{
//
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Password;
class StoreCollectiveRequest extends FormRequest
{
public function authorize() : bool
{
return true;
}
public function rules() : array
{
return [
'title' => ['required', 'string', 'max:255'],
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:100'],
'password' => ['required', 'confirmed', Password::min(6)->letters()->numbers()],
];
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateCollectiveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View file

@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
@ -39,4 +40,27 @@ class Collective extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];
/* -------------------------------------------------------------------------------- password ---- */
protected function password() : Attribute
{
return Attribute::make(
set: fn ($value) => bcrypt($value),
);
}
/* ----------------------------------------------------------------------------------- store ---- */
public static function store(array $validated) : Collective
{
$collective = new Collective();
$collective->title = $validated['title'];
$collective->name = $validated['name'];
$collective->email = $validated['email'];
$collective->password = $validated['password'];
$collective->save();
return $collective;
}
}

View file

@ -62,7 +62,7 @@
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
'model' => App\Models\Collective::class,
],
// 'users' => [

View file

@ -92,6 +92,10 @@ .form__btns:first-of-type {
margin-top: 20px;
}
.form__error {
color: #e20000;
}
html, body {
width: 100%;
height: 100%;
@ -109,7 +113,6 @@ .l-container {
margin: 0 auto;
background-color: #f8f8ff;
border: 1px solid #7874ff;
padding: 0 40px;
}
.l-nav {
@ -133,5 +136,13 @@ .l-nav__tab:last-child {
}
.l-main {
padding: 5px;
padding: 10px 40px;
}
.error {
background-color: #87ff5f;
border: 1px solid #30be00;
padding: 10px;
width: 60%;
margin: 10px auto;
}

View file

@ -68,4 +68,8 @@ h1 {
.form__btn {
@extend %btn;
}
.form__error {
color: $c-red;
}

View file

@ -18,7 +18,6 @@ body {
margin: 0 auto;
background-color: #f8f8ff;
border: 1px solid $c-main;
padding: 0 40px;
}
@ -44,5 +43,5 @@ body {
.l-main {
padding: 5px;
padding: 10px 40px;
}

View file

@ -0,0 +1,11 @@
@use 'vars' as *;
@use 'sass:color';
.error {
background-color: color.scale($c-green, $lightness: 50%);
border: 1px solid $c-green;
padding: 10px;
width: 60%;
margin: 10px auto;
}

View file

@ -0,0 +1,2 @@
@use 'vars' as *;

View file

@ -13,6 +13,10 @@ $c-accent: #de7cff;
$c-accent-light: color.scale($c-accent, $lightness: 40%);
$c-accent-lightest: color.scale($c-accent, $lightness: 80%);
$c-green: #30be00;
$c-yellow: #ebb000;
$c-red: #e20000;
/* ------------------------------------------------------------------------------------ &BTN ---- */
@mixin hover($focus: false) {

View file

@ -1,2 +1,4 @@
@use 'base';
@use 'layout';
@use 'layout';
@use 'modules';
@use 'states';

View file

@ -0,0 +1,5 @@
@extends('admin.layout')
@section('content')
<h1><span>Dashboard</span></h1>
@endsection

View file

@ -5,25 +5,33 @@
<p>This is the installation page. You will only need to complete this once, but values can be
changed after installation.</p>
<form action="{{-- route('collective.store') --}}" method="POST">
<form action="{{ route('collectives.store') }}" method="POST">
@csrf
<fieldset class="form__fieldset">
<label class="form__label" for="title">Collective title:</label>
<input class="form__input" type="text" name="title" id="title"
<input class="form__input" type="text" name="title" id="title" required
value="{{ old('title') }}">
@error('title') <p class="form__error">{{ $message }}</p> @enderror
<label class="form__label" for="name">Your name:</label>
<input class="form__input" type="text" id="name" name="name"
<input class="form__input" type="text" id="name" name="name" required
value="{{ old('name') }}">
@error('name') <p class="form__error">{{ $message }}</p> @enderror
<label class="form__label" for="email">Your email:</label>
<input class="form__input" type="email" id="email" name="email"
<input class="form__input" type="email" id="email" name="email" required
value="{{ old('email') }}">
@error('email') <p class="form__error">{{ $message }}</p> @enderror
<label class="form__label" for="password">Your password:</label>
<input class="form__input" type="password" id="password" name="password"
value="{{ old('password') }}">
<input class="form__input" type="password" id="password" name="password" required>
@error('password') <p class="form__error">{{ $message }}</p> @enderror
<label class="form__label" for="password_confirmation">Confirm password:</label>
<input class="form__input" type="password" id="password_confirmation"
name="password_confirmation" required>
@error('password_confirmation') <p class="form__error">{{ $message }}</p> @enderror
<div class="form__btns">
<input class="form__btn" type="submit" value="Submit">

View file

@ -22,6 +22,20 @@
@endauth
<main class="l-main">
@yield('title')
@if (session()->has('success'))
<p class="success">{{ session()->get('success') }}</p>
@endif
@if (session()->has('error'))
<p class="error">{{ session()->get('error') }}</p>
@endif
@if (session()->has('warning'))
<p class="warning">{{ session()->get('warning') }}</p>
@endif
@yield('content')
</main>

View file

@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\CollectiveController;
use Illuminate\Support\Facades\Route;
/*
@ -13,6 +14,6 @@
|
*/
Route::get('/fanatic/install', function () {
return view('admin.install');
});
Route::get('/fanatic', [CollectiveController::class, 'dashboard'])->name('dashboard');
Route::get('/fanatic/install', [CollectiveController::class, 'create'])->name('collectives.create');
Route::post('/fanatic', [CollectiveController::class, 'store'])->name('collectives.store');