Commit 079499d3 authored by ZeMKI's avatar ZeMKI
Browse files

Registration

* enabled registration
* added email_verified_at to user table
* bugfixed look of notifications tab
* now users need to verify their email when they register
parent d7330fc3
......@@ -2,11 +2,13 @@
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use App\Permission;
use App\Role;
use App\User;
use Helper;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
......@@ -28,7 +30,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = '/';
/**
* Create a new controller instance.
......@@ -43,13 +45,12 @@ class RegisterController extends Controller
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
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:6|confirmed',
]);
......@@ -58,15 +59,38 @@ class RegisterController extends Controller
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @param array $data
* @return \App\User
*/
protected function create(array $data)
protected function create($data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$userexist = User::where('email', '=', $data['email'])->first();
$role = Role::where('name', 'supervisor')->first();
if ($userexist) {
return $this->showRegistrationForm();
} else {
$user = new User();
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->password_token = Helper::random_str(30);
$user->save();
$createStudyPermission = Permission::where('name', 'create-studies')
->first();
$user->supervised_by = $user->id;
$user->attachPermissions([$createStudyPermission]);
$user->attachRole($role);
// send welcome email - no action required
// Mail::to($user->email)->send(new VerificationEmail($user, config('utilities.emailDefaultText')));
// a "verify mail" email is sent out now
$user->save();
return $user;
}
}
}
......@@ -8,8 +8,9 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laratrust\Traits\LaratrustUserTrait;
use Illuminate\Contracts\Auth\MustVerifyEmail;
class User extends Authenticatable
class User extends Authenticatable implements MustVerifyEmail
{
use LaratrustUserTrait;
use Notifiable;
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddEmailVerifiedToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->date('email_verified_at')->default(null)->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
}
......@@ -159,6 +159,15 @@ window.app = new Vue({
interview: {
interviewed: ""
},
registration: {
password: null,
password_length: 0,
contains_six_characters: false,
contains_number: false,
contains_letters: false,
contains_special_character: false,
valid_password: false
},
shownotificationbox: false,
usernotifications: [],
howmanyunreadnotifications: 0
......@@ -191,6 +200,28 @@ window.app = new Vue({
}
},
methods: {
checkPassword() {
this.registration.password_length = this.registration.password.length;
const special_chars = /[ !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/;
if (this.registration.password_length > 5) {
this.registration.contains_six_characters = true;
} else {
this.registration.contains_six_characters = false;
}
this.registration.contains_number = /\d/.test(this.registration.password);
this.registration.contains_letters = /[a-z]/.test(this.registration.password);
this.registration.contains_special_character = special_chars.test(this.registration.password);
if (this.registration.contains_six_characters === true &&
this.registration.contains_letters === true &&
this.registration.contains_number === true) {
this.registration.valid_password = true;
} else {
this.registration.valid_password = false;
}
},
formatdate: function (date) {
......
......@@ -241,3 +241,63 @@ filter: blur(5px);
}
/**
Registration
*/
.list-item-registration {
margin-bottom: 8px;
color: #525f7f;
position: relative;
}
.list-item-registration:before {
content: "";
width: 0%; height: 2px;
background: #2ecc71;
position: absolute;
left: 0; top: 50%;
display: block;
transition: all .6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.is_valid { color: rgba(136, 152, 170, 0.8); }
.is_valid:before { width: 100%; }
.checkmark_container {
border-radius: 50%;
position: absolute;
top: -15px; right: -15px;
background: #2ecc71;
width: 50px; height: 50px;
visibility: hidden;
opacity: 0;
display: flex;
justify-content: center;
align-items: center;
transition: opacity .4s ease;
}
.show_checkmark {
visibility: visible;
opacity: 1;
}
.checkmark {
width: 100%;
height: 100%;
fill: none;
stroke: white;
stroke-width: 15;
stroke-linecap: round;
stroke-dasharray: 180;
stroke-dashoffset: 180;
}
.checked { animation: draw 0.5s ease forwards; }
@keyframes draw {
to { stroke-dashoffset: 0; }
}
......@@ -10,7 +10,9 @@
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<script src="{{ asset('js/manifest.js') }}" ></script>
<script src="{{ asset('js/vendor.js') }}" ></script>
<script src="{{ asset('js/app.js') }}" defer ></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
......
@extends('layouts.app')
@extends('auth.layouts.app')
@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="bg-img"></div>
<div class="container ">
<div class="columns is-centered">
<div class="card-body">
<div class="column is-6" style="margin-top: 10%">
<div class="box" style="top:50%;left: 50%;">
<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="col-md-6">
<input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name') }}" required autofocus>
<div class='column'>
@if ($errors->has('name'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
<figure class="image is-64x64" style="margin: 0 auto; max-width: 100%;">
<img src="{{config('utilities.base64logo')}}">
</figure>
<div class="column has-text-centered ">
<h1 class="title" style="margin: 0 auto; max-width: 100%;">Mesort</h1>
<h4> {{ __('Register') }} </h4>
</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{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
@if ($errors->has('email'))
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</div>
@endif
<div class="field">
<label for="email" class="label">{{ __('E-Mail Address') }}</label>
<div class="control">
<input id="email" type="email"
class="input {{ $errors->has('email') ? ' is-invalid' : '' }}" name="email"
value="{{ old('email') }}" required autofocus>
</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{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
<ul class="w-1/2">
<li class="list-item-registration w-auto"
:class="{ is_valid: registration.contains_six_characters }">6 Characters
</li>
<li class="list-item-registration" :class="{ is_valid: registration.contains_number }">
Contains Number
</li>
<li class="list-item-registration" :class="{ is_valid: registration.contains_letters }">
Contains Letters
</li>
</ul>
@if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
<div class="field">
<label for="password" class="label">{{ __('Password') }}</label>
<p class="control has-icon-left">
<input id="password" type="password" v-model="registration.password"
@input="checkPassword()"
class="input {{ $errors->has('password') ? ' is-invalid' : '' }}" name="password"
required>
<span class="icon is-small is-left">
<i class="fas fa-lock"></i>
</span>
</p>
</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>
</div>
<div class="field">
<label for="password-confirm"
class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
<p class="control has-icon-left">
<input id="password-confirm" type="password" class="input"
name="password_confirmation" required>
<span class="icon is-small is-left">
<i class="fas fa-lock"></i>
</span>
</p>
</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>
@if ($errors->has('password'))
<div class="notification is-danger is-small">
<strong>{{ $errors->first('password') }}</strong>
</div>
@endif
<div class="field">
<p class="control">
<button class="button is-dark"
:class="{'opacity-50 cursor-not-allowed disabled' : !this.registration.valid_password}"
:disabled="!this.registration.valid_password"
>
Register
</button>
</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
@extends('layouts.app')
@extends('auth.layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Verify Your Email Address') }}</div>
<div class="bg-img"></div>
<div class="container ">
<div class="columns is-centered">
<div class="card-body">
@if (session('resent'))
<div class="alert alert-success" role="alert">
{{ __('A fresh verification link has been sent to your email address.') }}
</div>
@endif
<div class="column is-6" style="margin-top: 10%">
<div class="box" style="top:50%;left: 50%;">
<div class="column has-text-centered ">
<h1 class="title" style="margin: 0 auto; max-width: 100%;">Mesort</h1>
<h6> {{ __('Verify Your Email Address') }} </h6>
</div>
{{ __('Before proceeding, please check your email for a verification link.') }}
{{ __('If you did not receive the email') }}, <a href="{{ route('verification.resend') }}">{{ __('click here to request another') }}</a>.
<div class="column">
@if (session('resent'))
<div class="flex items-center bg-blue-500 text-white text-sm font-bold px-4 py-3" role="alert">
<svg class="fill-current w-4 h-4 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M12.432 0c1.34 0 2.01.912 2.01 1.957 0 1.305-1.164 2.512-2.679 2.512-1.269 0-2.009-.75-1.974-1.99C9.789 1.436 10.67 0 12.432 0zM8.309 20c-1.058 0-1.833-.652-1.093-3.524l1.214-5.092c.211-.814.246-1.141 0-1.141-.317 0-1.689.562-2.502 1.117l-.528-.88c2.572-2.186 5.531-3.467 6.801-3.467 1.057 0 1.233 1.273.705 3.23l-1.391 5.352c-.246.945-.141 1.271.106 1.271.317 0 1.357-.392 2.379-1.207l.6.814C12.098 19.02 9.365 20 8.309 20z"/></svg>
<p> {{ __('A fresh verification link has been sent to your email address.') }} </p>
</div>
@endif
{{ __('Before proceeding, please check your email for a verification link.') }}
<form id="resend-form" method="POST" action="{{route('verification.resend')}}">
@csrf
</form>
{{ __('If you did not receive the email') }}, <a class="text-red-700"
href="{{ route('verification.resend') }}"
onclick="event.preventDefault();
document.getElementById('resend-form').submit();">
{{ __('click here to request another') }}
</a>.
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
......@@ -41,7 +41,7 @@
</span>
</a>
<div class="w-1/5 absolute border-2 border-gray-300 overflow-auto h-64 border-solid mr-10"
<div class="w-1/5 absolute border-2 border-gray-300 overflow-auto h-64 border-solid mr-10 z-50 bg-gray-100"
style="margin-top: -20px;"
v-show="shownotificationbox">
......@@ -95,9 +95,6 @@
{{__('Language')}}
<Caret></Caret>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
@csrf
</form>
<div id="dropdownLanguage" class="languagedropdown-content absolute hidden w-full text-center"
@mouseover="showdropdown('dropdownLanguage')"
......
......@@ -11,7 +11,7 @@
|
*/
Auth::routes();
Auth::routes(['verify' => true]);
// Index
// Show
......@@ -43,7 +43,7 @@ Route::group(['prefix' => 'admin', 'middleware' => ['role:superadministrator']],
Route::post('/notify', 'NotificationController@store');
});
Route::group(['middleware' => 'auth'], static function () {
Route::group(['middleware' => ['auth','verified']], static function () {
Route::get('/', 'HomeController@index')->name('home');
Route::get('/studies/new', 'StudyController@create');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment