@@ -7,6 +7,7 @@ use App\Models\User; | |||||
use Illuminate\Support\Facades\Log; | use Illuminate\Support\Facades\Log; | ||||
use Illuminate\Support\Facades\Hash; | use Illuminate\Support\Facades\Hash; | ||||
use Illuminate\Auth\Events\Registered; | use Illuminate\Auth\Events\Registered; | ||||
use Illuminate\Support\Facades\Password; | |||||
class UserController extends Controller | class UserController extends Controller | ||||
{ | { | ||||
@@ -21,6 +22,7 @@ class UserController extends Controller | |||||
$user = new User; | $user = new User; | ||||
$user->name = $request->name; | $user->name = $request->name; | ||||
$user->email = $request->email; | $user->email = $request->email; | ||||
$user->role = "client"; | |||||
$user->password = Hash::make($request->password); | $user->password = Hash::make($request->password); | ||||
$user->save(); | $user->save(); | ||||
@@ -29,4 +31,45 @@ class UserController extends Controller | |||||
"status" => "success" | "status" => "success" | ||||
]); | ]); | ||||
} | } | ||||
public function forgotPassword(Request $request) { | |||||
$request->validate(['email' => 'required|email']); | |||||
$status = Password::sendResetLink( | |||||
$request->only('email') | |||||
); | |||||
if ($status === Password::RESET_LINK_SENT) { | |||||
return response()->json([ | |||||
"status" => "success" | |||||
]) | |||||
} else { | |||||
return response()->json($errors->all()) | |||||
} | |||||
} | |||||
public function resetPassword(Request $request) { | |||||
$request->validate([ | |||||
'token' => 'required', | |||||
'email' => 'required|email', | |||||
'password' => 'required|min:8|confirmed', | |||||
]); | |||||
$status = Password::reset( | |||||
$request->only('email', 'password', | |||||
'password_confirmation', 'token'), | |||||
function ($user, $password) use ($request) { | |||||
$user->forceFill([ | |||||
'password' => Hash::make($password) | |||||
])->setRememberToken(Str::random(60)) | |||||
}); | |||||
if ($status == Password::PASSWORD_RESET) { | |||||
return response()->json([ | |||||
"status" => "success" | |||||
]); | |||||
} else { | |||||
return response()->json([__($status)]); | |||||
} | |||||
} | |||||
} | } |
@@ -19,6 +19,8 @@ class CreateUsersTable extends Migration | |||||
$table->string('email')->unique(); | $table->string('email')->unique(); | ||||
$table->timestamp('email_verified_at')->nullable(); | $table->timestamp('email_verified_at')->nullable(); | ||||
$table->string('password'); | $table->string('password'); | ||||
$table->string('role'); | |||||
$table->bigInteger('credits'); | |||||
$table->rememberToken(); | $table->rememberToken(); | ||||
$table->timestamps(); | $table->timestamps(); | ||||
}); | }); | ||||
@@ -18,7 +18,7 @@ function register(event) { | |||||
'X-XSRF-TOKEN': token}, | 'X-XSRF-TOKEN': token}, | ||||
body: JSON.stringify({"name": document.getElementById("register-name").value, | body: JSON.stringify({"name": document.getElementById("register-name").value, | ||||
"email": document.getElementById("register-email").value, | "email": document.getElementById("register-email").value, | ||||
"password": document.getElementById("register-password").value}) | |||||
"password": document.getElementById("register-password").value}), | |||||
"password_confirmation": document.getElementById("confirm-password").value}) | "password_confirmation": document.getElementById("confirm-password").value}) | ||||
}).then(response => { | }).then(response => { | ||||
console.log('sent registration'); | console.log('sent registration'); | ||||
@@ -0,0 +1,17 @@ | |||||
@EXTEnds('master') | |||||
@section('title', 'Password Reset') | |||||
@section('head-metas') | |||||
@parent | |||||
<link rel="stylesheet" href="{{asset('main.css')}}"> | |||||
@endsection | |||||
@section('content') | |||||
Reset form goes here. | |||||
@endsection | |||||
@section('scripts') | |||||
@parent | |||||
<script src="main.js"></script> | |||||
@endsection |
@@ -0,0 +1,17 @@ | |||||
@extends('master') | |||||
@section('title', 'Password Reset') | |||||
@section('head-metas') | |||||
@parent | |||||
<link rel="stylesheet" href="{{asset('main.css')}}"> | |||||
@endsection | |||||
@section('content') | |||||
Reset form goes here. | |||||
@endsection | |||||
@section('scripts') | |||||
@parent | |||||
<script src="main.js"></script> | |||||
@endsection |
@@ -35,10 +35,20 @@ Route::post('/resend-verification', function (Request $request) { | |||||
$request->user()->sendEmailVerificationNotification(); | $request->user()->sendEmailVerificationNotification(); | ||||
return back()->with('message', 'Verification link sent!'); | return back()->with('message', 'Verification link sent!'); | ||||
})->middleware(['auth', 'throttle:6,1'])->name('verification.send') | |||||
Route::get('/login', function () { | |||||
return view('home'); | |||||
}); | |||||
})->middleware(['auth', 'throttle:6,1'])->name('verification.send'); | |||||
Route::post('/register', [UserController::class, 'create']); | Route::post('/register', [UserController::class, 'create']); | ||||
Route::get('/forgot-password', function () { | |||||
return view('request-reset'); | |||||
})->middleware('guest')->name('password.request'); | |||||
Route::post('/forgot-passowrd', [UserController::class, | |||||
'forgotPassword'])->middleware('guest')->name('password.email'); | |||||
Route::get('/reset-password/{token}', function ($token) { | |||||
return view('reset-password', ['token' => $token]); | |||||
})->middleware('guest')->name('password.reset'); | |||||
Route::post('/reset-passowrd', [UserController::class, | |||||
'resetPassword'])->middleware('guest')->name('password.email'); |