Merge pull request #6 from WDI-Ideas/sayli

Sayli
This commit is contained in:
Sayli Raut
2024-05-24 19:41:22 +05:30
committed by GitHub
19 changed files with 517 additions and 14 deletions

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Http\Controllers\Admin\APIs\Customer_API;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Log;
use App\Services\APIs\CustomerAPIs\ContactUsApiServices;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use Exception;
class ContactUsApiController extends Controller
{
protected $ContactUsApiServices;
public function __construct(ContactUsApiServices $ContactUsApiServices)
{
$this->ContactUsApiServices = $ContactUsApiServices;
}
/**
* Created By : Sayli Raut
* Created at : 24 May 2024
* Use : To store Contact Form for customer & restaurant
*/
public function addContactForm(Request $request)
{
try {
$token = readHeaderToken();
if ($token) {
$iam_principal_id = $token['sub'];
$validator = $this->validateContactForm($request);
if ($validator->fails()) {
$validationErrors = $validator->errors()->all();
Log::error("Contact form validation error: " . implode(", ", $validationErrors));
return jsonResponseWithErrorMessageApi($validationErrors, 403);
}
$request['iam_principal_id'] = $iam_principal_id;
return $this->ContactUsApiServices->addCustomerRestaurantContactForm($request);
} else {
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
}
} catch (Exception $e) {
Log::error('Contact form controller function failed: ' . $e);
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
}
}
/**
* Created By : Hritik
* Created at : 30 JAN 2024
* Use : To validate Customer and Restaurant Contact form data
*/
public function validateContactForm(Request $request)
{
return Validator::make(
$request->all(),
[
'name' => 'required|string|max:50',
'email' => 'required|email|max:50',
'message' => 'required',
// 'iam_principal_xid'=>'required|integer'
]
);
}
}

View File

