Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin category and sub-category CRUD #8

Merged
merged 8 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/AdminDataDetailsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function login(LoginFormValidator $request): RedirectResponse
return redirect()->back()->with('error', $e->getMessage());
}

return redirect()->back()->with('error', 'Credentials do not match!');
return redirect()->back()->with('message', 'Credentials do not match!');
}


Expand Down
89 changes: 89 additions & 0 deletions app/Http/Controllers/PasswordResetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\ForgotPasswordMailValidator;
use App\Http\Requests\ResetPasswordValidator;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;

use function PHPUnit\Framework\returnSelf;

class PasswordResetController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
return view('backend.forgotPassword');
}


//send reset mail to the user
public function sendResetMail(ForgotPasswordMailValidator $request)
{
$token = Str::random(64);

// dd($request->validated()['email']);


try{
DB::table('password_reset_tokens')->insert([
'email' => $request->validated()['email'],
'token' => $token,
"created_at" => Carbon::now(),
]);

Mail::send('backend.resetPasswordLink', ['token' => $token], function($message) use($request){
$message->to($request->validated()['email']);
$message->subject('Reset Password');
});

return back()->with('message', 'Your password reset link has been sent to your email.');


}catch(\Exception $e){
// dd($e);
}
}


public function showNewPasswordForm(string $token){
return view('backend.passwordReset', ['token'=> $token]);
}


public function submitResetPasswordForm(ResetPasswordValidator $request){
try{
$tokenData = DB::table('password_reset_tokens')->where('token', $request->validated()['token'])->first();

if(!$tokenData):
return back()->with(['message' => 'Invalid token id!!']);
endif;


User::where('email', $tokenData->email)->first()->update([
'password' => Hash::make($request->validated()['new-password']),
]);

DB::table('password_reset_tokens')->where('email', $tokenData->email)->delete();

return redirect()->route('login')->with('message', 'Password successfully updated!!');
}catch(\Exception $e){
// dd($e);
}
}





}
28 changes: 28 additions & 0 deletions app/Http/Requests/ForgotPasswordMailValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ForgotPasswordMailValidator extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'email' => ['bail','required','email'],
];
}
}
30 changes: 30 additions & 0 deletions app/Http/Requests/ResetPasswordValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ResetPasswordValidator extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'new-password' => ['bail','required'],
'confirm-password' => ['required', 'same:new-password'],
'token' => ['required'],
];
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"laravel/tinker": "^2.8"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.9",
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
Expand Down
152 changes: 151 additions & 1 deletion composer.lock

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

2 changes: 1 addition & 1 deletion database/seeders/AdminDataDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function run(): void
{
DB::table('users')->insert([
'username' => 'slymee',
'email' => 'slymeesmurf@super.com',
'email' => 'slimismurf@gmail.com',
'password' => Hash::make('slymee'),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
Expand Down
13 changes: 10 additions & 3 deletions resources/views/backend/adminLogin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@
<input type="password" name="password" id="" placeholder="Enter Password"><br>
<input type="submit" value="Login">
</form>
<span class="forgot-password">Forgot Password?</span>
<a href="#" onclick="event.preventDefault(); document.getElementById('forgot-password').submit();">
<span class="forgot-password">Forgot Password?</span>
</a>

<form id="forgot-password" action="{{ route('forgot-password-view') }}" method="GET" style="display: none;">
@csrf
</form>

<span class="error-message">
@if(session('error'))
{{ session('error') }}
@if(session('message'))
{{ session('message') }}
@endif

@if($errors->any())
Expand Down
Loading