integration
This commit is contained in:
parent
d511a591fa
commit
6ac75efe43
|
@ -5,6 +5,9 @@ APP_DEBUG=true
|
|||
APP_TIMEZONE=UTC
|
||||
APP_URL=http://localhost
|
||||
|
||||
|
||||
|
||||
|
||||
APP_LOCALE=en
|
||||
APP_FALLBACK_LOCALE=en
|
||||
APP_FAKER_LOCALE=en_US
|
||||
|
|
|
@ -12,7 +12,7 @@ class ApiService
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->baseUrl = config('app.api_base_url');
|
||||
$this->baseUrl = rtrim(env('API_URL', '/'));
|
||||
}
|
||||
|
||||
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;
|
||||
// $this->defaultHeaders['Authorization'] = 'Bearer ' . $token;
|
||||
// return $this->makeRequest('get', $url, $params);
|
||||
// }
|
||||
|
||||
// public function post($url, $params = [])
|
||||
// {
|
||||
// return $this->makeRequest('post', $url, $params);
|
||||
// }
|
||||
|
||||
public function get(string $endpoint, array $query = [])
|
||||
{
|
||||
$token = $this->cookieService->getCookie()['token'] ?? null;
|
||||
$this->defaultHeaders['Authorization'] = 'Bearer ' . $token;
|
||||
return $this->makeRequest('get', $url, $params);
|
||||
return Http::get("{$this->baseUrl}/{$endpoint}", $data);
|
||||
}
|
||||
|
||||
public function post($url, $params = [])
|
||||
public function post(string $endpoint, array $data = [])
|
||||
{
|
||||
return $this->makeRequest('post', $url, $params);
|
||||
return Http::post("{$this->baseUrl}/{$endpoint}", $data);
|
||||
}
|
||||
|
||||
public function put($url, $params = [])
|
||||
|
|
|
@ -47,9 +47,9 @@ return [
|
|||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', 'db_mysql'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'laravel-cms'),
|
||||
'username' => env('DB_USERNAME', 'laravel_user'),
|
||||
'password' => env('DB_PASSWORD', 'password'),
|
||||
'database' => env('DB_DATABASE', 'unioil-app'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', 'secret'),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||
'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,16 +11,11 @@ services:
|
|||
working_dir: /var/www
|
||||
volumes:
|
||||
- .:/var/www
|
||||
depends_on:
|
||||
db_mysql:
|
||||
condition: service_healthy
|
||||
command: >
|
||||
/bin/sh -c '
|
||||
mkdir -p /var/www/storage /var/www/bootstrap/cache &&
|
||||
/bin/sh -c 'mkdir -p /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 &&
|
||||
composer install --no-dev --optimize-autoloader &&
|
||||
php artisan migrate --force &&
|
||||
php-fpm'
|
||||
healthcheck:
|
||||
test: [ "CMD", "sh", "-c", "pgrep php-fpm" ]
|
||||
|
@ -29,32 +24,18 @@ services:
|
|||
retries: 10
|
||||
networks:
|
||||
- app_network
|
||||
|
||||
# MySQL
|
||||
db_mysql:
|
||||
image: mysql:8.0
|
||||
container_name: db_mysql
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: newpassword
|
||||
MYSQL_DATABASE: laravel-cms
|
||||
MYSQL_USER: laravel_user
|
||||
MYSQL_PASSWORD: password
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
|
||||
volumes:
|
||||
- mysql-data:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-pnewpassword"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
networks:
|
||||
- app_network
|
||||
- API_URL=http://web:80
|
||||
- DB_HOST=db_mysql
|
||||
- DB_PORT=3306
|
||||
- DB_DATABASE=unioil-app
|
||||
- DB_USERNAME=root
|
||||
- DB_PASSWORD=secret
|
||||
|
||||
# Nginx
|
||||
web:
|
||||
# Nginx (renamed to avoid conflict)
|
||||
nginx-frontend:
|
||||
image: nginx:1.26.3-alpine
|
||||
container_name: web
|
||||
container_name: web-app
|
||||
restart: always
|
||||
ports:
|
||||
- "8000:80"
|
||||
|
@ -72,9 +53,7 @@ services:
|
|||
networks:
|
||||
- app_network
|
||||
|
||||
volumes:
|
||||
mysql-data:
|
||||
|
||||
networks:
|
||||
app_network:
|
||||
external: true
|
||||
driver: bridge
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frontend/docker/nginx/default.conf
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
@ -12,7 +13,7 @@ server {
|
|||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
include fastcgi.conf;
|
||||
fastcgi_pass app:9000;
|
||||
fastcgi_pass laravel-app:9000; # Matches frontend's 'app' service
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||
fastcgi_param DOCUMENT_ROOT $realpath_root;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^10.4.20",
|
||||
"axios": "^1.7.4",
|
||||
"axios": "^1.9.0",
|
||||
"concurrently": "^9.0.1",
|
||||
"laravel-vite-plugin": "^1.2.0",
|
||||
"postcss": "^8.4.47",
|
||||
|
@ -911,9 +911,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.8.4",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.8.4.tgz",
|
||||
"integrity": "sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==",
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz",
|
||||
"integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^10.4.20",
|
||||
"axios": "^1.7.4",
|
||||
"axios": "^1.9.0",
|
||||
"concurrently": "^9.0.1",
|
||||
"laravel-vite-plugin": "^1.2.0",
|
||||
"postcss": "^8.4.47",
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
import './bootstrap';
|
||||
import axios from 'axios';
|
||||
window.axios = axios; // Make axios globally available
|
|
@ -764,3 +764,4 @@
|
|||
renderTable();
|
||||
renderPagination();
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
@ -297,5 +297,5 @@
|
|||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||
</html>
|
|
@ -29,6 +29,6 @@
|
|||
</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/axios/dist/axios.min.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,10 +1,10 @@
|
|||
```php
|
||||
@extends('layouts.login')
|
||||
|
||||
@section('content')
|
||||
<div class="container py-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12 col-md-6">
|
||||
|
||||
<img src="{{ asset('img/logo.png') }}" alt="Unioil Logo" class="img-fluid" style="max-width: 150px;">
|
||||
|
||||
<div class="mb-3 text-center">
|
||||
|
@ -12,37 +12,34 @@
|
|||
<span style="font-size: 14px;" class="text-muted">Sign in to continue</span>
|
||||
</div>
|
||||
|
||||
<form>
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold" style="font-size: 13px; color: #003366;">Enter
|
||||
Username</label>
|
||||
<!-- Error/Success Messages -->
|
||||
<div id="alert" class="alert d-none" role="alert"></div>
|
||||
|
||||
<input type="text" class="form-control" placeholder="Username">
|
||||
<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>
|
||||
|
||||
<!-- Mockup password input -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold text-primary"
|
||||
style="font-size: 13px; color: #003366 !important;">Enter Password</label>
|
||||
<input type="password" class="form-control" placeholder="Password">
|
||||
<label class="form-label fw-semibold text-primary" style="font-size: 13px; color: #003366 !important;">Enter Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-6">
|
||||
<a href="#" class="text-decoration-none text-primary">Forgot Username</a>
|
||||
<a href="#" class="text-decoration-none text-primary" data-bs-toggle="modal" data-bs-target="#forgotPasswordModal">Forgot Username</a>
|
||||
</div>
|
||||
<div class="col-6 text-end">
|
||||
<a href="{{ url('/my-profile') }}" class="btn btn-primary w-100"
|
||||
style="background-color: #E74610; border-color: #E74610;">
|
||||
<button type="submit" class="btn btn-primary w-100" style="background-color: #E74610; border-color: #E74610;">
|
||||
Login
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Modal Simulation -->
|
||||
<!-- <div class="modal fade show d-block mt-5" tabindex="-1" style="background-color: rgba(0,0,0,0.3); display: none;">
|
||||
<!-- Forgot Password Modal -->
|
||||
<div class="modal fade" id="forgotPasswordModal" tabindex="-1" aria-labelledby="forgotPasswordModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" style="max-width: 337px;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
|
@ -53,12 +50,69 @@
|
|||
</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>
|
||||
<button class="btn btn-primary" data-bs-dismiss="modal" style="background-color: #E74610; border-color: #E74610; width: 64px;">Ok</button>
|
||||
</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
|
||||
```
|
|
@ -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
|
|
@ -149,3 +149,7 @@ Route::get('/fuel-price-schedule', function () {
|
|||
Route::get('/fuel-price-update-logs', function () {
|
||||
return view('pages.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