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\Models\Application;
use App\Models\FileUploader;
use App\Models\Instructors;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Carbon\Carbon;
@ -12,37 +13,29 @@ use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rules;
use Illuminate\View\View;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
class RegisteredUserController extends Controller
{
/**
* Display the registration view.
*/
public function create(): View
{
return view('auth.register');
}
/**
* Handle an incoming registration request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse
{
$input = $request->all();
if (get_frontend_settings('recaptcha_status') == true && check_recaptcha($input['g-recaptcha-response']) == false) {
Session::flash('error', get_phrase('Recaptcha verification failed'));
return redirect(route('register.form'));
}
@ -62,15 +55,37 @@ class RegisteredUserController extends Controller
'password.min' => get_phrase('Password must be at least 8 characters'),
]);
if ($validator->fails()) {
// Get the first error message to show as flash message
$firstError = $validator->errors()->first();
Session::flash('error', $firstError);
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 = [
'name' => $request->name,
'email' => $request->email,
@ -84,36 +99,98 @@ class RegisteredUserController extends Controller
}
$user = User::create($user_data);
event(new Registered($user));
Auth::login($user);
// If applying as an instructor, process the application
if ($request->has('instructor')) {
return $this->processInstructorApplication($request, $user);
}
// Log the user in after successful registration
Auth::login($user);
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');
}
// Process instructor application
$application['user_id'] = $user->id;
$application['phone'] = $request->phone;
$application['description'] = $request->description;
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();
}
Log::info('API Response for Nama: ' . $matched_dosen['nama'], ' || nama :',$user->name);
// Prepare instructor data - adjust fields according to your database
$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
if ($request->hasFile('document') && $request->file('document')->isValid()) {
$doc = $request->file('document');
$application['document'] = 'uploads/applications/' . $user->id . Str::random(20) . '.' . $doc->extension();
$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
Application::insert($application);
// Prepare application data
$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);

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
$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_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
<style>
.instructor-info li:nth-last-child(1){
border: none;
@ -27,10 +33,15 @@
</style>
<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">
</div>
<p>$placeholder_image: {{ $placeholder_image ?? 'N/A' }}</p>
<p>$user_photo: {{ $user_photo ?? 'N/A' }}</p>
<ul class="instructor-info">
<li>
<span>{{ get_phrase('Applicant') }}</span>
@ -41,12 +52,16 @@
<span>{{ $user->email }}</span>
</li>
<li>
<span>{{ get_phrase('Phone number') }}</span>
<span>{{ $user->phone }}</span>
<span>{{ get_phrase('NIDN') }}</span>
<span>{{ $applicant_instrucutor->nidn ?? 'N/A' }}</span>
</li>
<li>
<span>{{ get_phrase('Address') }}</span>
<span>{{ $user->address }}</span>
<span>{{ get_phrase('Study Program') }}</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>
<span>{{ get_phrase('Message') }}&nbsp</span>: &nbsp

View File

@ -24,7 +24,8 @@
<p class="description">{{ get_phrase('See your growth and get consulting support! ') }}</p>
<div class="form-group mb-5">
<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>
@ -32,7 +33,8 @@
</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') }}">
<input type="email" name="email" class="form-control @error('email') is-invalid @enderror" placeholder="{{ get_phrase('Your Email') }}" value="{{ old('email') }}">
@error('email')
<small class="text-danger">{{ $message }}</small>
@ -42,35 +44,38 @@
<label for="" class="form-label">{{ get_phrase('Password') }}</label>
<input type="password" name="password" class="form-control @error('password') is-invalid @enderror" placeholder="*********">
@error('password')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
@if (get_settings('allow_instructor'))
<div class="form-group mb-5">
<input id="instructor" type="checkbox" name="instructor" value="1" {{ old('instructor') ? 'checked' : '' }}>
<label for="instructor">{{ get_phrase('Apply to Become an instructor') }}</label>
</div>
<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')
<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="phone" name="phone" placeholder="{{ get_phrase('Enter your phone number') }}" value="{{ old('phone') }}">
<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, txt, png, jpg, jpeg)</small></label>
<input class="form-control @error('document') is-invalid @enderror" id="document" type="file" name="document">
<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
@ -92,6 +97,7 @@
<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>
@ -103,36 +109,11 @@
<script>
"use strict";
$(document).ready(function() {
$('#showpassword').on('click', function(e) {
e.preventDefault();
const type = $('#password').attr('type');
if (type == 'password') {
$('#password').attr('type', 'text');
} else {
$('#password').attr('type', 'password');
}
});
});
$(document).ready(function() {
$('#showcpassword').on('click', function(e) {
e.preventDefault();
const type = $('#cpassword').attr('type');
if (type == 'password') {
$('#cpassword').attr('type', 'text');
} else {
$('#cpassword').attr('type', 'password');
}
});
});
function onLoginSubmit(token) {
document.getElementById("login-form").submit();
}
$(document).ready(function() {
$('#instructor').on('change', function() {
if ($(this).is(':checked')) {
@ -142,5 +123,19 @@
}
});
});
// File size validation
function validateFileSize(input) {
const file = input.files[0];
if (file) {
const fileSizeInMB = file.size / (1024 * 1024); // Convert to MB
if (fileSizeInMB > 2) {
// Show error message using existing toaster system
error('{{ get_phrase("File size exceeds 2MB limit.") }}');
input.value = "";
}
}
}
</script>
@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.