Skip to content

Commit

Permalink
Merge pull request #398 from LavaLite/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
georgemjohn authored Jul 20, 2023
2 parents ecc39a2 + 101f7c5 commit 6b28186
Show file tree
Hide file tree
Showing 40 changed files with 1,095 additions and 664 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ Homestead.json
# composer files
composer.dev.json
composer.lock
package-lock.json

# package files
package-lock.json

# all lock files
*.lock
107 changes: 107 additions & 0 deletions app/Http/Controllers/Auth/AuthenticatedApiController.php
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 app/Http/Controllers/Auth/AuthenticatedSessionController.php
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('/');
}
}
40 changes: 0 additions & 40 deletions app/Http/Controllers/Auth/ConfirmPasswordController.php

This file was deleted.

59 changes: 59 additions & 0 deletions app/Http/Controllers/Auth/ConfirmablePasswordController.php
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);
}
}
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 app/Http/Controllers/Auth/EmailVerificationPromptController.php
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')]);
}
}
51 changes: 0 additions & 51 deletions app/Http/Controllers/Auth/ForgotPasswordController.php

This file was deleted.

Loading

0 comments on commit 6b28186

Please sign in to comment.