Skip to content

Commit

Permalink
Merge pull request #1 from HijenHEK/form-validation
Browse files Browse the repository at this point in the history
Form validation
  • Loading branch information
HijenHEK authored May 1, 2021
2 parents 99fac1a + b6888ef commit e3430e7
Show file tree
Hide file tree
Showing 43 changed files with 729 additions and 277,925 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/node_modules
/public/hot
/public/storage
node_modules
public/hot
public/storage
public/js
public/css
/storage/*.key
/vendor
.env
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Support\Facades\Auth;

class AuthController extends Controller
Expand All @@ -21,7 +20,7 @@ public function Login(Request $request)
if (!$this->guard()->attempt($credentials)) {
return response()->json([

'message' => 'Unauthorized , The provided credentials are incorrect.'
'message' => 'The provided credentials are incorrect.'
], 500);
}

Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

Expand All @@ -18,10 +19,15 @@ public function __invoke(Request $request)
]);


return User::create([
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);

if ($user) {
event(new Registered($user));
return $user;
}
}
}
69 changes: 69 additions & 0 deletions app/Http/Controllers/VerificationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Foundation\Auth\VerifiesEmails;
use Illuminate\Http\Request;

class VerificationController extends Controller
{
//
use VerifiesEmails;

/**
* Mark the authenticated user's email address as verified.
*
* @param \Illuminate\Http\Request $request
*
*/

public function verify(Request $request)
{
$user = User::findOrFail($request->route('id'));

if (
!hash_equals((string) $request->route('id'), (string) $user->getKey())
|| !hash_equals((string) $request->route('hash'), sha1($user->getEmailForVerification()))
) {

return response()->json(['message' => 'Verification error ! Try again'], 500);
}


if ($user->hasVerifiedEmail()) {
return response()->json(['message' => 'already verified !'], 200);
}

if ($user->markEmailAsVerified()) {
return response()->json(['message' => 'email verified successfully !'], 200);
}

return response()->json(['verified' => true]);
}


/**
* Resend the email verification notification.
*
* @param \Illuminate\Http\Request $request
*/
public function resend(Request $request)
{

$this->validate($request, ['id' => 'required']);

$user = User::find($request->id);

if (!$user) return response()->json(['message' => 'Verification error '], 500);


if ($user->hasVerifiedEmail()) {
return response()->json(['message' => 'already verified !'], 200);
}

$user->sendEmailVerificationNotification();
return response()->json(['message' => 'verification email has been resent !', 200]);
}
}
9 changes: 7 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace App\Models;

use App\Notifications\ResetPasswordNotification;
use Illuminate\Auth\Passwords\CanResetPassword;
use App\Notifications\VerifyEmailNotification;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable, HasApiTokens;

Expand Down Expand Up @@ -48,4 +49,8 @@ public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
public function sendEmailVerificationNotification()
{
$this->notify(new VerifyEmailNotification());
}
}
39 changes: 39 additions & 0 deletions app/Notifications/VerifyEmailNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Notifications;

use Carbon\Carbon;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\URL;

class VerifyEmailNotification extends verifyEmail implements ShouldQueue
{
use Queueable;


/**
* Get the verification URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function verificationUrl($notifiable)
{
$url = URL::temporarySignedRoute(
'verify',
Carbon::now()->addMinutes(60),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);

return str_replace('/api', '', $url);
}
}
1 change: 1 addition & 0 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@

'password_timeout' => 10800,


];
36 changes: 36 additions & 0 deletions database/migrations/2021_04_26_093603_create_jobs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

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

class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}
27 changes: 26 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
},
"dependencies": {
"@heroicons/vue": "^1.0.1",
"moment": "^2.29.1",
"vue-router": "^4.0.6",
"vuex": "^4.0.0"
"vuex": "^4.0.0",
"vuex-shared-mutations": "^1.0.2"
}
}
Loading

0 comments on commit e3430e7

Please sign in to comment.