fix gitignore

This commit is contained in:
baghizadizn 2025-11-17 08:12:57 +00:00
parent 00390b2505
commit cc4862a8da
9 changed files with 265 additions and 167 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Application; use App\Models\Application;
use App\Models\FileUploader; use App\Models\FileUploader;
use App\Models\Instructors;
use App\Models\User; use App\Models\User;
use App\Providers\RouteServiceProvider; use App\Providers\RouteServiceProvider;
use Carbon\Carbon; use Carbon\Carbon;
@ -12,37 +13,29 @@ use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rules; use Illuminate\Validation\Rules;
use Illuminate\View\View; use Illuminate\View\View;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
class RegisteredUserController extends Controller class RegisteredUserController extends Controller
{ {
/**
* Display the registration view.
*/
public function create(): View public function create(): View
{ {
return view('auth.register'); return view('auth.register');
} }
/**
* Handle an incoming registration request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse public function store(Request $request): RedirectResponse
{ {
$input = $request->all(); $input = $request->all();
if (get_frontend_settings('recaptcha_status') == true && check_recaptcha($input['g-recaptcha-response']) == false) { if (get_frontend_settings('recaptcha_status') == true && check_recaptcha($input['g-recaptcha-response']) == false) {
Session::flash('error', get_phrase('Recaptcha verification failed')); Session::flash('error', get_phrase('Recaptcha verification failed'));
return redirect(route('register.form')); return redirect(route('register.form'));
} }
@ -62,15 +55,37 @@ class RegisteredUserController extends Controller
'password.min' => get_phrase('Password must be at least 8 characters'), 'password.min' => get_phrase('Password must be at least 8 characters'),
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
// Get the first error message to show as flash message
$firstError = $validator->errors()->first(); $firstError = $validator->errors()->first();
Session::flash('error', $firstError); Session::flash('error', $firstError);
return redirect()->back()->withErrors($validator)->withInput(); return redirect()->back()->withErrors($validator)->withInput();
} }
// Check if the user is applying to be an instructor and validate instructor fields
if ($request->has('instructor') && $request->instructor == 1) {
// Validate instructor-specific fields (NIDN, Phone, Document)
$instructorValidator = Validator::make($request->all(), [
'nidn' => ['required', 'string', 'max:11'],
'phone' => ['required', 'string'],
'document' => ['required', 'file', 'mimes:pdf,doc,docx', 'max:2048'],
], [
'nidn.required' => get_phrase('NIDN is required'),
'nidn.string' => get_phrase('NIDN must be a valid number'),
'nidn.max' => get_phrase('NIDN may not be greater than 11 characters'),
'phone.required' => get_phrase('Phone number is required'),
'document.required' => get_phrase('Document is required'),
'document.file' => get_phrase('Document must be a valid file'),
'document.mimes' => get_phrase('Document must be PDF, DOC, or DOCX'),
'document.max' => get_phrase('Document size must be less than 2MB'),
]);
if ($instructorValidator->fails()) {
$firstError = $instructorValidator->errors()->first();
Session::flash('error', $firstError);
return redirect()->back()->withErrors($instructorValidator)->withInput();
}
}
$user_data = [ $user_data = [
'name' => $request->name, 'name' => $request->name,
'email' => $request->email, 'email' => $request->email,
@ -84,36 +99,98 @@ class RegisteredUserController extends Controller
} }
$user = User::create($user_data); $user = User::create($user_data);
event(new Registered($user)); event(new Registered($user));
Auth::login($user);
// If applying as an instructor, process the application // If applying as an instructor, process the application
if ($request->has('instructor')) { if ($request->has('instructor')) {
return $this->processInstructorApplication($request, $user);
}
// Check if application already exists // Log the user in after successful registration
if (Application::where('user_id', $user->id)->exists()) { Auth::login($user);
Session::flash('error', get_phrase('Your request is in process. Please wait for admin to respond.'));
return redirect()->route('become.instructor'); return redirect(RouteServiceProvider::HOME);
}
private function processInstructorApplication(Request $request, User $user): RedirectResponse
{
// Check if application already exists
if (Application::where('user_id', $user->id)->exists()) {
Session::flash('error', get_phrase('Your request is in process. Please wait for admin to respond.'));
return redirect()->route('become.instructor');
}
try {
// Check NIDN with the API
$nidn = $request->nidn;
$api_url = "https://sindig.unesa.ac.id/apipddikti/api?nidn={$nidn}&auto=1";
$response = Http::timeout(30)->get($api_url);
$data = $response->json();
Log::info('API Response for NIDN: ' . $nidn, ['response' => $data]);
// Extract matched dosen data
$matched_dosen = $data['matched_dosen'][0];
Log::info('Instructor data to be saved:', $matched_dosen);
if (!isset($data['ok']) || !isset($data['matched_dosen']) || count($data['matched_dosen']) == 0) {
Session::flash('error', get_phrase('NIDN not found in the system. Please check your NIDN.'));
return redirect()->back()->withInput();
}else if ($matched_dosen['nama'] != $user->name){
Session::flash('error', get_phrase('Name does not match PDDikti records. Please check your name.'));
return redirect()->back()->withInput();
} }
// Process instructor application Log::info('API Response for Nama: ' . $matched_dosen['nama'], ' || nama :',$user->name);
$application['user_id'] = $user->id;
$application['phone'] = $request->phone; // Prepare instructor data - adjust fields according to your database
$application['description'] = $request->description; $instructor = [
'user_id' => $user->id,
'nidn' => $nidn,
'name' => $matched_dosen['nama'] ?? $user->name,
'id_sdm' => $matched_dosen['id'] ?? null,
'id_sms' => $matched_dosen['nama_prodi'] ?? null,
'id_pt' => $matched_dosen['nama_pt'] ?? null
];
Log::info('Instructor data to be saved:', $instructor);
// Upload document // Upload document
$doc = $request->file('document'); if ($request->hasFile('document') && $request->file('document')->isValid()) {
$application['document'] = 'uploads/applications/' . $user->id . Str::random(20) . '.' . $doc->extension(); $doc = $request->file('document');
$fileName = 'uploads/applications/' . $user->id . Str::random(20) . '.' . $doc->extension();
FileUploader::upload($doc, $application['document'], null, null, 300); FileUploader::upload($doc, $fileName, null, null, 300);
} else {
Session::flash('error', 'Document upload failed or no document selected.');
return redirect()->back()->withInput();
}
// Store application // Prepare application data
Application::insert($application); $application = [
'user_id' => $user->id,
'phone' => $request->phone,
'description' => $request->description
];
Session::flash('success', get_phrase('Your application has been submitted.')); // Start database transaction to ensure both records are saved
DB::transaction(function () use ($application, $instructor) {
Application::create($application);
Instructors::create($instructor);
});
Session::flash('success', get_phrase('Your application has been submitted successfully.'));
} catch (\Exception $e) {
Log::error('Instructor registration error:', [
'user_id' => $user->id,
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
Session::flash('error', get_phrase('Error while processing your application. Please try again later!'));
return redirect()->back()->withInput();
} }
return redirect(RouteServiceProvider::HOME); return redirect(RouteServiceProvider::HOME);

View File

@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Instructors extends Model
{
use HasFactory;
protected $fillable = [
'user_id', 'nidn', 'id_sdm', 'id_sms', 'id_pt'
];
}

1
public/phpmyadmin Symbolic link
View File

@ -0,0 +1 @@
/usr/share/phpmyadmin

View File

@ -1,8 +1,14 @@
@php @php
$applicant_details = App\Models\Application::where('id', $id)->first(); $applicant_details = App\Models\Application::where('id', $id)->first();
$applicant_instrucutor = App\Models\Instructors::where('id', $id)->first();
$user = get_user_info($applicant_details->user_id); $user = get_user_info($applicant_details->user_id);
$user_photo = get_user_info($applicant_details->user_id)->photo;
// Ensure the placeholder image path is correct
$placeholder_image = asset('uploads/users/student/placeholder/placeholder.png');
@endphp @endphp
<style> <style>
.instructor-info li:nth-last-child(1){ .instructor-info li:nth-last-child(1){
border: none; border: none;
@ -27,10 +33,15 @@
</style> </style>
<div class="text-center mb-2"> <div class="text-center mb-2">
<img class="mr-2 rounded-circle image-100" src="{{ asset(get_user_info($applicant_details->user_id)->photo) }}" alt="" <img class="mr-2 rounded-circle image-100" src="{{ $user_photo ? asset($user_photo) : $placeholder_image }}" alt=""
height="80"> height="80">
</div> </div>
<p>$placeholder_image: {{ $placeholder_image ?? 'N/A' }}</p>
<p>$user_photo: {{ $user_photo ?? 'N/A' }}</p>
<ul class="instructor-info"> <ul class="instructor-info">
<li> <li>
<span>{{ get_phrase('Applicant') }}</span> <span>{{ get_phrase('Applicant') }}</span>
@ -41,12 +52,16 @@
<span>{{ $user->email }}</span> <span>{{ $user->email }}</span>
</li> </li>
<li> <li>
<span>{{ get_phrase('Phone number') }}</span> <span>{{ get_phrase('NIDN') }}</span>
<span>{{ $user->phone }}</span> <span>{{ $applicant_instrucutor->nidn ?? 'N/A' }}</span>
</li> </li>
<li> <li>
<span>{{ get_phrase('Address') }}</span> <span>{{ get_phrase('Study Program') }}</span>
<span>{{ $user->address }}</span> <span>{{ $applicant_instrucutor->id_sms ?? 'N/A' }}</span>
</li>
<li>
<span>{{ get_phrase('University') }}</span>
<span>{{ $applicant_instrucutor->id_pt?? 'N/A' }}</span>
</li> </li>
<li> <li>
<span>{{ get_phrase('Message') }}&nbsp</span>: &nbsp <span>{{ get_phrase('Message') }}&nbsp</span>: &nbsp

View File

@ -2,145 +2,140 @@
@push('title', get_phrase('Sign Up')) @push('title', get_phrase('Sign Up'))
@push('meta')@endpush @push('meta')@endpush
@push('css') @push('css')
<style> <style>
.form-icons .right { .form-icons .right {
right: 20px; right: 20px;
cursor: pointer !important; cursor: pointer !important;
} }
</style> </style>
@endpush @endpush
@section('content') @section('content')
<section class="login-area"> <section class="login-area">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-7 col-md-6"> <div class="col-lg-7 col-md-6">
<div class="login-img"> <div class="login-img">
<img src="{{ asset('assets/frontend/' . get_frontend_settings('theme') . '/image/signup.gif') }}" alt="register-banner"> <img src="{{ asset('assets/frontend/' . get_frontend_settings('theme') . '/image/signup.gif') }}" alt="register-banner">
</div> </div>
</div> </div>
<div class="col-lg-5 col-md-6"> <div class="col-lg-5 col-md-6">
<form action="{{ route('register') }}" class="global-form login-form mt-25" id="login-form" method="post" enctype="multipart/form-data">@csrf <form action="{{ route('register') }}" class="global-form login-form mt-25" id="login-form" method="post" enctype="multipart/form-data">@csrf
<h4 class="g-title">{{ get_phrase('Sign Up') }}</h4> <h4 class="g-title">{{ get_phrase('Sign Up') }}</h4>
<p class="description">{{ get_phrase('See your growth and get consulting support! ') }}</p> <p class="description">{{ get_phrase('See your growth and get consulting support! ') }}</p>
<div class="form-group mb-5"> <div class="form-group mb-5">
<label for="" class="form-label">{{ get_phrase('Name') }}</label> <label for="" class="form-label">{{ get_phrase('Name') }}</label>
<input type="text" name="name" class="form-control @error('name') is-invalid @enderror" placeholder="Your Name" value="{{ old('name') }}"> <input type="text" name="name" class="form-control @error('name') is-invalid @enderror" placeholder="{{ get_phrase('Your Name') }}" value="{{ old('name') }}">
@error('name')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
<div class="form-group mb-5">
<label for="" class="form-label">{{ get_phrase('Email') }}</label>
<input type="email" name="email" class="form-control @error('email') is-invalid @enderror" placeholder="Your Email" value="{{ old('email') }}">
@error('email') @error('name')
<small class="text-danger">{{ $message }}</small> <small class="text-danger">{{ $message }}</small>
@enderror @enderror
</div> </div>
<div class="form-group mb-5"> <div class="form-group mb-5">
<label for="" class="form-label">{{ get_phrase('Password') }}</label> <label for="" class="form-label">{{ get_phrase('Email') }}</label>
<input type="password" name="password" class="form-control @error('password') is-invalid @enderror" placeholder="*********"> <input type="email" name="email" class="form-control @error('email') is-invalid @enderror" placeholder="{{ get_phrase('Your Email') }}" value="{{ old('email') }}">
@error('password')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
@if (get_settings('allow_instructor')) @error('email')
<div class="form-group mb-5"> <small class="text-danger">{{ $message }}</small>
<input id="instructor" type="checkbox" name="instructor" value="1" {{ old('instructor') ? 'checked' : '' }}> @enderror
<label for="instructor">{{ get_phrase('Apply to Become an instructor') }}</label> </div>
</div> <div class="form-group mb-5">
<label for="" class="form-label">{{ get_phrase('Password') }}</label>
<input type="password" name="password" class="form-control @error('password') is-invalid @enderror" placeholder="*********">
<div id="become-instructor-fields" class="{{ old('instructor') ? '' : 'd-none' }}">
<div class="form-group mb-5">
<label for="" class="form-label">{{ get_phrase('NIDN') }}</label>
<input class="form-control @error('phone') is-invalid @enderror" id="nidn" type="text" name="nidn" placeholder="{{ get_phrase('Enter your NIDN number') }}" value="{{ old('nidn') }}">
@error('phone')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
<div class="form-group mb-5">
<label for="phone" class="form-label">{{ get_phrase('Phone') }}</label>
<input class="form-control @error('phone') is-invalid @enderror" id="phone" type="phone" name="phone" placeholder="{{ get_phrase('Enter your phone number') }}" value="{{ old('phone') }}">
@error('phone')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
<div class="form-group mb-5">
<label for="document" class="form-label">{{ get_phrase('Document') }} <small>(doc, docs, pdf, txt, png, jpg, jpeg)</small></label>
<input class="form-control @error('document') is-invalid @enderror" id="document" type="file" name="document">
@error('document')
<small class="text-danger">{{ $message }}</small>
@enderror
<small>{{ get_phrase('Provide some documents about your qualifications') }}</small>
</div>
<div class="form-group mb-5">
<label for="description" class="form-label">{{ get_phrase('Message') }}</label>
<textarea class="form-control @error('description') is-invalid @enderror" id="description" name="description" rows="4">{{ old('description') }}</textarea>
@error('description')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
</div>
@endif
@if (get_frontend_settings('recaptcha_status')) @error('password')
<button class="eBtn gradient w-100 g-recaptcha" data-sitekey="{{ get_frontend_settings('recaptcha_sitekey') }}" data-callback='onLoginSubmit' data-action='submit'>{{ get_phrase('Sign Up') }}</button> <small class="text-danger">{{ $message }}</small>
@else @enderror
<button type="submit" class="eBtn gradient w-100">{{ get_phrase('Sign Up') }}</button> </div>
@endif
<p class="mt-20">{{ get_phrase('Already have account?') }} <a href="{{ route('login') }}">{{ get_phrase('Sign in') }}</a></p>
</form> @if (get_settings('allow_instructor'))
</div> <div class="form-group mb-5">
</div> <input id="instructor" type="checkbox" name="instructor" value="1" {{ old('instructor') ? 'checked' : '' }}>
</div> <label for="instructor">{{ get_phrase('Apply to Become an instructor') }}</label>
</section> </div>
<div id="become-instructor-fields" class="{{ old('instructor') ? '' : 'd-none' }}">
<div class="form-group mb-5">
<label for="nidn" class="form-label">{{ get_phrase('NIDN') }}</label>
<input class="form-control @error('nidn') is-invalid @enderror" id="nidn" type="number" name="nidn" placeholder="{{ get_phrase('Enter your NIDN number') }}" value="{{ old('nidn') }}">
@error('nidn')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
<div class="form-group mb-5">
<label for="phone" class="form-label">{{ get_phrase('Phone') }}</label>
<input class="form-control @error('phone') is-invalid @enderror" id="phone" type="number" name="phone" placeholder="{{ get_phrase('Enter your phone number') }}" value="{{ old('phone') }}">
@error('phone')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
<div class="form-group mb-5">
<label for="document" class="form-label">{{ get_phrase('Document') }} <small>(doc, docs, pdf)</small></label>
<input class="form-control @error('document') is-invalid @enderror" id="document" type="file" name="document" accept=".doc,.docx,.pdf" onchange="validateFileSize(this)">
@error('document')
<small class="text-danger">{{ $message }}</small>
@enderror
<small>{{ get_phrase('Provide some documents about your qualifications') }}</small>
</div>
<div class="form-group mb-5">
<label for="description" class="form-label">{{ get_phrase('Message') }}</label>
<textarea class="form-control @error('description') is-invalid @enderror" id="description" name="description" rows="4">{{ old('description') }}</textarea>
@error('description')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
</div>
@endif
@if (get_frontend_settings('recaptcha_status'))
<button class="eBtn gradient w-100 g-recaptcha" data-sitekey="{{ get_frontend_settings('recaptcha_sitekey') }}" data-callback='onLoginSubmit' data-action='submit'>{{ get_phrase('Sign Up') }}</button>
@else
<button type="submit" class="eBtn gradient w-100">{{ get_phrase('Sign Up') }}</button>
@endif
<p class="mt-20">{{ get_phrase('Already have account?') }} <a href="{{ route('login') }}">{{ get_phrase('Sign in') }}</a></p>
</form>
</div>
</div>
</div>
</section>
@endsection @endsection
@push('js') @push('js')
<script> <script>
"use strict"; "use strict";
$(document).ready(function() { function onLoginSubmit(token) {
$('#showpassword').on('click', function(e) { document.getElementById("login-form").submit();
e.preventDefault(); }
const type = $('#password').attr('type');
if (type == 'password') {
$('#password').attr('type', 'text');
} else {
$('#password').attr('type', 'password');
}
});
});
$(document).ready(function() { $(document).ready(function() {
$('#showcpassword').on('click', function(e) { $('#instructor').on('change', function() {
e.preventDefault(); if ($(this).is(':checked')) {
const type = $('#cpassword').attr('type'); $('#become-instructor-fields').removeClass('d-none');
} else {
$('#become-instructor-fields').addClass('d-none');
}
});
});
if (type == 'password') {
$('#cpassword').attr('type', 'text');
} else {
$('#cpassword').attr('type', 'password');
}
});
});
function onLoginSubmit(token) { // File size validation
document.getElementById("login-form").submit(); function validateFileSize(input) {
} const file = input.files[0];
if (file) {
$(document).ready(function() { const fileSizeInMB = file.size / (1024 * 1024); // Convert to MB
$('#instructor').on('change', function() { if (fileSizeInMB > 2) {
if ($(this).is(':checked')) { // Show error message using existing toaster system
$('#become-instructor-fields').removeClass('d-none'); error('{{ get_phrase("File size exceeds 2MB limit.") }}');
} else { input.value = "";
$('#become-instructor-fields').addClass('d-none'); }
} }
}); }
}); </script>
</script>
@endpush @endpush

BIN
storage/.DS_Store vendored

Binary file not shown.

View File

@ -1,3 +0,0 @@
*
!public/
!.gitignore

View File

@ -1,2 +0,0 @@
*
!.gitignore

Binary file not shown.