integration
This commit is contained in:
parent
5d52948d50
commit
8a24e65251
|
@ -4,61 +4,133 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
|
||||||
|
|
||||||
class AuthController extends Controller
|
class AuthController extends Controller
|
||||||
{
|
{
|
||||||
|
protected $apiBaseUrl = 'http://192.168.100.6:8081/api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the login form
|
||||||
|
*/
|
||||||
public function showLoginForm()
|
public function showLoginForm()
|
||||||
{
|
{
|
||||||
return view('login');
|
return view('login');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login(Request $request): RedirectResponse
|
/**
|
||||||
|
* Handle login form submission by calling the API
|
||||||
|
*/
|
||||||
|
public function login(Request $request)
|
||||||
{
|
{
|
||||||
$validator = Validator::make($request->all(), [
|
$url = "{$this->apiBaseUrl}/cms/login_password";
|
||||||
'username' => 'required|string',
|
$csrfToken = $request->session()->token();
|
||||||
'password' => 'required|string',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return redirect()->back()
|
|
||||||
->withErrors($validator)
|
|
||||||
->withInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = Http::timeout(30)->post(config('services.backend_api.url') . '/api/cms/login_password', [
|
$response = Http::withHeaders([
|
||||||
'username' => $request->username,
|
'X-CSRF-TOKEN' => $csrfToken,
|
||||||
'password' => $request->password,
|
'Accept' => 'application/json',
|
||||||
|
])->post($url, [
|
||||||
|
'username' => $request->input('username'),
|
||||||
|
'password' => $request->input('password'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$json = $response->json();
|
$data = $response->json();
|
||||||
|
|
||||||
if ($response->successful()) {
|
// Log the full response for debugging
|
||||||
if ($json['code'] === 200) {
|
Log::info('Login API Response: ', [$data]);
|
||||||
Session::put('user', $json['data']['user'] ?? null);
|
|
||||||
return redirect('my-profile');
|
if ($response->successful() && isset($data['code']) && $data['code'] === 200) {
|
||||||
|
if (isset($data['data']) && isset($data['data']['access_token'])) {
|
||||||
|
session(['token' => $data['data']['access_token']]);
|
||||||
|
return redirect()->intended(route('my-profile'));
|
||||||
|
} elseif (isset($data['data']['prompt_password'])) {
|
||||||
|
session(['admin_uuid' => $data['data']['admin_uuid']]);
|
||||||
|
return redirect()->route('password.change.form');
|
||||||
} else {
|
} else {
|
||||||
return redirect()->back()
|
return redirect()->back()->withErrors(['login' => 'Invalid API response or no token received.']);
|
||||||
->withErrors(['username' => $json['message'] ?? 'Login failed.'])
|
|
||||||
->withInput();
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$message = $json['message'] ?? 'Login request failed. Please try again.';
|
|
||||||
return redirect()->back()
|
|
||||||
->withErrors(['username' => $message])
|
|
||||||
->withInput();
|
|
||||||
}
|
}
|
||||||
} catch (\Illuminate\Http\Client\ConnectionException $e) {
|
|
||||||
return redirect()->back()
|
return redirect()->back()->withErrors(['login' => $data['message'] ?? 'Login failed.']);
|
||||||
->withErrors(['username' => 'Unable to connect to the server. Please try again later.'])
|
|
||||||
->withInput();
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return redirect()->back()
|
Log::error('Login Exception: ' . $e->getMessage());
|
||||||
->withErrors(['username' => 'An error occurred: ' . $e->getMessage()])
|
return redirect()->back()->withErrors(['login' => 'Login request failed: ' . $e->getMessage()]);
|
||||||
->withInput();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the change password form
|
||||||
|
*/
|
||||||
|
public function showChangePasswordForm()
|
||||||
|
{
|
||||||
|
if (!session()->has('admin_uuid')) {
|
||||||
|
return redirect()->route('login')->withErrors(['error' => 'Unauthorized access']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('change-password');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle change password form submission by calling the API
|
||||||
|
*/
|
||||||
|
public function changePassword(Request $request)
|
||||||
|
{
|
||||||
|
$url = "{$this->apiBaseUrl}/cms/login_changePassword";
|
||||||
|
$csrfToken = $request->session()->token();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = Http::withHeaders([
|
||||||
|
'X-CSRF-TOKEN' => $csrfToken,
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
'Authorization' => 'Bearer ' . session('token'),
|
||||||
|
])->post($url, [
|
||||||
|
'admin_uuid' => $request->input('admin_uuid'),
|
||||||
|
'password' => $request->input('password'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = $response->json();
|
||||||
|
|
||||||
|
Log::info('Change Password API Response: ', [$data]);
|
||||||
|
|
||||||
|
if ($response->successful() && isset($data['code']) && $data['code'] === 200) {
|
||||||
|
if (isset($data['data']['access_token'])) {
|
||||||
|
session(['token' => $data['data']['access_token']]);
|
||||||
|
} elseif (isset($data['data']['token'])) {
|
||||||
|
session(['token' => $data['data']['token']]);
|
||||||
|
}
|
||||||
|
session()->forget('admin_uuid');
|
||||||
|
return redirect()->route('my-profile')->with('success', $data['message'] ?? 'Password changed successfully');
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->back()->withErrors(['error' => $data['message'] ?? 'Failed to change password']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Change Password Exception: ' . $e->getMessage());
|
||||||
|
return redirect()->back()->withErrors(['error' => 'Password change request failed: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle logout by calling the API
|
||||||
|
*/
|
||||||
|
public function logout(Request $request)
|
||||||
|
{
|
||||||
|
$url = "{$this->apiBaseUrl}/logout_cms";
|
||||||
|
$csrfToken = $request->session()->token();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Http::withHeaders([
|
||||||
|
'X-CSRF-TOKEN' => $csrfToken,
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
'Authorization' => 'Bearer ' . session('token'),
|
||||||
|
])->post($url);
|
||||||
|
|
||||||
|
session()->flush();
|
||||||
|
return redirect()->route('login')->with('success', 'Logged out successfully');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Logout Exception: ' . $e->getMessage());
|
||||||
|
session()->flush();
|
||||||
|
return redirect()->route('login')->with('success', 'Logged out successfully');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
|
||||||
|
class ChangePasswordController extends Controller
|
||||||
|
{
|
||||||
|
protected $apiBaseUrl;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->apiBaseUrl = env('API_BASE_URL', 'http://your-backend-api-url');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showChangePasswordForm()
|
||||||
|
{
|
||||||
|
return view('change-password');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePassword(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'password' => 'required|min:8|confirmed',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$adminId = Session::get('admin_id');
|
||||||
|
$apiToken = Session::get('api_token');
|
||||||
|
|
||||||
|
if (!$adminId || !$apiToken) {
|
||||||
|
return redirect()->route('login')->with('error', 'You must be logged in to change your password');
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = Http::withToken($apiToken)
|
||||||
|
->get("{$this->apiBaseUrl}/api/admin/{$adminId}");
|
||||||
|
|
||||||
|
if ($response->failed()) {
|
||||||
|
return redirect()->back()->with('error', 'Unable to fetch admin data. Please try again later.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$admin = $response->json();
|
||||||
|
|
||||||
|
if (!$admin) {
|
||||||
|
return redirect()->route('login')->with('error', 'Admin not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$updateResponse = Http::withToken($apiToken)
|
||||||
|
->put("{$this->apiBaseUrl}/api/admin/{$adminId}", [
|
||||||
|
'password' => bcrypt($request->password),
|
||||||
|
'is_passwordChanged' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($updateResponse->failed()) {
|
||||||
|
return redirect()->back()->with('error', 'Failed to update password. Please try again.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('my-profile')->with('success', 'Password updated successfully');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to fetch and display admin profile data
|
||||||
|
public function showProfile()
|
||||||
|
{
|
||||||
|
$adminId = Session::get('admin_id');
|
||||||
|
$apiToken = Session::get('api_token');
|
||||||
|
|
||||||
|
if (!$adminId || !$apiToken) {
|
||||||
|
return redirect()->route('login')->with('error', 'You must be logged in to view your profile');
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = Http::withToken($apiToken)
|
||||||
|
->get("{$this->apiBaseUrl}/api/admin/{$adminId}");
|
||||||
|
|
||||||
|
if ($response->failed()) {
|
||||||
|
return redirect()->back()->with('error', 'Unable to fetch profile data. Please try again later.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$admin = $response->json();
|
||||||
|
|
||||||
|
if (!$admin) {
|
||||||
|
return redirect()->route('login')->with('error', 'Admin not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('my-profile', ['admin' => $admin]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,9 @@
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
@ -19,6 +22,10 @@ class AppServiceProvider extends ServiceProvider
|
||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
//
|
// Share authenticated user with the 'layouts.app' view
|
||||||
|
View::composer('layouts.app', function ($view) {
|
||||||
|
$user = Auth::user();
|
||||||
|
$view->with('user', $user);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ return [
|
||||||
],
|
],
|
||||||
|
|
||||||
'backend_api' => [
|
'backend_api' => [
|
||||||
'url' => env('BACKEND_API_URL', 'http://192.168.56.1:80'),
|
'url' => 'http://192.168.100.6:8081', // Use the backend container name and internal port
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@ services:
|
||||||
- .:/var/www/html
|
- .:/var/www/html
|
||||||
- ./storage:/var/www/html/storage
|
- ./storage:/var/www/html/storage
|
||||||
- ./bootstrap/cache:/var/www/html/bootstrap/cache
|
- ./bootstrap/cache:/var/www/html/bootstrap/cache
|
||||||
|
depends_on:
|
||||||
|
db_mysql:
|
||||||
|
condition: service_healthy
|
||||||
command: [ "sh", "-c", "/var/www/html/docker/php/entrypoint.sh" ]
|
command: [ "sh", "-c", "/var/www/html/docker/php/entrypoint.sh" ]
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ "CMD", "pgrep", "php-fpm" ]
|
test: [ "CMD", "pgrep", "php-fpm" ]
|
||||||
|
@ -16,8 +19,26 @@ services:
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 10
|
retries: 10
|
||||||
networks:
|
networks:
|
||||||
- frontend_network
|
- app_network
|
||||||
- unioil-mobile-api_app_network
|
|
||||||
|
db_mysql:
|
||||||
|
image: mysql:8.2
|
||||||
|
container_name: unioil-db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: newpassword
|
||||||
|
MYSQL_DATABASE: unioil-database
|
||||||
|
MYSQL_USER: rootuser
|
||||||
|
MYSQL_PASSWORD: password
|
||||||
|
volumes:
|
||||||
|
- mysql-data:/var/lib/mysql
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 5
|
||||||
|
networks:
|
||||||
|
- app_network
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx:alpine
|
image: nginx:alpine
|
||||||
|
@ -32,14 +53,13 @@ services:
|
||||||
app:
|
app:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- frontend_network
|
- app_network
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
mysql-data:
|
||||||
storage-volume:
|
storage-volume:
|
||||||
driver: local
|
driver: local
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
frontend_network:
|
app_network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
unioil-mobile-api_app_network:
|
|
||||||
external: true
|
|
||||||
|
|
|
@ -8,57 +8,50 @@
|
||||||
|
|
||||||
<div class="mb-3 text-center">
|
<div class="mb-3 text-center">
|
||||||
<h4 class="mb-1 fw-bold">Change Password</h4>
|
<h4 class="mb-1 fw-bold">Change Password</h4>
|
||||||
<span style="font-size: 14px;" class="text-muted">Enter your new password</span>
|
<span style="font-size: 14px;" class="text-muted">Enter a new password to continue</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Error/Success Messages -->
|
<!-- Error/Success Messages -->
|
||||||
|
@if ($errors->any())
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
@foreach ($errors->all() as $error)
|
||||||
|
{{ $error }}<br>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@if (session('success'))
|
@if (session('success'))
|
||||||
<div class="alert alert-success" role="alert">
|
<div class="alert alert-success">
|
||||||
{{ session('success') }}
|
{{ session('success') }}
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@if (session('error'))
|
|
||||||
<div class="alert alert-danger" role="alert">
|
|
||||||
{{ session('error') }}
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
@if ($errors->any())
|
|
||||||
<div class="alert alert-danger" role="alert">
|
|
||||||
<ul>
|
|
||||||
@foreach ($errors->all() as $error)
|
|
||||||
<li>{{ $error }}</li>
|
|
||||||
@endforeach
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<form method="POST" action="{{ route('password.submit') }}">
|
<form method="POST" action="{{ route('password.change') }}">
|
||||||
@csrf
|
@csrf
|
||||||
|
<input type="hidden" name="admin_uuid" value="{{ session('admin_uuid') }}">
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label fw-semibold" style="font-size: 13px; color: #003366;">Username</label>
|
<label for="password" class="form-label fw-semibold" style="font-size: 13px; color: #003366;">New Password</label>
|
||||||
<input type="text" class="form-control @error('username') is-invalid @enderror" id="username" name="username" placeholder="Username" value="{{ old('username', session('username')) }}" required readonly>
|
<input type="password" class="form-control" id="password" name="password" placeholder="••••••••" required>
|
||||||
@error('username')
|
|
||||||
<div class="invalid-feedback">{{ $message }}</div>
|
|
||||||
@enderror
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label fw-semibold" style="font-size: 13px; color: #003366;">New Password</label>
|
<label for="password_confirmation" class="form-label fw-semibold" style="font-size: 13px; color: #003366;">Confirm Password</label>
|
||||||
<input type="password" class="form-control @error('new_password') is-invalid @enderror" id="new_password" name="new_password" placeholder="New Password" required>
|
<input type="password" class="form-control" id="password_confirmation" name="password_confirmation" placeholder="••••••••" required>
|
||||||
@error('new_password')
|
|
||||||
<div class="invalid-feedback">{{ $message }}</div>
|
|
||||||
@enderror
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row mt-4">
|
<div class="row mt-4">
|
||||||
<div class="col-12 text-end">
|
<div class="col-6">
|
||||||
<button type="submit" class="btn btn-primary w-100" style="background-color: #E74610; border-color: #E74610;">
|
<a href="{{ route('login') }}" class="text-decoration-none text-primary">Back to Login</a>
|
||||||
Change Password
|
</div>
|
||||||
</button>
|
<div class="col-6 text-end">
|
||||||
|
<button type="submit" class="btn btn-primary w-100" style="background-color: #E74610; border-color: #E74610;">Change Password</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Include Bootstrap 5 JS for modal functionality -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
@endsection
|
@endsection
|
|
@ -230,7 +230,7 @@
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
<a class="nav-link dropdown-toggle d-flex align-items-center gap-2" href="#"
|
<a class="nav-link dropdown-toggle d-flex align-items-center gap-2" href="#"
|
||||||
role="button" data-toggle="dropdown">
|
role="button" data-toggle="dropdown">
|
||||||
<span style="margin-right:5px">LBTek Systems</span>
|
<span style="margin-right:5px">{{ $user->username }}</span>
|
||||||
<i class="fa-solid fa-user-circle" style="padding-right:5px"></i>
|
<i class="fa-solid fa-user-circle" style="padding-right:5px"></i>
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-sm">
|
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-sm">
|
||||||
|
@ -242,12 +242,13 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item d-flex align-items-center gap-2"
|
<form action="{{ route('logout') }}" method="POST">
|
||||||
href="{{ route('login') }}">
|
@csrf
|
||||||
<i class="fa-solid fa-right-from-bracket"
|
<button type="submit" class="dropdown-item d-flex align-items-center gap-2 logout-btn">
|
||||||
style="font-size:16px; color:gray;"></i>
|
<i class="fa-solid fa-right-from-bracket" style="font-size:16px; color:gray;"></i>
|
||||||
<span style="margin-left:5px">Logout</span>
|
<span style="margin-left:5px;color:black">Logout</span>
|
||||||
</a>
|
</button>
|
||||||
|
</form>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -12,23 +12,16 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Error/Success Messages -->
|
<!-- Error/Success Messages -->
|
||||||
@if (session('success'))
|
|
||||||
<div class="alert alert-success" role="alert">
|
|
||||||
{{ session('success') }}
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
@if (session('error'))
|
|
||||||
<div class="alert alert-danger" role="alert">
|
|
||||||
{{ session('error') }}
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger">
|
||||||
<ul>
|
|
||||||
@foreach ($errors->all() as $error)
|
@foreach ($errors->all() as $error)
|
||||||
<li>{{ $error }}</li>
|
{{ $error }}<br>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</div>
|
||||||
|
@endif
|
||||||
|
@if (session('success'))
|
||||||
|
<div class="alert alert-success">
|
||||||
|
{{ session('success') }}
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
@extends('layouts.app')
|
|
||||||
|
|
||||||
@section('content')
|
|
||||||
<div class="container py-5">
|
|
||||||
<h1>Change Password</h1>
|
|
||||||
<div id="alert" class="alert d-none" role="alert"></div>
|
|
||||||
<form id="changePasswordForm">
|
|
||||||
<div class="mb-3">
|
|
||||||
<label class="form-label">New Password</label>
|
|
||||||
<input type="password" class="form-control" id="password" name="password" required>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label class="form-label">Confirm Password</label>
|
|
||||||
<input type="password" class="form-control" id="password_confirmation" name="password_confirmation" required>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn btn-primary">Submit</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
||||||
<script>
|
|
||||||
document.getElementById('changePasswordForm').addEventListener('submit', async function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
const password = document.getElementById('password').value.trim();
|
|
||||||
const passwordConfirmation = document.getElementById('password_confirmation').value.trim();
|
|
||||||
const adminUuid = localStorage.getItem('admin_uuid');
|
|
||||||
const alertBox = document.getElementById('alert');
|
|
||||||
|
|
||||||
if (password !== passwordConfirmation) {
|
|
||||||
alertBox.classList.remove('d-none', 'alert-success');
|
|
||||||
alertBox.classList.add('alert-danger');
|
|
||||||
alertBox.textContent = 'Passwords do not match';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const apiBaseUrl = 'http://localhost:8080/api';
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await axios.post(${apiBaseUrl}/cms/login_changePassword, {
|
|
||||||
admin_uuid: adminUuid,
|
|
||||||
password: password,
|
|
||||||
password_confirmation: passwordConfirmation,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.data.success) {
|
|
||||||
throw new Error(response.data.message || 'Password change failed');
|
|
||||||
}
|
|
||||||
|
|
||||||
alertBox.classList.remove('d-none', 'alert-danger');
|
|
||||||
alertBox.classList.add('alert-success');
|
|
||||||
alertBox.textContent = 'Password changed successfully! Redirecting...';
|
|
||||||
|
|
||||||
localStorage.setItem('authToken', response.data.data.token);
|
|
||||||
localStorage.removeItem('admin_uuid');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location.href = '{{ url("/my-profile") }}';
|
|
||||||
}, 1000);
|
|
||||||
} catch (error) {
|
|
||||||
alertBox.classList.remove('d-none', 'alert-success');
|
|
||||||
alertBox.classList.add('alert-danger');
|
|
||||||
alertBox.textContent = error.response?.data?.message || error.message || 'Password change failed.';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@endsection
|
|
|
@ -9,7 +9,7 @@
|
||||||
<div class="banner-icon me-3">
|
<div class="banner-icon me-3">
|
||||||
<i class="fas fa-user-circle" style="font-size: 40px; color: #6c757d;"></i>
|
<i class="fas fa-user-circle" style="font-size: 40px; color: #6c757d;"></i>
|
||||||
</div>
|
</div>
|
||||||
<h4 class="fw-bold text-primary mb-0" style="margin-left:10px">LBTek Systems</h4>
|
<h4 class="fw-bold text-primary mb-0" style="margin-left:10px">{{ $user->name ?? 'User' }}</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Profile Section -->
|
<!-- Profile Section -->
|
||||||
|
@ -20,22 +20,21 @@
|
||||||
<h3 class="fw-bold mb-3" style="font-size: 20px; font-weight:400">My Information</h3>
|
<h3 class="fw-bold mb-3" style="font-size: 20px; font-weight:400">My Information</h3>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<span class="fw-bold text-dark">Username: </span>
|
<span class="fw-bold text-dark">Username: </span>
|
||||||
<span>lbteksupport</span>
|
<span>{{ $user->username }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<span class="fw-bold text-dark">Email: </span>
|
<span class="fw-bold text-dark">Email: </span>
|
||||||
<a href="mailto:support@lbteksystems.com" class="text-primary">support@lbteksystems.com</a>
|
<a href="mailto:{{ $user->email }}" class="text-primary">{{ $user->email }}</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="fw-bold text-dark">Access Role: </span>
|
<span class="fw-bold text-dark">Access Role: </span>
|
||||||
<span>System Admin</span>
|
<span>{{ $user->role ?? 'System Admin' }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.card {
|
.card {
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
@ -99,32 +98,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
|
||||||
const profileImage = document.getElementById('profileImage');
|
|
||||||
const pictureInput = document.getElementById('profilePictureInput');
|
|
||||||
const changePictureBtn = document.getElementById('changePicture');
|
|
||||||
|
|
||||||
// Load saved profile picture
|
|
||||||
const savedPicture = sessionStorage.getItem('profilePicture');
|
|
||||||
if (savedPicture) {
|
|
||||||
profileImage.src = savedPicture;
|
|
||||||
}
|
|
||||||
|
|
||||||
changePictureBtn?.addEventListener('click', () => {
|
|
||||||
pictureInput?.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
pictureInput?.addEventListener('change', (e) => {
|
|
||||||
const file = e.target.files[0];
|
|
||||||
if (file) {
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = (event) => {
|
|
||||||
profileImage.src = event.target.result;
|
|
||||||
sessionStorage.setItem('profilePicture', event.target.result);
|
|
||||||
};
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@endsection
|
@endsection
|
|
@ -10,11 +10,26 @@ use App\Http\Controllers\AuthController;
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return redirect()->route('login');
|
return redirect()->route('login');
|
||||||
});
|
});
|
||||||
Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login.form');
|
|
||||||
|
// Show login form
|
||||||
|
Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
|
||||||
|
|
||||||
|
// Handle login form submission
|
||||||
Route::post('/login', [AuthController::class, 'login'])->name('login');
|
Route::post('/login', [AuthController::class, 'login'])->name('login');
|
||||||
|
|
||||||
Route::get('/change-password', [AuthController::class, 'showChangePasswordForm'])->name('password.change');
|
// Show change password form
|
||||||
Route::post('/change-password', [AuthController::class, 'changePassword'])->name('password.submit');
|
Route::get('/change-password', [AuthController::class, 'showChangePasswordForm'])->name('password.change.form');
|
||||||
|
|
||||||
|
// Handle change password form submission
|
||||||
|
Route::post('/change-password', [AuthController::class, 'changePassword'])->name('password.change');
|
||||||
|
|
||||||
|
// Redirect to my-profile (adjust as needed)
|
||||||
|
Route::get('/my-profile', function () {
|
||||||
|
return view('my-profile'); // Replace with your actual profile view or controller
|
||||||
|
})->name('my-profile')->middleware('auth');
|
||||||
|
// Handle logout
|
||||||
|
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Route::get('/dashboard', function () {
|
Route::get('/dashboard', function () {
|
||||||
|
@ -90,10 +105,6 @@ Route::get('/fuels', function () {
|
||||||
return view('pages.station locator.fuels');
|
return view('pages.station locator.fuels');
|
||||||
})->name('fuels');
|
})->name('fuels');
|
||||||
|
|
||||||
Route::get('/my-profile', function () {
|
|
||||||
return view('pages.my-profile');
|
|
||||||
})->name('my-profile');
|
|
||||||
|
|
||||||
Route::get('/add-user', function () {
|
Route::get('/add-user', function () {
|
||||||
return view('pages.user-management.add-user');
|
return view('pages.user-management.add-user');
|
||||||
})->name('add-user');
|
})->name('add-user');
|
||||||
|
@ -160,6 +171,3 @@ Route::get('/fuel-price-update-logs', function () {
|
||||||
return view('pages.fuel-price-update-logs');
|
return view('pages.fuel-price-update-logs');
|
||||||
})->name('fuel-price-update-logs');
|
})->name('fuel-price-update-logs');
|
||||||
|
|
||||||
Route::get('/change-password', function () {
|
|
||||||
return view('pages.change-password');
|
|
||||||
})->name('change-password');
|
|
Loading…
Reference in New Issue