Skip to content

Commit

Permalink
Added register functionality and updated landing page.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevsbuddy committed Dec 30, 2021
1 parent ec2d9f3 commit d37fadc
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 75 deletions.
35 changes: 31 additions & 4 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Auth\Events\Registered;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Spatie\Permission\Models\Role;

class RegisterController extends Controller
{
Expand Down Expand Up @@ -50,9 +54,11 @@ public function __construct()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'name' => ['required'],
'username' => ['required', 'unique:users'],
'email' => ['required', 'email', 'unique:users'],
'phone' => ['required', 'unique:users', 'numeric', 'min:10'],
'password' => ['required', 'min:6'],
]);
}

Expand All @@ -67,7 +73,28 @@ protected function create(array $data)
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'username' => $data['username'],
'phone' => $data['phone'],
'password' => bcrypt($data['password']),
]);
}

public function register(Request $request)
{
$this->validator($request->all())->validate();

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

$user->syncRoles(Role::where('name', 'user')->first()->id);

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

if ($response = $this->registered($request, $user)) {
return $response;
}

return $request->wantsJson()
? response()->json(['message' => "User registered successfully!"], 201)
: redirect($this->redirectPath());
}
}
2 changes: 2 additions & 0 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
</div>
</div>
</form>
<p class="text-center mt-3">OR</p>
<a href="{{ route('register') }}" class="btn btn-block btn-light px-4">Create an account</a>
</div>
</div>

Expand Down
204 changes: 133 additions & 71 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,139 @@
@extends('layouts.app')
@extends('adminr.layouts.auth')

@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-7">
<div class="card-group">
<div class="card p-4">
<div class="card-body">
<h1>Register</h1>
<p class="text-muted">Create a new account</p>
<form method="POST" action="{{ route('register') }}">
@csrf
<div class="row">
<div class="col-lg-6">
<label for="name">Name <span class="text-danger">*</span></label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">
<svg class="c-icon">
<use xlink:href="{{ coreUiIcon('cil-user') }}"></use>
</svg>
</span>
</div>
<input id="name" type="text"
class="form-control @error('name') is-invalid @enderror" name="name"
value="{{ old('name') }}" required autocomplete="off"
placeholder="Name" autofocus>
@error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-lg-6">
<label for="username">Username <span class="text-danger">*</span></label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">
<svg class="c-icon">
<use xlink:href="{{ coreUiIcon('cil-user') }}"></use>
</svg>
</span>
</div>
<input id="username" type="text"
class="form-control @error('username') is-invalid @enderror"
name="username" value="{{ old('username') }}" required
autocomplete="off" placeholder="Username" autofocus>
@error('username')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-lg-6">
<label for="email">Email <span class="text-danger">*</span></label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">
<svg class="c-icon">
<use xlink:href="{{ coreUiIcon('cil-send') }}"></use>
</svg>
</span>
</div>
<input id="email" type="text"
class="form-control @error('email') is-invalid @enderror"
name="email" value="{{ old('email') }}" required autocomplete="off"
placeholder="Email" autofocus>
@error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-lg-6">
<label for="phone">Phone <span class="text-danger">*</span></label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">
<svg class="c-icon">
<use xlink:href="{{ coreUiIcon('cil-phone') }}"></use>
</svg>
</span>
</div>
<input id="phone" type="text"
class="form-control @error('phone') is-invalid @enderror"
name="phone" value="{{ old('phone') }}" required autocomplete="off"
placeholder="Phone" autofocus>
@error('phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-lg-12">
<label for="password">Password*</label>
<div class="input-group mb-4">
<div class="input-group-prepend">
<span class="input-group-text">
<svg class="c-icon">
<use xlink:href="{{ coreUiIcon('cil-lock-locked') }}"></use>
</svg>
</span>
</div>
<input id="password" type="password"
class="form-control @error('password') is-invalid @enderror"
name="password" placeholder="Password" required
autocomplete="current-password">
@error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
</div>

<div class="card-body">
<form method="POST" action="{{ route('register') }}">
@csrf

<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="row">
<div class="col-6">
<button class="btn btn-block btn-primary px-4" type="submit">Register</button>
</div>
<div class="col-6">
<a href="{{ route('login') }}" class="btn btn-block btn-light px-4">Login here</a>
</div>
</div>
</form>
</div>
</div>

<div class="col-md-6">
<input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>

@error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>

<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

<div class="col-md-6">
<input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email">

@error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>

<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

<div class="col-md-6">
<input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">

@error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>

<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
</div>
</div>

<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection

0 comments on commit d37fadc

Please sign in to comment.