Skip to content

Commit 101f7c5

Browse files
committed
Update for 10.1.
1 parent 1ba91e8 commit 101f7c5

20 files changed

+431
-116
lines changed

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,9 @@ Homestead.json
106106
# composer files
107107
composer.dev.json
108108
composer.lock
109-
package-lock.json
109+
110+
# package files
111+
package-lock.json
112+
113+
# all lock files
114+
*.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Exception;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\Hash;
9+
use Illuminate\Validation\ValidationException;
10+
use Litepie\Http\Response\AuthResponse;
11+
use Litepie\Theme\ThemeAndViews;
12+
use Litepie\User\Traits\RoutesAndGuards;
13+
14+
class AuthenticatedApiController extends Controller
15+
{
16+
use RoutesAndGuards, ThemeAndViews;
17+
/**
18+
* Create a new controller instance.
19+
*
20+
* @return void
21+
*/
22+
public function __construct()
23+
{
24+
$this->middleware('set.guard');
25+
$this->middleware('auth')->only(['profile']);
26+
$this->middleware('guest')->only(['store']);
27+
$this->middleware(function ($request, $next) {
28+
$this->response = resolve(AuthResponse::class);
29+
$this->setTheme();
30+
return $next($request);
31+
});
32+
33+
}
34+
35+
/**
36+
* Handle an incoming authentication request.
37+
*/
38+
public function store(Request $request)
39+
{
40+
try {
41+
42+
$request->validate([
43+
'email' => 'required|email',
44+
'password' => 'required',
45+
'device_name' => 'required',
46+
]);
47+
$model = $this->getAuthModel();
48+
$user = $model::where('email', $request->email)->first();
49+
if (!$user || !Hash::check($request->password, $user->password)) {
50+
throw ValidationException::withMessages([
51+
'email' => trans('auth.failed'),
52+
]);
53+
}
54+
$token = $user->createToken($request->device_name)->plainTextToken;
55+
56+
$user = $user->only([
57+
'name',
58+
'email',
59+
'sex',
60+
'mobile',
61+
'languages',
62+
'designation',
63+
'picture',
64+
]);
65+
66+
$user['token'] = $token;
67+
return $user;
68+
} catch (Exception $e) {
69+
return $e->errors();
70+
}
71+
}
72+
73+
/**
74+
* Destroy an authenticated session.
75+
*/
76+
public function destroy(Request $request)
77+
{
78+
$request
79+
->user()
80+
->currentAccessToken()
81+
->delete();
82+
return [
83+
'code' => 200,
84+
'message' => trans('auth.loggedout'),
85+
];
86+
}
87+
88+
/**
89+
* Show dashboard for each user.
90+
*
91+
* @return \Illuminate\Http\Response
92+
*/
93+
public function profile(Request $request)
94+
{
95+
$user = $request->user()->only([
96+
'name',
97+
'email',
98+
'sex',
99+
'mobile',
100+
'languages',
101+
'designation',
102+
'picture',
103+
]);
104+
$user['token'] = trim($request->header('Authorization'), 'Bearer ');
105+
return compact('user');
106+
}
107+
}

app/Http/Controllers/Auth/ConfirmablePasswordController.php

+22-5
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,42 @@
88
use Illuminate\Http\Request;
99
use Illuminate\Support\Facades\Auth;
1010
use Illuminate\Validation\ValidationException;
11-
use Inertia\Inertia;
12-
use Inertia\Response;
11+
use Litepie\Http\Response\AuthResponse;
12+
use Litepie\Theme\ThemeAndViews;
1313

