integration
This commit is contained in:
parent
d511a591fa
commit
6ac75efe43
|
@ -5,6 +5,9 @@ APP_DEBUG=true
|
||||||
APP_TIMEZONE=UTC
|
APP_TIMEZONE=UTC
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
APP_LOCALE=en
|
APP_LOCALE=en
|
||||||
APP_FALLBACK_LOCALE=en
|
APP_FALLBACK_LOCALE=en
|
||||||
APP_FAKER_LOCALE=en_US
|
APP_FAKER_LOCALE=en_US
|
||||||
|
|
|
@ -12,7 +12,7 @@ class ApiService
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->baseUrl = config('app.api_base_url');
|
$this->baseUrl = rtrim(env('API_URL', '/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchData($url, $token = null)
|
public function fetchData($url, $token = null)
|
||||||
|
@ -71,16 +71,26 @@ class ApiService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($url, $params = [])
|
// public function get($url, $params = [])
|
||||||
{
|
// {
|
||||||
$token = $this->cookieService->getCookie()['token'] ?? null;
|
// $token = $this->cookieService->getCookie()['token'] ?? null;
|
||||||
$this->defaultHeaders['Authorization'] = 'Bearer ' . $token;
|
// $this->defaultHeaders['Authorization'] = 'Bearer ' . $token;
|
||||||
return $this->makeRequest('get', $url, $params);
|
// return $this->makeRequest('get', $url, $params);
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function post($url, $params = [])
|
// public function post($url, $params = [])
|
||||||
|
// {
|
||||||
|
// return $this->makeRequest('post', $url, $params);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function get(string $endpoint, array $query = [])
|
||||||
{
|
{
|
||||||
return $this->makeRequest('post', $url, $params);
|
return Http::get("{$this->baseUrl}/{$endpoint}", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function post(string $endpoint, array $data = [])
|
||||||
|
{
|
||||||
|
return Http::post("{$this->baseUrl}/{$endpoint}", $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function put($url, $params = [])
|
public function put($url, $params = [])
|
||||||
|
|
|
@ -47,9 +47,9 @@ return [
|
||||||
'url' => env('DB_URL'),
|
'url' => env('DB_URL'),
|
||||||
'host' => env('DB_HOST', 'db_mysql'),
|
'host' => env('DB_HOST', 'db_mysql'),
|
||||||
'port' => env('DB_PORT', '3306'),
|
'port' => env('DB_PORT', '3306'),
|
||||||
'database' => env('DB_DATABASE', 'laravel-cms'),
|
'database' => env('DB_DATABASE', 'unioil-app'),
|
||||||
'username' => env('DB_USERNAME', 'laravel_user'),
|
'username' => env('DB_USERNAME', 'root'),
|
||||||
'password' => env('DB_PASSWORD', 'password'),
|
'password' => env('DB_PASSWORD', 'secret'),
|
||||||
'unix_socket' => env('DB_SOCKET', ''),
|
'unix_socket' => env('DB_SOCKET', ''),
|
||||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||||
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::create('users', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->string('name');
|
|
||||||
$table->string('email')->unique();
|
|
||||||
$table->timestamp('email_verified_at')->nullable();
|
|
||||||
$table->string('password');
|
|
||||||
$table->rememberToken();
|
|
||||||
$table->timestamps();
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
|
||||||
$table->string('email')->primary();
|
|
||||||
$table->string('token');
|
|
||||||
$table->timestamp('created_at')->nullable();
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::create('sessions', function (Blueprint $table) {
|
|
||||||
$table->string('id')->primary();
|
|
||||||
$table->foreignId('user_id')->nullable()->index();
|
|
||||||
$table->string('ip_address', 45)->nullable();
|
|
||||||
$table->text('user_agent')->nullable();
|
|
||||||
$table->longText('payload');
|
|
||||||
$table->integer('last_activity')->index();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('users');
|
|
||||||
Schema::dropIfExists('password_reset_tokens');
|
|
||||||
Schema::dropIfExists('sessions');
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,57 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::create('jobs', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->string('queue')->index();
|
|
||||||
$table->longText('payload');
|
|
||||||
$table->unsignedTinyInteger('attempts');
|
|
||||||
$table->unsignedInteger('reserved_at')->nullable();
|
|
||||||
$table->unsignedInteger('available_at');
|
|
||||||
$table->unsignedInteger('created_at');
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::create('job_batches', function (Blueprint $table) {
|
|
||||||
$table->string('id')->primary();
|
|
||||||
$table->string('name');
|
|
||||||
$table->integer('total_jobs');
|
|
||||||
$table->integer('pending_jobs');
|
|
||||||
$table->integer('failed_jobs');
|
|
||||||
$table->longText('failed_job_ids');
|
|
||||||
$table->mediumText('options')->nullable();
|
|
||||||
$table->integer('cancelled_at')->nullable();
|
|
||||||
$table->integer('created_at');
|
|
||||||
$table->integer('finished_at')->nullable();
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->string('uuid')->unique();
|
|
||||||
$table->text('connection');
|
|
||||||
$table->text('queue');
|
|
||||||
$table->longText('payload');
|
|
||||||
$table->longText('exception');
|
|
||||||
$table->timestamp('failed_at')->useCurrent();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('jobs');
|
|
||||||
Schema::dropIfExists('job_batches');
|
|
||||||
Schema::dropIfExists('failed_jobs');
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -11,50 +11,31 @@ services:
|
||||||
working_dir: /var/www
|
working_dir: /var/www
|
||||||
volumes:
|
volumes:
|
||||||
- .:/var/www
|
- .:/var/www
|
||||||
depends_on:
|
|
||||||
db_mysql:
|
|
||||||
condition: service_healthy
|
|
||||||
command: >
|
command: >
|
||||||
/bin/sh -c '
|
/bin/sh -c 'mkdir -p /var/www/storage /var/www/bootstrap/cache &&
|
||||||
mkdir -p /var/www/storage /var/www/bootstrap/cache &&
|
chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache &&
|
||||||
chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache &&
|
chmod -R 775 /var/www/storage /var/www/bootstrap/cache &&
|
||||||
chmod -R 775 /var/www/storage /var/www/bootstrap/cache &&
|
composer install --no-dev --optimize-autoloader &&
|
||||||
composer install --no-dev --optimize-autoloader &&
|
php-fpm'
|
||||||
php artisan migrate --force &&
|
|
||||||
php-fpm '
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "sh", "-c", "pgrep php-fpm"]
|
test: [ "CMD", "sh", "-c", "pgrep php-fpm" ]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 10
|
retries: 10
|
||||||
networks:
|
networks:
|
||||||
- app_network
|
- app_network
|
||||||
|
|
||||||
# MySQL
|
|
||||||
db_mysql:
|
|
||||||
image: mysql:8.0
|
|
||||||
container_name: db_mysql
|
|
||||||
restart: always
|
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: newpassword
|
- API_URL=http://web:80
|
||||||
MYSQL_DATABASE: laravel-cms
|
- DB_HOST=db_mysql
|
||||||
MYSQL_USER: laravel_user
|
- DB_PORT=3306
|
||||||
MYSQL_PASSWORD: password
|
- DB_DATABASE=unioil-app
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
|
- DB_USERNAME=root
|
||||||
volumes:
|
- DB_PASSWORD=secret
|
||||||
- mysql-data:/var/lib/mysql
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-pnewpassword"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
networks:
|
|
||||||
- app_network
|
|
||||||
|
|
||||||
# Nginx
|
# Nginx (renamed to avoid conflict)
|
||||||
web:
|
nginx-frontend:
|
||||||
image: nginx:1.26.3-alpine
|
image: nginx:1.26.3-alpine
|
||||||
container_name: web
|
container_name: web-app
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "8000:80"
|
- "8000:80"
|
||||||
|
@ -65,16 +46,14 @@ services:
|
||||||
app:
|
app:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost"]
|
test: [ "CMD", "curl", "-f", "http://localhost" ]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 5
|
retries: 5
|
||||||
networks:
|
networks:
|
||||||
- app_network
|
- app_network
|
||||||
|
|
||||||
volumes:
|
|
||||||
mysql-data:
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
app_network:
|
app_network:
|
||||||
|
external: true
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frontend/docker/nginx/default.conf
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
|
@ -12,7 +13,7 @@ server {
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
try_files $uri =404;
|
try_files $uri =404;
|
||||||
include fastcgi.conf;
|
include fastcgi.conf;
|
||||||
fastcgi_pass app:9000;
|
fastcgi_pass laravel-app:9000; # Matches frontend's 'app' service
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||||
fastcgi_param DOCUMENT_ROOT $realpath_root;
|
fastcgi_param DOCUMENT_ROOT $realpath_root;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
"axios": "^1.7.4",
|
"axios": "^1.9.0",
|
||||||
"concurrently": "^9.0.1",
|
"concurrently": "^9.0.1",
|
||||||
"laravel-vite-plugin": "^1.2.0",
|
"laravel-vite-plugin": "^1.2.0",
|
||||||
"postcss": "^8.4.47",
|
"postcss": "^8.4.47",
|
||||||
|
@ -911,9 +911,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "1.8.4",
|
"version": "1.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.8.4.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz",
|
||||||
"integrity": "sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==",
|
"integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.15.6",
|
"follow-redirects": "^1.15.6",
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
"axios": "^1.7.4",
|
"axios": "^1.9.0",
|
||||||
"concurrently": "^9.0.1",
|
"concurrently": "^9.0.1",
|
||||||
"laravel-vite-plugin": "^1.2.0",
|
"laravel-vite-plugin": "^1.2.0",
|
||||||
"postcss": "^8.4.47",
|
"postcss": "^8.4.47",
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
import './bootstrap';
|
import './bootstrap';
|
||||||
|
import axios from 'axios';
|
||||||
|
window.axios = axios; // Make axios globally available
|
|
@ -763,4 +763,5 @@
|
||||||
|
|
||||||
renderTable();
|
renderTable();
|
||||||
renderPagination();
|
renderPagination();
|
||||||
</script>
|
</script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
@ -297,5 +297,5 @@
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||||
</html>
|
</html>
|
|
@ -29,6 +29,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,64 +1,118 @@
|
||||||
|
```php
|
||||||
@extends('layouts.login')
|
@extends('layouts.login')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="container py-5">
|
<div class="container py-5">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-12 col-md-6">
|
<div class="col-12 col-md-6">
|
||||||
|
<img src="{{ asset('img/logo.png') }}" alt="Unioil Logo" class="img-fluid" style="max-width: 150px;">
|
||||||
|
|
||||||
<img src="{{ asset('img/logo.png') }}" alt="Unioil Logo" class="img-fluid" style="max-width: 150px;">
|
<div class="mb-3 text-center">
|
||||||
|
<h4 class="mb-1 fw-bold">Welcome</h4>
|
||||||
|
<span style="font-size: 14px;" class="text-muted">Sign in to continue</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mb-3 text-center">
|
<!-- Error/Success Messages -->
|
||||||
<h4 class="mb-1 fw-bold">Welcome</h4>
|
<div id="alert" class="alert d-none" role="alert"></div>
|
||||||
<span style="font-size: 14px;" class="text-muted">Sign in to continue</span>
|
|
||||||
|
<form id="loginForm">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label fw-semibold" style="font-size: 13px; color: #003366;">Enter Username</label>
|
||||||
|
<input type="text" class="form-control" id="username" name="username" placeholder="Username" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form>
|
<div class="mb-3">
|
||||||
<div class="mb-3">
|
<label class="form-label fw-semibold text-primary" style="font-size: 13px; color: #003366 !important;">Enter Password</label>
|
||||||
<label class="form-label fw-semibold" style="font-size: 13px; color: #003366;">Enter
|
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
|
||||||
Username</label>
|
</div>
|
||||||
|
|
||||||
<input type="text" class="form-control" placeholder="Username">
|
<div class="row mt-4">
|
||||||
|
<div class="col-6">
|
||||||
|
<a href="#" class="text-decoration-none text-primary" data-bs-toggle="modal" data-bs-target="#forgotPasswordModal">Forgot Username</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-6 text-end">
|
||||||
<!-- Mockup password input -->
|
<button type="submit" class="btn btn-primary w-100" style="background-color: #E74610; border-color: #E74610;">
|
||||||
<div class="mb-3">
|
Login
|
||||||
<label class="form-label fw-semibold text-primary"
|
</button>
|
||||||
style="font-size: 13px; color: #003366 !important;">Enter Password</label>
|
|
||||||
<input type="password" class="form-control" placeholder="Password">
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<div class="row mt-4">
|
<!-- Forgot Password Modal -->
|
||||||
<div class="col-6">
|
<div class="modal fade" id="forgotPasswordModal" tabindex="-1" aria-labelledby="forgotPasswordModalLabel" aria-hidden="true">
|
||||||
<a href="#" class="text-decoration-none text-primary">Forgot Username</a>
|
<div class="modal-dialog modal-dialog-centered" style="max-width: 337px;">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-body">
|
||||||
|
<h4>Forgot Password</h4>
|
||||||
|
<p>
|
||||||
|
To have your password reset, please contact <br>
|
||||||
|
Unioil's admin at <a href="mailto:admin@unioil.com" class="text-primary">admin@unioil.com</a>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6 text-end">
|
<div class="modal-footer justify-content-end">
|
||||||
<a href="{{ url('/my-profile') }}" class="btn btn-primary w-100"
|
<button class="btn btn-primary" data-bs-dismiss="modal" style="background-color: #E74610; border-color: #E74610; width: 64px;">Ok</button>
|
||||||
style="background-color: #E74610; border-color: #E74610;">
|
|
||||||
Login
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
|
||||||
<!-- Modal Simulation -->
|
|
||||||
<!-- <div class="modal fade show d-block mt-5" tabindex="-1" style="background-color: rgba(0,0,0,0.3); display: none;">
|
|
||||||
<div class="modal-dialog modal-dialog-centered" style="max-width: 337px;">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-body">
|
|
||||||
<h4>Forgot Password</h4>
|
|
||||||
<p>
|
|
||||||
To have your password reset, please contact <br>
|
|
||||||
Unioil's admin at <a href="mailto:admin@unioil.com" class="text-primary">admin@unioil.com</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer justify-content-end">
|
|
||||||
<button class="btn btn-primary" style="background-color: #E74610; border-color: #E74610; width: 64px;">Ok</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div> -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Axios CDN -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById('loginForm').addEventListener('submit', async function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const username = document.getElementById('username').value.trim();
|
||||||
|
const password = document.getElementById('password').value.trim();
|
||||||
|
const alertBox = document.getElementById('alert');
|
||||||
|
|
||||||
|
// Use environment variable for the API base URL
|
||||||
|
const apiBaseUrl = '{{ env('API_URL', 'http://web:80') }}/api';
|
||||||
|
|
||||||
|
// Reset alert box
|
||||||
|
alertBox.classList.add('d-none');
|
||||||
|
alertBox.classList.remove('alert-success', 'alert-danger');
|
||||||
|
alertBox.textContent = '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Validate username
|
||||||
|
const usernameResponse = await axios.post(`${apiBaseUrl}/cms/login_username`, { username });
|
||||||
|
if (!usernameResponse.data.success) {
|
||||||
|
throw new Error(usernameResponse.data.message || 'Invalid username');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate password
|
||||||
|
const passwordResponse = await axios.post(`${apiBaseUrl}/cms/login_password`, { username, password });
|
||||||
|
if (!passwordResponse.data.success) {
|
||||||
|
throw new Error(passwordResponse.data.message || 'Invalid password');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success
|
||||||
|
alertBox.classList.remove('d-none', 'alert-danger');
|
||||||
|
alertBox.classList.add('alert-success');
|
||||||
|
alertBox.textContent = 'Login successful! Redirecting...';
|
||||||
|
|
||||||
|
// Store token
|
||||||
|
if (passwordResponse.data.token) {
|
||||||
|
localStorage.setItem('authToken', passwordResponse.data.token);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = '{{ url("/my-profile") }}';
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
// Log detailed error to console for debugging
|
||||||
|
console.error('Login error:', error, error.response);
|
||||||
|
alertBox.classList.remove('d-none', 'alert-success');
|
||||||
|
alertBox.classList.add('alert-danger');
|
||||||
|
alertBox.textContent = error.response?.data?.message || error.message || 'Login failed. Please try again.';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
```
|
|
@ -0,0 +1,67 @@
|
||||||
|
@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
|
|
@ -148,4 +148,8 @@ Route::get('/fuel-price-schedule', function () {
|
||||||
|
|
||||||
Route::get('/fuel-price-update-logs', function () {
|
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