Skip to content

Commit 07d64e2

Browse files
author
islamroshan
committed
Dashboard update
1 parent 7a0b79e commit 07d64e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2718
-571
lines changed

app/Actions/Fortify/CreateNewUser.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Support\Facades\Validator;
8+
use Illuminate\Validation\Rule;
9+
use Laravel\Fortify\Contracts\CreatesNewUsers;
10+
11+
class CreateNewUser implements CreatesNewUsers
12+
{
13+
use PasswordValidationRules;
14+
15+
/**
16+
* Validate and create a newly registered user.
17+
*
18+
* @param array $input
19+
* @return \App\Models\User
20+
*/
21+
public function create(array $input)
22+
{
23+
Validator::make($input, [
24+
'name' => ['required', 'string', 'max:255'],
25+
'email' => [
26+
'required',
27+
'string',
28+
'email',
29+
'max:255',
30+
Rule::unique(User::class),
31+
],
32+
'password' => $this->passwordRules(),
33+
])->validate();
34+
35+
return User::create([
36+
'name' => $input['name'],
37+
'email' => $input['email'],
38+
'password' => Hash::make($input['password']),
39+
]);
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use Laravel\Fortify\Rules\Password;
6+
7+
trait PasswordValidationRules
8+
{
9+
/**
10+
* Get the validation rules used to validate passwords.
11+
*
12+
* @return array
13+
*/
14+
protected function passwordRules()
15+
{
16+
return ['required', 'string', new Password, 'confirmed'];
17+
}
18+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use Illuminate\Support\Facades\Hash;
6+
use Illuminate\Support\Facades\Validator;
7+
use Laravel\Fortify\Contracts\ResetsUserPasswords;
8+
9+
class ResetUserPassword implements ResetsUserPasswords
10+
{
11+
use PasswordValidationRules;
12+
13+
/**
14+
* Validate and reset the user's forgotten password.
15+
*
16+
* @param mixed $user
17+
* @param array $input
18+
* @return void
19+
*/
20+
public function reset($user, array $input)
21+
{
22+
Validator::make($input, [
23+
'password' => $this->passwordRules(),
24+
])->validate();
25+
26+
$user->forceFill([
27+
'password' => Hash::make($input['password']),
28+
])->save();
29+
}
30+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use Illuminate\Support\Facades\Hash;
6+
use Illuminate\Support\Facades\Validator;
7+
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
8+
9+
class UpdateUserPassword implements UpdatesUserPasswords
10+
{
11+
use PasswordValidationRules;
12+
13+
/**
14+
* Validate and update the user's password.
15+
*
16+
* @param mixed $user
17+
* @param array $input
18+
* @return void
19+
*/
20+
public function update($user, array $input)
21+
{
22+
Validator::make($input, [
23+
'current_password' => ['required', 'string'],
24+
'password' => $this->passwordRules(),
25+
])->after(function ($validator) use ($user, $input) {
26+
if (! isset($input['current_password']) || ! Hash::check($input['current_password'], $user->password)) {
27+
$validator->errors()->add('current_password', __('The provided password does not match your current password.'));
28+
}
29+
})->validateWithBag('updatePassword');
30+
31+
$user->forceFill([
32+
'password' => Hash::make($input['password']),
33+
])->save();
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use Illuminate\Contracts\Auth\MustVerifyEmail;
6+
use Illuminate\Support\Facades\Validator;
7+
use Illuminate\Validation\Rule;
8+
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
9+
10+
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
11+
{
12+
/**
13+
* Validate and update the given user's profile information.
14+
*
15+
* @param mixed $user
16+
* @param array $input
17+
* @return void
18+
*/
19+
public function update($user, array $input)
20+
{
21+
Validator::make($input, [
22+
'name' => ['required', 'string', 'max:255'],
23+
24+
'email' => [
25+
'required',
26+
'string',
27+
'email',
28+
'max:255',
29+
Rule::unique('users')->ignore($user->id),
30+
],
31+
])->validateWithBag('updateProfileInformation');
32+
33+
if ($input['email'] !== $user->email &&
34+
$user instanceof MustVerifyEmail) {
35+
$this->updateVerifiedUser($user, $input);
36+
} else {
37+
$user->forceFill([
38+
'name' => $input['name'],
39+
'email' => $input['email'],
40+
])->save();
41+
}
42+
}
43+
44+
/**
45+
* Update the given verified user's profile information.
46+
*
47+
* @param mixed $user
48+
* @param array $input
49+
* @return void
50+
*/
51+
protected function updateVerifiedUser($user, array $input)
52+
{
53+
$user->forceFill([
54+
'name' => $input['name'],
55+
'email' => $input['email'],
56+
'email_verified_at' => null,
57+
])->save();
58+
59+
$user->sendEmailVerificationNotification();
60+
}
61+
}
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
use App\Models\User;
5+
use Illuminate\Support\Facades\Auth;
6+
use Illuminate\Support\Facades\Session;
7+
8+
use Illuminate\Http\Request;
9+
10+
class UserController extends Controller
11+
{
12+
/**
13+
* Login
14+
*/
15+
public function login(Request $request)
16+
{
17+
$credentials = [
18+
'email' => $request->email,
19+
'password' => $request->password,
20+
];
21+
22+
if (Auth::attempt($credentials)) {
23+
$id = Auth::user()->id;
24+
$user = User::find($id);
25+
$success = true;
26+
$layout = 'layout';
27+
$message = 'User login successfully';
28+
} else {
29+
$user = '';
30+
$success = false;
31+
$layout = 'login';
32+
$message = 'Unauthorised';
33+
}
34+
35+
// response
36+
$response = [
37+
'user' => $user,
38+
'success' => $success,
39+
'layout' => $layout,
40+
'message' => $message,
41+
];
42+
return response()->json($response);
43+
}
44+
45+
public function checkAuth()
46+
{
47+
if (Auth::check()) {
48+
$id = Auth::user()->id;
49+
$user = User::find($id);
50+
$success = true;
51+
$layout = 'layout';
52+
$message = 'User login successfully';
53+
} else {
54+
$user = '';
55+
$success = false;
56+
$layout = 'login';
57+
$message = 'Unauthorised';
58+
}
59+
60+
// response
61+
$response = [
62+
'user' => $user,
63+
'success' => $success,
64+
'layout' => $layout,
65+
'message' => $message,
66+
];
67+
return response()->json($response);
68+
}
69+
70+
/**
71+
* logout
72+
*/
73+
public function logout()
74+
{
75+
try {
76+
$user = '';
77+
Session::flush();
78+
$success = false;
79+
$layout = 'login';
80+
$message = 'Successfully logged out';
81+
} catch (\Illuminate\Database\QueryException $ex) {
82+
$user = '';
83+
$success = false;
84+
$layout = 'login';
85+
$message = $ex->getMessage();
86+
}
87+
88+
// response
89+
$response = [
90+
'user' => $user,
91+
'success' => $success,
92+
'layout' => $layout,
93+
'message' => $message,
94+
];
95+
return response()->json($response);
96+
}
97+
}

app/Http/Kernel.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ class Kernel extends HttpKernel
3737
\App\Http\Middleware\VerifyCsrfToken::class,
3838
\Illuminate\Routing\Middleware\SubstituteBindings::class,
3939
],
40-
4140
'api' => [
42-
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
41+
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
4342
'throttle:api',
4443
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4544
],

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"php": "^8.0.2",
99
"guzzlehttp/guzzle": "^7.2",
1010
"laravel/framework": "^9.19",
11-
"laravel/sanctum": "^2.14.1",
11+
"laravel/sanctum": "^2.15",
1212
"laravel/tinker": "^2.7"
1313
},
1414
"require-dev": {

0 commit comments

Comments
 (0)