1414
class ConfirmablePasswordController extends Controller
1515
{
16+
use ThemeAndViews;
17+
/**
18+
* Create a new controller instance.
19+
*
20+
* @return void
21+
*/
22+
public function __construct()
23+
{
24+
$this->middleware(function ($request, $next) {
25+
$this->response = resolve(AuthResponse::class);
26+
$this->setTheme();
27+
return $next($request);
28+
});
29+
}
1630
/**
1731
* Show the confirm password view.
1832
*/
19-
public function show(): Response
33+
public function show()
2034
{
21-
return Inertia::render('Auth/ConfirmPassword');
35+
return $this->response->setMetaTitle('Confirm Password')
36+
->layout('auth')
37+
->view('auth.confirm-password')
38+
->output();
2239
}
2340

2441
/**
2542
* Confirm the user's password.
2643
*/
2744
public function store(Request $request): RedirectResponse
2845
{
29-
if (! Auth::guard('web')->validate([
46+
if (!Auth::guard(guard())->validate([
3047
'email' => $request->user()->email,
3148
'password' => $request->password,
3249
])) {

app/Http/Controllers/Auth/NewPasswordController.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function create(Request $request)
3939
{
4040
return $this->response->setMetaTitle('Forgot Password')
4141
->layout('auth')
42-
->view('auth.passwords.reset')
42+
->view('password.reset')
4343
->data([
4444
'email' => $request->email,
4545
'token' => $request->route('token'),
@@ -79,7 +79,9 @@ function ($user) use ($request) {
7979
// the application's home authenticated view. If there is an error we can
8080
// redirect them back to where they came from with their error message.
8181
if ($status == Password::PASSWORD_RESET) {
82-
return redirect()->route('login')->with('status', __($status));
82+
return redirect()->route('guard.login',
83+
['guard' => 'user']
84+
)->with('status', __($status));
8385
}
8486

8587
throw ValidationException::withMessages([

app/Http/Controllers/Auth/PasswordResetLinkController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function create()
3636
{
3737
return $this->response->setMetaTitle('Forgot Password')
3838
->layout('auth')
39-
->view('auth.passwords.email')
39+
->view('password.email')
4040
->output();
4141
}
4242

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Laravel\Socialite\Facades\Socialite;
7+
use Litepie\Http\Response\AuthResponse;
8+
use Litepie\User\Traits\RoutesAndGuards;
9+
use Illuminate\Support\Str;
10+
use Illuminate\Foundation\Auth\AuthenticatesUsers;
11+
class SocialAuthController extends Controller
12+
{
13+
/*
14+
|--------------------------------------------------------------------------
15+
| Login Controller
16+
|--------------------------------------------------------------------------
17+
|
18+
| This controller handles authenticating users for the application and
19+
| redirecting them to your home screen. The controller uses a trait
20+
| to conveniently provide its functionality to your applications.
21+
|
22+
*/
23+
use RoutesAndGuards;
24+
use AuthenticatesUsers;
25+
26+
/**
27+
* Create a new controller instance.
28+
*
29+
* @return void
30+
*/
31+
public function __construct()
32+
{
33+
$this->response = resolve(AuthResponse::class);
34+
$this->middleware('guest', ['except' => 'logout']);
35+
}
36+
37+
/**
38+
* Redirect the user to the provider authentication page.
39+
*
40+
* @return Response
41+
*/
42+
public function redirectToProvider($provider)
43+
{
44+
if (!config("services.{$provider}.client_id")) {
45+
abort(404, "Please configure the [{$provider}] parameters.");
46+
}
47+
48+
$this->setCallbackUrl($provider);
49+
50+
return Socialite::driver($provider)->redirect();
51+
}
52+
53+
/**
54+
* Obtain the user information from provider.
55+
*
56+
* @return Response
57+
*/
58+
public function handleProviderCallback($provider)
59+
{
60+
$this->setCallbackUrl($provider);
61+
$guard = $this->getGuard();
62+
$user = Socialite::driver($provider)->user();
63+
$model = $this->getAuthModel();
64+
$data = [
65+
'name' => $user->getName(),
66+
'email' => $user->getEmail(),
67+
'status' => 'Active',
68+
'password' => bcrypt(Str::random(8)),
69+
'api_token' => Str::random(60),
70+
];
71+
$user = $model::whereEmail($data['email'])->first();
72+
73+
if (!is_null($user)) {
74+
app('auth')->login($user, false, $guard);
75+
} else {
76+
$user = $model::create($data);
77+
app('auth')->login($user, false, $guard);
78+
}
79+
80+
return redirect()->intented($this->redirectTo);
81+
}
82+
83+
/**
84+
* undocumented function.
85+
*
86+
* @return void
87+
*
88+
* @author
89+
**/
90+
public function setCallbackUrl($provider)
91+
{
92+
$guard = $this->getGuardRoute();
93+
$currentUrl = config("services.{$provider}.redirect");
94+
$newUrl = str_replace('/user/', "/$guard/", $currentUrl);
95+
config(["services.{$provider}.redirect" => $newUrl]);
96+
}
97+
}

app/Http/Controllers/Controller.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ class Controller extends BaseController
1111
{
1212
use AuthorizesRequests;
1313
use DispatchesJobs;
14-
use ValidatesRequests;
14+
// use ValidatesRequests;
1515

1616
}

app/Http/Controllers/ProfileController.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Illuminate\Http\Request;
99
use Illuminate\Support\Facades\Auth;
1010
use Illuminate\Support\Facades\Redirect;
11-
use Inertia\Inertia;
12-
use Inertia\Response;
1311
use Litepie\Http\Response\AuthResponse;
1412
use Litepie\Theme\ThemeAndViews;
1513

@@ -22,9 +20,8 @@ class ProfileController extends Controller
2220
* @return void
2321
*/
2422
public function __construct()
25-
{
26-
$this->middleware('set.guard');
27-
$this->middleware('auth');
23+
{
24+
2825
$this->middleware(function ($request, $next) {
2926
$this->response = resolve(AuthResponse::class);
3027
$this->setTheme();
@@ -37,15 +34,15 @@ public function __construct()
3734
*/
3835
public function edit(Request $request)
3936
{
40-
return $this->response->setMetaTitle('Forgot Password')
41-
->layout('app')
42-
->view('user.profile')
37+
return $this->response->setMetaTitle('Update Profile')
38+
->layout('user')
39+
->view('user.profile')
4340
->data([
4441
'mustVerifyEmail' => $request->user() instanceof MustVerifyEmail,
4542
'status' => session('status'),
4643
])
4744
->output();
48-
45+
4946
}
5047

5148
/**
@@ -61,7 +58,7 @@ public function update(ProfileUpdateRequest $request): RedirectResponse
6158

6259
$request->user()->save();
6360

64-
return Redirect::route('profile.edit');
61+
return Redirect::back();
6562
}
6663

6764
/**

app/Http/Controllers/PublicController.php

-21
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,4 @@ public function home()
3232
->data(compact('data'))
3333
->output();
3434
}
35-
36-
37-
public function test(){
38-
$content = $this->getContents('https://www.propertyfinder.ae/en/rent/apartment-for-rent-dubai-dubai-sports-city-hera-tower-8805176.html');
39-
return $content;
40-
}
41-
42-
private function getContents($url) {
43-
try{
44-
$response = Http::withHeaders([
45-
"User-Agent" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
46-
"Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
47-
"Accept-Encoding" => "gzip, deflate, sdch",
48-
"Accept-Language" => "en-GB,en-US;q=0.8,en;q=0.6"
49-
])->get($url);
50-
51-
return $response->body();
52-
} catch (Exception $e) {
53-
return null;
54-
}
55-
}
5635
}

0 commit comments

Comments
 (0)