-
Notifications
You must be signed in to change notification settings - Fork 965
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #398 from LavaLite/develop
Develop
- Loading branch information
Showing
40 changed files
with
1,095 additions
and
664 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
app/Http/Controllers/Auth/AuthenticatedApiController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Exception; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Validation\ValidationException; | ||
use Litepie\Http\Response\AuthResponse; | ||
use Litepie\Theme\ThemeAndViews; | ||
use Litepie\User\Traits\RoutesAndGuards; | ||
|
||
class AuthenticatedApiController extends Controller | ||
{ | ||
use RoutesAndGuards, ThemeAndViews; | ||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('set.guard'); | ||
$this->middleware('auth')->only(['profile']); | ||
$this->middleware('guest')->only(['store']); | ||
$this->middleware(function ($request, $next) { | ||
$this->response = resolve(AuthResponse::class); | ||
$this->setTheme(); | ||
return $next($request); | ||
}); | ||
|
||
} | ||
|
||
/** | ||
* Handle an incoming authentication request. | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
try { | ||
|
||
$request->validate([ | ||
'email' => 'required|email', | ||
'password' => 'required', | ||
'device_name' => 'required', | ||
]); | ||
$model = $this->getAuthModel(); | ||
$user = $model::where('email', $request->email)->first(); | ||
if (!$user || !Hash::check($request->password, $user->password)) { | ||
throw ValidationException::withMessages([ | ||
'email' => trans('auth.failed'), | ||
]); | ||
} | ||
$token = $user->createToken($request->device_name)->plainTextToken; | ||
|
||
$user = $user->only([ | ||
'name', | ||
'email', | ||
'sex', | ||
'mobile', | ||
'languages', | ||
'designation', | ||
'picture', | ||
]); | ||
|
||
$user['token'] = $token; | ||
return $user; | ||
} catch (Exception $e) { | ||
return $e->errors(); | ||
} | ||
} | ||
|
||
/** | ||
* Destroy an authenticated session. | ||
*/ | ||
public function destroy(Request $request) | ||
{ | ||
$request | ||
->user() | ||
->currentAccessToken() | ||
->delete(); | ||
return [ | ||
'code' => 200, | ||
'message' => trans('auth.loggedout'), | ||
]; | ||
} | ||
|
||
/** | ||
* Show dashboard for each user. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function profile(Request $request) | ||
{ | ||
$user = $request->user()->only([ | ||
'name', | ||
'email', | ||
'sex', | ||
'mobile', | ||
'languages', | ||
'designation', | ||
'picture', | ||
]); | ||
$user['token'] = trim($request->header('Authorization'), 'Bearer '); | ||
return compact('user'); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
app/Http/Controllers/Auth/AuthenticatedSessionController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\Auth\LoginRequest; | ||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Litepie\Http\Response\AuthResponse; | ||
use Litepie\Theme\ThemeAndViews; | ||
|
||
class AuthenticatedSessionController extends Controller | ||
{ | ||
use ThemeAndViews; | ||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('set.guard'); | ||
$this->middleware(function ($request, $next) { | ||
$this->response = resolve(AuthResponse::class); | ||
$this->setTheme(); | ||
return $next($request); | ||
}); | ||
} | ||
|
||
/** | ||
* Display the login view. | ||
*/ | ||
public function create() | ||
{ | ||
return $this->response | ||
->setMetaTitle(__('Login')) | ||
->layout('auth') | ||
->view('auth.login') | ||
->output(); | ||
} | ||
|
||
/** | ||
* Handle an incoming authentication request. | ||
*/ | ||
public function store(LoginRequest $request): RedirectResponse | ||
{ | ||
$request->authenticate(); | ||
|
||
$request->session()->regenerate(); | ||
|
||
return redirect()->intended(RouteServiceProvider::HOME); | ||
} | ||
|
||
/** | ||
* Destroy an authenticated session. | ||
*/ | ||
public function destroy(Request $request): RedirectResponse | ||
{ | ||
Auth::guard(guard())->logout(); | ||
|
||
$request->session()->invalidate(); | ||
|
||
$request->session()->regenerateToken(); | ||
|
||
return redirect('/'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
app/Http/Controllers/Auth/ConfirmablePasswordController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Validation\ValidationException; | ||
use Litepie\Http\Response\AuthResponse; | ||
use Litepie\Theme\ThemeAndViews; | ||
|
||
class ConfirmablePasswordController extends Controller | ||
{ | ||
use ThemeAndViews; | ||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware(function ($request, $next) { | ||
$this->response = resolve(AuthResponse::class); | ||
$this->setTheme(); | ||
return $next($request); | ||
}); | ||
} | ||
/** | ||
* Show the confirm password view. | ||
*/ | ||
public function show() | ||
{ | ||
return $this->response->setMetaTitle('Confirm Password') | ||
->layout('auth') | ||
->view('auth.confirm-password') | ||
->output(); | ||
} | ||
|
||
/** | ||
* Confirm the user's password. | ||
*/ | ||
public function store(Request $request): RedirectResponse | ||
{ | ||
if (!Auth::guard(guard())->validate([ | ||
'email' => $request->user()->email, | ||
'password' => $request->password, | ||
])) { | ||
throw ValidationException::withMessages([ | ||
'password' => __('auth.password'), | ||
]); | ||
} | ||
|
||
$request->session()->put('auth.password_confirmed_at', time()); | ||
|
||
return redirect()->intended(RouteServiceProvider::HOME); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/Http/Controllers/Auth/EmailVerificationNotificationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
|
||
class EmailVerificationNotificationController extends Controller | ||
{ | ||
/** | ||
* Send a new email verification notification. | ||
*/ | ||
public function store(Request $request): RedirectResponse | ||
{ | ||
if ($request->user()->hasVerifiedEmail()) { | ||
return redirect()->intended(RouteServiceProvider::HOME); | ||
} | ||
|
||
$request->user()->sendEmailVerificationNotification(); | ||
|
||
return back()->with('status', 'verification-link-sent'); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/Http/Controllers/Auth/EmailVerificationPromptController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Inertia\Inertia; | ||
use Inertia\Response; | ||
|
||
class EmailVerificationPromptController extends Controller | ||
{ | ||
/** | ||
* Display the email verification prompt. | ||
*/ | ||
public function __invoke(Request $request): RedirectResponse|Response | ||
{ | ||
return $request->user()->hasVerifiedEmail() | ||
? redirect()->intended(RouteServiceProvider::HOME) | ||
: Inertia::render('Auth/VerifyEmail', ['status' => session('status')]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.