Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
Registro en DB
Browse files Browse the repository at this point in the history
  • Loading branch information
victorhqc committed Aug 4, 2019
1 parent 96cea1a commit 62c2e14
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
namespace App\Http\Controllers\Auth;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;

use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Auth;


class RegisterController extends Controller
class SignupController extends Controller
{
/*
|--------------------------------------------------------------------------
Expand All @@ -20,15 +25,41 @@ class RegisterController extends Controller
|
*/

use RegistersUsers;

/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/home';

/**
* Show the application registration form.
*
* @return \Illuminate\Http\Response
*/
public function showSignupForm()
{
return view('auth.signup');
}

/**
* Maneja la autenticación para la solicitud de registro a la aplicación.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function signup(Request $request)
{
$this->validator($request->all())->validate();

event(new Registered($user = $this->create($request->all())));

$this->guard()->login($user);

return $this->registered($request, $user)
?: redirect($this->redirectPath());
}

/**
* Create a new controller instance.
*
Expand All @@ -47,12 +78,23 @@ public function __construct()
*/
protected function validator(array $data)
{
return Validator::make($data, [
$rules = [
'name' => ['required', 'string', 'max:144'],
'last_name' => ['required', 'string', 'max:144'],
'email' => ['required', 'string', 'email', 'max:144', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
'password' => ['required', 'string', 'min:8', 'confirmed']
];

$messages = [
'required' => ':attribute es requerido.',
'min' => ':attribute debe tener al menos :min caracteres',
'confirmed' => ':attribute no coincide con la confirmación.',
'email.unique:users' => 'El correo ya se encuentra registrado',
'password.min:8' => 'La contraseña debe tener al menos 8 caracteres',
'password_confirmation.same:password' => 'Las contraseñas no son iguales, asegurate que sean correctas.',
];

return Validator::make($data, $rules, $messages);
}

/**
Expand Down
1 change: 0 additions & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Kernel extends HttpKernel
*/
protected $middleware = [
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
Expand Down
2 changes: 1 addition & 1 deletion config/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
|
*/

'driver' => env('SESSION_DRIVER', 'file'),
'driver' => env('SESSION_DRIVER', 'cookie'),

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions database/migrations/2019_08_04_123253_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateUsersTable extends Migration
*/
public function up()
{
Schema::create('user', function (Blueprint $table) {
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('email', 144)->unique();
$table->string('password', 512);
Expand All @@ -30,6 +30,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('user');
Schema::dropIfExists('users');
}
}
117 changes: 117 additions & 0 deletions resources/views/auth/signup.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
@extends('layouts.app')

@section('title', 'Registro')

@section('app-styles')
<style type="text/css">
.main-login {
display: flex;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
}
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
border: 1px solid #ccc;
}
.form-sugnin .form-control {
position: relative;
box-sizing: border-box;
height: auto;
padding: 10px;
font-size: 16px;
}
</style>
@endsection

@section('content')
<div class="main-login text-center">
<form
class="form-signin"
action="{{ action('Auth\SignupController@signup') }}"
method="post"
>
@csrf
<h1 class="h3 mb-3 font-weight-normal">Regístrate</h1>
@if ($errors->any())
<div class="alert alert-danger" role="alety">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="text-left">
<div class="form-group">
<label for="input_email">Correo electrónico</label>
<input
id="input_email"
name="email"
class="form-control"
type="email"
placeholder="Correo electrónico"
required=""
autofocus=""
/>
</div>
<div class="form-group">
<label for="input_name">Nombre</label>
<input
id="input_name"
name="name"
class="form-control"
type="text"
placeholder="Nombre"
required=""
/>
</div>
<div class="form-group">
<label for="input_last_name">Apellido</label>
<input
id="input_last_name"
name="last_name"
class="form-control"
type="text"
placeholder="Apellido"
required=""
/>
</div>
<div class="form-group">
<label for="input_password">Contraseña</label>
<input
id="input_password"
name="password"
class="form-control"
type="password"
placeholder="Contraseña"
required=""
/>
</div>
<div class="form-group">
<label for="input_password_confirmation">Repite la contraseña</label>
<input
id="input_password_confirmation"
name="password_confirmation"
class="form-control"
type="password"
placeholder="Repite la Contraseña"
required=""
/>
</div>
</div>
<button class="btn btn-lg btn-primary btn-lock" type="submit">
Registrarse
</button>
<p class="mt-5 mb-3">
<a href="/login">Inicia sesión</a>
</p>
</form>
</div>
@endsection
5 changes: 2 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
return view('login', ['name' => 'James']);
});

$router->get('/signup', function () {
return view('signup', []);
});
$router->get('signup', 'Auth\SignupController@showSignupForm')->name('signup');
$router->post('signup', 'Auth\SignupController@signup');

0 comments on commit 62c2e14

Please sign in to comment.