@@ -24,7 +24,6 @@ class LoginController extends Controller
public function login(Request $request)
{
dd($request);
$validatedData = $request->validate([
'email' => 'required|email',
'password' => 'required|string',

View File

@@ -15,11 +15,11 @@ class Kernel extends HttpKernel
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
// \App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
// \App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
// \App\Http\Middleware\TrimStrings::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
@@ -30,11 +30,11 @@ class Kernel extends HttpKernel
*/
protected $middlewareGroups = [
'web' => [
// \App\Http\Middleware\EncryptCookies::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
// \App\Http\Middleware\VerifyCsrfToken::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
@@ -54,22 +54,23 @@ class Kernel extends HttpKernel
*/
protected $middlewareAliases = [
'checkStatus' => \App\Http\Middleware\CheckStatus::class,
// 'auth' => \App\Http\Middleware\Authenticate::class,
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
// 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
// 'signed' => \App\Http\Middleware\ValidateSignature::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
//custom middleware created by hritik on 29-jan-2024
'customerApiBasicAuth' => \App\Http\Middleware\CustomerApiBasicAuth::class,
// 'restaurantApiBasicAuth' => \App\Http\Middleware\RestaurantApiBasicAuth::class,
'restaurantApiBasicAuth' => \App\Http\Middleware\RestaurantApiBasicAuth::class,
'customer.jwt.verify' => \App\Http\Middleware\CustomerJwtMiddleware::class,
// 'restaurant.jwt.verify' => \App\Http\Middleware\RestaurantJwtMiddleware::class,
'restaurant.jwt.verify' => \App\Http\Middleware\RestaurantJwtMiddleware::class,
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
protected function redirectTo(Request $request): ?string
{
return $request->expectsJson() ? null : route('login');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Middleware;
use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next, string ...$guards): Response
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Symfony\Component\HttpFoundation\Response;
class RestaurantApiBasicAuth
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
/**
* Created By : sayli raut
* Created at : 06 Feb 2024
* Use : To validate request before sending response
*/
$locale = $request->header('Accept-Language');
if ($locale) {
app()->setLocale($locale);
}
$authorizedUsers = [
'CheersRestaurant' => 'gBMRR~LR2p5&T\-9o1oV{nTX6@D%J!', // Replace with actual credentials
];
$authUser = $request->getUser();
$authPass = $request->getPassword();
if (!isset($authorizedUsers[$authUser]) || $authorizedUsers[$authUser] !== $authPass) {
return response()->json([
'error' => 'Authorization Required',
'message' => 'Access denied'
], 401);
}
$lang = $request->header('Accept-Language', null);
if (!empty($lang)) {
app()->setLocale($lang);
}
return $next($request);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Symfony\Component\HttpFoundation\Response;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Facades\JWTAuth;
class RestaurantJwtMiddleware
{
/**
* Created By: Sayli Raut
* Created at: 07 Feb 2024
* Use: To handle Restaurant login authentication middleware
*
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
// Check if the custom access-token header is present
if (!$request->hasHeader('access-token')) {
return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Access token not provided'], 401);
}
// Retrieve the token from the custom access-token header
$token = $request->header('access-token');
try {
// Attempt to authenticate the user based on the token
$user = JWTAuth::setToken($token)->authenticate();
// Check if the user is of restaurant type
if (!$user ||$user->principal_type_xid !== 4) {
return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Unauthorized access'], 401);
}
Session::flash('RestToken', $token);
} catch (JWTException $e) {
return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Invalid token'], 401);
}
return $next($request);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array<int, string>
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array<int, string>|string|null
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
class ValidateSignature extends Middleware
{
/**
* The names of the query string parameters that should be ignored.
*
* @var array<int, string>
*/
protected $except = [
// 'fbclid',
// 'utm_campaign',
// 'utm_content',
// 'utm_medium',
// 'utm_source',
// 'utm_term',
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class ManageContactus extends Model
{
use SoftDeletes;
use HasFactory;
protected $table = "manage_contact_us";
protected $fillable = [
'id',
'principal_xid',
'name',
'email',
'message',
'is_reply',
'reply_message',
'deleted_at',
'created_at',
'updated_at',
'is_active',
'created_by',
'modified_by',
];
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Auth;
class AuthServiceProvider extends ServiceProvider
{
/**
* The model to policy mappings for the application.
*
* @var array<class-string, class-string>
*/
protected $policies = [
//
];
/**
* Register any authentication / authorization services.
*/
public function boot()
{
$this->registerPolicies();
// Register 'admin' guard
Auth::extend('admin', function ($app, $name, array $config) {
return new \Illuminate\Auth\SessionGuard($name, $this->app['session.store']);
});
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Services\APIs\CustomerAPIs;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Models\IamPrincipal;
use App\Models\ManageContactus;
use Throwable;
class ContactUsApiServices
{
public function addCustomerRestaurantContactForm($request)
{
try {
DB::beginTransaction();
//create user_data
$user_data = IamPrincipal::where('id', $request['iam_principal_id'])->first();
if ($user_data) {
// Create a new instance of ManageContactus model
$contact = new ManageContactus();
$contact->principal_xid = $user_data->id;
$contact->name = $request->name;
$contact->email = $request->email;
$contact->message = $request->message;
// Save the contact data
$contact->save();
DB::commit();
//response data
Log::info('Contact form data Created successfully');
return jsonResponseWithSuccessMessageApi(__('success.save_data'), [], 201);
} else {
Log::error('Contact not found in addVendorContactForm.');
return jsonResponseWithErrorMessageApi(__('auth.validation_failed'), 403);
}
} catch (Throwable $ex) {
DB::rollBack();
Log::error('Contact API failed : ' . $ex->getMessage());
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
}
}
}

View File

@@ -0,0 +1,46 @@
<?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('manage_contact_us', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('principal_xid');
$table->string('name', 60)->nullable();
$table->string('email', 100)->nullable();
$table->longText('message')->nullable();
$table->boolean('is_reply')->default(false);
$table->longText('reply_message')->nullable();
$table->softDeletes();
$table->foreign('principal_xid')->references('id')->on('iam_principal')->onDelete('cascade');
$table->timestamps();
$table->boolean('is_active')->default(1)->comment('1=Active, 0=Deactive');
$table->integer('created_by')->nullable();
$table->integer('modified_by')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('manage_contact_us');
}
};

View File

@@ -2,6 +2,7 @@
use App\Http\Controllers\Admin\APIs\Customer_API\AuthController;
use App\Http\Controllers\Admin\APIs\Customer_API\CMSApiController;
use App\Http\Controllers\Admin\APIs\Customer_API\ContactUsApiController;
use Illuminate\Support\Facades\Route;
@@ -26,12 +27,12 @@ Route::get('/v1/list-of-about-us', [CMSApiController::class, 'getAboutUs']);
Route::get('/v1/list-of-privacy-policy', [CMSApiController::class, 'getPrivacyPolicy']);
Route::get('/v1/list-of-news-articles', [CMSApiController::class, 'getNewsArticles']);
//*******************************************************contact us********************************************************
// Route::post('/v1/contact-us', [ContactUsApiController::class, 'addContactForm']);
// });
// });

View File

@@ -29,6 +29,7 @@ Route::post('/otp_verify', [LoginController::class, 'verify_otp']);
Route::get('/password_reset', [LoginController::class, 'reset_password_page']);
Route::post('/password_update', [LoginController::class, 'updatePassword']);
// Route::group(['middleware' => ['checkStatus']], function () {
Route::get('/dashboard', [DashboardController ::class, 'index'])->name('dashboard');
@@ -81,6 +82,6 @@ Route::get('/manage-feedback', [ManageFeedbackController ::class, 'index'])->na
//*******************************************************manage notification********************************************************
Route::get('/manage-notification', [ManageNotificationsController ::class, 'index'])->name('manage.notification');
// });