Преглед на файлове

Add forgot password function and test user seeding

tags/v0.1.0
Immanuel Onyeka преди 3 години
родител
ревизия
becc938852
променени са 5 файла, в които са добавени 43 реда и са изтрити 14 реда
  1. +0
    -6
      app/Http/Controllers/UserController.php
  2. +17
    -1
      database/seeders/DatabaseSeeder.php
  3. +0
    -1
      resources/js/main.js
  4. +25
    -1
      resources/js/register-area/register-area.vue
  5. +1
    -5
      routes/web.php

+ 0
- 6
app/Http/Controllers/UserController.php Целия файл

@@ -37,12 +37,6 @@ class UserController extends Controller
$status = Password::sendResetLink(
$request->only('email')
);

if ($status === Password::RESET_LINK_SENT) {
return response()->json([
"status" => "success"
]);
}
}

public function resetPassword(Request $request) {


+ 17
- 1
database/seeders/DatabaseSeeder.php Целия файл

@@ -3,6 +3,8 @@
namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\User;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
@@ -13,6 +15,20 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// \App\Models\User::factory(10)->create();
User::create([
'name' => 'test_user_unverified',
'email' => 'unverified@example.com',
'role' => 'client',
'active' => true,
'password' => Hash::make("test123")
]);
User::create([
'name' => 'test_user_verified',
'email' => 'verified@example.com',
'email_verified_at' => now(),
'role' => 'client',
'active' => true,
'password' => Hash::make("test123")
]);
}
}

+ 0
- 1
resources/js/main.js Целия файл

@@ -80,7 +80,6 @@ if (window.location.pathname == '/') {
document.getElementById("forgot-password-btn").onclick = event => {
document.querySelector(".register-area").classList.add("active")
app.active = 'forgot'
console.log(app.active)
event.preventDefault()
}



+ 25
- 1
resources/js/register-area/register-area.vue Целия файл

@@ -24,7 +24,7 @@
</div>
<button class="submit-btn" type="submit">Submit</button>
</form>
<form v-if="active === 'forgot'" v-on:submit="register" id="forgot-form">
<form v-if="active === 'forgot'" v-on:submit="forgotPassword" id="forgot-form">
<h3>Forgot Password</h3>
<div>
<label for='sender_email'>Email</label>
@@ -93,6 +93,29 @@
}
}

function forgotPassword(event) {
this.active = 'loading'
fetch("/forgot-password", {
method: 'POST',
headers: {'Content-Type': 'application/json',
'Accept': 'application/json',
'X-XSRF-TOKEN': this.token},
body: JSON.stringify({"email": document.getElementById("forgot-email").value})})
.then(response => {
//Give completed or error
console.log(response.status)
console.log(response.json())
if (response.ok) {
this.active = 'forgot-completed'
} else {
this.error = response.status
this.errorMessage = response.statusText
this.active = 'error'
}
/* console.log(response.json()) */
});
event.preventDefault();
}

module.exports = {
data() {
@@ -101,6 +124,7 @@
methods: {
register,
checkPasswords,
forgotPassword,
closeArea() {
document.querySelector(".register-area").classList.remove("active")
},


+ 1
- 5
routes/web.php Целия файл

@@ -42,11 +42,7 @@ Route::post('/resend-verification', function (Request $request) {

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,
Route::post('/forgot-password', [UserController::class,
'forgotPassword'])->middleware('guest')->name('password.email');

Route::get('/reset-password/{token}', function ($token) {


Loading…
Отказ
Запис