Browse Source

Finish migrations and functions for registration

The .htaccess file was restored to solve the redirection problem,
migrations were created with more information about the user and good
defaults, and an accept header was added because of the annoyance of
not getting a JSON response after a validation error.
tags/v0.1.0
Immanuel Onyeka 3 years ago
parent
commit
591a27e165
8 changed files with 82 additions and 15 deletions
  1. +4
    -4
      app/Http/Controllers/UserController.php
  2. +2
    -2
      database/migrations/2014_10_12_000000_create_users_table.php
  3. +33
    -0
      database/migrations/2021_05_13_185302_create_orders_table.php
  4. +21
    -0
      public/.htaccess
  5. +3
    -0
      resources/images/warning-colored.svg
  6. +13
    -6
      resources/js/register-area/register-area.vue
  7. +6
    -2
      resources/scss/main.scss
  8. +0
    -1
      routes/web.php

+ 4
- 4
app/Http/Controllers/UserController.php View File

@@ -13,18 +13,18 @@ use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function create(Request $request) {
Log::("it works")
$validated = $request->validate([
'name' => 'required',
'email' => 'required|email|unique:users',
'password' => 'required'
/* 'password' => 'required|confirmed|min:8|regex:/[a-z]/|regex:/[A-Z]/|regex:/[0-9]/' */
'email' => 'required|email|unique:users,email',
/* 'password' => 'required' */
'password' => 'required|confirmed|min:8|regex:/[a-z]/|regex:/[A-Z]/|regex:/[0-9]/'
]);

$user = new User;
$user->name = $request->name;
$user->email = $request->email;
$user->role = "client";
$user->active = true;
$user->password = Hash::make($request->password);
$user->save();



+ 2
- 2
database/migrations/2014_10_12_000000_create_users_table.php View File

@@ -20,8 +20,8 @@ class CreateUsersTable extends Migration
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('role');
$table->boolean('active');
$table->bigInteger('credits');
$table->boolean('active')->default(true);
$table->bigInteger('credits')->default(0);
$table->rememberToken();
$table->timestamps();
});


+ 33
- 0
database/migrations/2021_05_13_185302_create_orders_table.php View File

@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('product');
$table->bigInteger('quantity');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('orders');
}
}

+ 21
- 0
public/.htaccess View File

@@ -0,0 +1,21 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

+ 3
- 0
resources/images/warning-colored.svg View File

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="red" class="bi bi-exclamation-triangle-fill" viewBox="0 0 16 16">
<path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
</svg>

+ 13
- 6
resources/js/register-area/register-area.vue View File

@@ -1,6 +1,7 @@
<template>
<form v-if="active === 'register'" v-on:submit="register" id="register-form">
<h3>Registration</h3>
<div>{{errorMessage}}</div>
<div>
<label for='sender_name'>Name</label>
<input id='register-name' required type='name' name='sender_name' placeholder=''
@@ -44,7 +45,7 @@
<p>A password reset link has been sent.</p>
</div>
<div v-if="active === 'error'">
<img class="medium-icon" src="../../images/warning.svg" alt="">
<img class="medium-icon" src="../../images/warning-colored.svg" alt="">
<h3>An Error Occured.</h3>
<p>{{`${error}: ${errorMessage}`}}</p>
</div>
@@ -57,6 +58,7 @@
fetch("/register", {
method: 'POST',
headers: {'Content-Type': 'application/json',
'Accept': 'application/json',
'X-XSRF-TOKEN': this.token},
body: JSON.stringify({"name": document.getElementById("register-name").value,
"email": document.getElementById("register-email").value,
@@ -65,13 +67,18 @@
.then(response => {
//Give completed or error
if (response.ok) {
this.active = 'completed'
this.active = 'register-completed'
} else {
this.error = response.status
this.errorMessage = response.statusText
this.active = 'error'
if (response.status === 422) {
this.errorMessage = 'That email is already registered.'
this.active = 'register'
} else {
this.error = response.status
this.errorMessage = response.statusText
this.active = 'error'
}
}
console.log(response)
/* console.log(response.json()) */
});
event.preventDefault();
}


+ 6
- 2
resources/scss/main.scss View File

@@ -501,15 +501,17 @@ div.register-area {
color: black;
display: block;
border-color: black;
width: 95%;
}

div {
margin-top: 20px;
margin-bottom: 20px;
width: 100%;
}

form {
width: fit-content;
width: 160px;
margin: 20px auto;
}

@@ -535,7 +537,7 @@ section.features-info {
}

div.register-area.active {
height: 400px;
min-height: 400px;
opacity: 1;
}

@@ -623,6 +625,8 @@ div.register-area.active {
div.register-area div {
margin-top: 10px;
margin-bottom: 5px;
margin-left: auto;
margin-right: auto;
}

.landing-hero div.hero-filter h2 {


+ 0
- 1
routes/web.php View File

@@ -41,7 +41,6 @@ Route::post('/resend-verification', function (Request $request) {
})->middleware(['auth', 'throttle:6,1'])->name('verification.send');

Route::post('/register', [UserController::class, 'create']);
Route::view('/register', 'home');

Route::get('/forgot-password', function () {
return view('request-reset');


Loading…
Cancel
Save