notifikasi email instruktur
This commit is contained in:
parent
24405c69f1
commit
0d31ea3bac
@ -67,12 +67,14 @@ class RegisteredUserController extends Controller
|
||||
$instructorValidator = Validator::make($request->all(), [
|
||||
'nidn' => ['required', 'string', 'max:11'],
|
||||
'phone' => ['required', 'string'],
|
||||
'description' => ['nullable', 'string', 'max:1000'],
|
||||
'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'),
|
||||
'description.max' => get_phrase('Description may not be greater than 1000 characters'),
|
||||
'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'),
|
||||
@ -100,23 +102,39 @@ class RegisteredUserController extends Controller
|
||||
'password' => Hash::make($request->password),
|
||||
];
|
||||
|
||||
if (get_settings('student_email_verification') != 1) {
|
||||
$user_data['email_verified_at'] = Carbon::now();
|
||||
}
|
||||
// Don't set email_verified_at here yet - only set it after everything succeeds
|
||||
// This prevents sending verification email if registration fails
|
||||
|
||||
$user = User::create($user_data);
|
||||
event(new Registered($user));
|
||||
|
||||
|
||||
// If applying as an instructor, process the application
|
||||
if ($request->has('instructor')) {
|
||||
if ($request->has('instructor') && $request->instructor == 1) {
|
||||
$result = $this->processInstructorApplication($request, $user);
|
||||
|
||||
// Check if result is a RedirectResponse with error
|
||||
if ($result instanceof RedirectResponse && $result->getSession()->get('error')) {
|
||||
// If there was an error in instructor application, rollback
|
||||
DB::rollBack();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// If result is a success response (true), continue with commit
|
||||
if ($result !== true) {
|
||||
DB::rollBack();
|
||||
Session::flash('error', get_phrase('Error during registration. Please try again.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
// Now that everything succeeded, set email_verified_at if needed
|
||||
if (get_settings('student_email_verification') != 1) {
|
||||
$user->email_verified_at = Carbon::now();
|
||||
$user->save(); // Save the update
|
||||
}
|
||||
|
||||
// Fire the Registered event AFTER everything is committed
|
||||
// This ensures email is only sent when registration is fully successful
|
||||
event(new Registered($user));
|
||||
|
||||
DB::commit();
|
||||
|
||||
// Log the user in after successful registration
|
||||
@ -129,90 +147,136 @@ class RegisteredUserController extends Controller
|
||||
DB::rollBack();
|
||||
}
|
||||
|
||||
Log::error('Registration error:', ['error' => $e->getMessage()]);
|
||||
Log::error('Registration error:', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
'request' => $request->except(['password', 'document'])
|
||||
]);
|
||||
|
||||
Session::flash('error', get_phrase('Error during registration. Please try again.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
private function processInstructorApplication(Request $request, User $user): RedirectResponse
|
||||
private function processInstructorApplication(Request $request, User $user)
|
||||
{
|
||||
// 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 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()->back()->withInput();
|
||||
}
|
||||
|
||||
// Check if NIDN already exists in Instructors table with status = 1 (active)
|
||||
$nidn = $request->nidn;
|
||||
$existingInstructor = Instructors::where('nidn', $nidn)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
// Check if NIDN already exists in Instructors table with status = 1 (active)
|
||||
$nidn = $request->nidn;
|
||||
$existingInstructor = Instructors::where('nidn', $nidn)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
|
||||
if ($existingInstructor) {
|
||||
Session::flash('error', get_phrase('This NIDN is already registered as an active instructor.'));
|
||||
if ($existingInstructor) {
|
||||
Session::flash('error', get_phrase('This NIDN is already registered as an active instructor.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
// Check NIDN with the API
|
||||
$api_url = "https://sindig.unesa.ac.id/apipddikti/api?nidn={$nidn}&auto=1";
|
||||
|
||||
Log::info('Calling API for NIDN: ' . $nidn);
|
||||
|
||||
$response = Http::timeout(30)->get($api_url);
|
||||
|
||||
if (!$response->successful()) {
|
||||
Log::error('API request failed', [
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body()
|
||||
]);
|
||||
Session::flash('error', get_phrase('Unable to verify NIDN. Please try again later.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
$data = $response->json();
|
||||
Log::info('API Response for NIDN: ' . $nidn, ['response' => $data]);
|
||||
|
||||
if (!isset($data['ok']) || $data['ok'] !== true || !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();
|
||||
}
|
||||
|
||||
// Extract matched dosen data
|
||||
$matched_dosen = $data['matched_dosen'][0];
|
||||
|
||||
if (strtolower(trim($matched_dosen['nama'])) != strtolower(trim($user->name))) {
|
||||
Log::warning('Name mismatch', [
|
||||
'api_name' => $matched_dosen['nama'],
|
||||
'user_name' => $user->name
|
||||
]);
|
||||
Session::flash('error', get_phrase('Name does not match PDDikti records. Please check your name.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
// Upload document
|
||||
$fileName = null;
|
||||
if ($request->hasFile('document') && $request->file('document')->isValid()) {
|
||||
$doc = $request->file('document');
|
||||
$fileName = 'uploads/applications/' . $user->id . '_' . time() . '_' . Str::random(10) . '.' . $doc->getClientOriginalExtension();
|
||||
|
||||
$uploadResult = FileUploader::upload($doc, $fileName, null, null, 300);
|
||||
|
||||
if (!$uploadResult) {
|
||||
Session::flash('error', get_phrase('Document upload failed. Please try again.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', get_phrase('Document upload failed or no document selected.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
// Prepare instructor data
|
||||
$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,
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
Log::info('Creating instructor record:', $instructor);
|
||||
|
||||
// Prepare application data
|
||||
$application = [
|
||||
'user_id' => $user->id,
|
||||
'phone' => $request->phone,
|
||||
'description' => $request->description ?? null,
|
||||
'document' => $fileName,
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
// Create both application and instructor records
|
||||
$applicationRecord = Application::create($application);
|
||||
Instructors::create($instructor);
|
||||
|
||||
// Send notification to user
|
||||
try {
|
||||
$user->notify(new \App\Notifications\InstructorApplicant($applicationRecord));
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to send notification:', ['error' => $e->getMessage()]);
|
||||
// Don't fail registration if notification fails
|
||||
}
|
||||
|
||||
// Return true to indicate success
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Instructor application processing error:', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
'user_id' => $user->id ?? null
|
||||
]);
|
||||
|
||||
Session::flash('error', get_phrase('Error processing instructor application. Please try again.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
// Check NIDN with the API
|
||||
$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 (strtolower($matched_dosen['nama']) != strtolower($user->name)) {
|
||||
Session::flash('error', get_phrase('Name does not match PDDikti records. Please check your name.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
// 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,
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
Log::info('Instructor data to be saved:', $instructor);
|
||||
|
||||
// Upload document
|
||||
if ($request->hasFile('document') && $request->file('document')->isValid()) {
|
||||
$doc = $request->file('document');
|
||||
$fileName = 'uploads/applications/' . $user->id . Str::random(20) . '.' . $doc->extension();
|
||||
|
||||
FileUploader::upload($doc, $fileName, null, null, 300);
|
||||
} else {
|
||||
Session::flash('error', 'Document upload failed or no document selected.');
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
// Prepare application data
|
||||
$application = [
|
||||
'user_id' => $user->id,
|
||||
'phone' => $request->phone,
|
||||
'description' => $request->description
|
||||
];
|
||||
|
||||
//send notification to user
|
||||
$user->notify(new \App\Notifications\InstructorApplicant($application));
|
||||
|
||||
// Create both application and instructor records
|
||||
Application::create($application);
|
||||
Instructors::create($instructor);
|
||||
|
||||
Session::flash('success', get_phrase('Your application has been submitted successfully.'));
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,46 +1,5 @@
|
||||
<?php
|
||||
|
||||
// namespace App\Http\Controllers\Auth;
|
||||
|
||||
// use App\Http\Controllers\Controller;
|
||||
// use App\Providers\RouteServiceProvider;
|
||||
// use Illuminate\Auth\Events\Verified;
|
||||
// use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
// use Illuminate\Http\RedirectResponse;
|
||||
|
||||
// class VerifyEmailController extends Controller
|
||||
// {
|
||||
// /**
|
||||
// * Mark the authenticated user's email address as verified.
|
||||
// */
|
||||
// public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
// {
|
||||
// if ($request->user()->hasVerifiedEmail()) {
|
||||
// return redirect()->intended(RouteServiceProvider::HOME . '?verified=1');
|
||||
// }
|
||||
|
||||
// if ($request->user()->markEmailAsVerified()) {
|
||||
// event(new Verified($request->user()));
|
||||
// }
|
||||
|
||||
// return redirect()->intended(RouteServiceProvider::HOME . '?verified=1');
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
@ -56,33 +15,29 @@ class VerifyEmailController extends Controller
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __construct(Type $var = null) {
|
||||
$this->var = $var;
|
||||
$user = User::findOrFail(request()->route('id'));
|
||||
Auth::login($user);
|
||||
}
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
// Fetch the user directly from the database using the route parameters
|
||||
$user = Auth::user();
|
||||
|
||||
|
||||
// Validate the hash matches the user's email
|
||||
if (!hash_equals((string) $request->route('hash'), sha1($user->getEmailForVerification()))) {
|
||||
abort(403, 'Invalid or expired verification link.');
|
||||
// If you need to manually handle user authentication, do it here
|
||||
// But note: Laravel should already handle this with EmailVerificationRequest
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
if (!$user) {
|
||||
// Fallback: try to get user from route parameters if not authenticated
|
||||
$user = User::find($request->route('id'));
|
||||
if ($user) {
|
||||
Auth::login($user);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME . '?verified=1');
|
||||
}
|
||||
|
||||
// Mark email as verified and trigger the Verified event
|
||||
if ($user->markEmailAsVerified()) {
|
||||
event(new Verified($user));
|
||||
}
|
||||
|
||||
// Optionally log the user in after successful verification
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME . '?verified=1');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,14 +8,13 @@ use App\Models\FileUploader;
|
||||
use App\Models\Instructors;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class BecomeInstructorController extends Controller
|
||||
{
|
||||
@ -27,151 +26,183 @@ class BecomeInstructorController extends Controller
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Check if application already exists
|
||||
if (Application::where('user_id', auth()->user()->id)->exists()) {
|
||||
Session::flash('error', get_phrase('Your request is in process. Please wait for admin to response.'));
|
||||
return redirect()->route('become.instructor');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'nidn' => ['required', 'string', 'max:11'],
|
||||
'phone' => 'required',
|
||||
'document' => ['required', 'file', 'mimes:pdf,doc,docx', 'max:2048'],
|
||||
'description' => 'required',
|
||||
];
|
||||
|
||||
// Validate data
|
||||
$validator = Validator::make($request->all(), $rules, [
|
||||
'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'),
|
||||
'description.required' => get_phrase('Description is required'),
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$firstError = $validator->errors()->first();
|
||||
Session::flash('error', $firstError);
|
||||
return redirect()->back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
$user = auth()->user();
|
||||
|
||||
|
||||
// Use a lock to prevent race conditions
|
||||
$lock = Cache::lock('instructor_application_' . $user->id, 10);
|
||||
|
||||
if (!$lock->get()) {
|
||||
Session::flash('error', get_phrase('Another request is being processed. Please try again.'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
try {
|
||||
// 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 response.'));
|
||||
return redirect()->route('become.instructor');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'nidn' => ['required', 'string', 'max:11'],
|
||||
'phone' => 'required',
|
||||
'document' => ['required', 'file', 'mimes:pdf,doc,docx', 'max:2048'],
|
||||
'description' => 'required',
|
||||
];
|
||||
|
||||
// Validate data
|
||||
$validator = Validator::make($request->all(), $rules, [
|
||||
'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'),
|
||||
'description.required' => get_phrase('Description is required'),
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$firstError = $validator->errors()->first();
|
||||
Session::flash('error', $firstError);
|
||||
return redirect()->back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$result = $this->processInstructorApplication($request, $user);
|
||||
|
||||
if ($result instanceof RedirectResponse && $result->getSession()->get('error')) {
|
||||
if ($result['success'] === false) {
|
||||
DB::rollBack();
|
||||
return $result;
|
||||
Session::flash('error', $result['error']);
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
Session::flash('success', get_phrase('Your application has been submitted successfully.'));
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
return redirect()->route('home'); // Use named route instead of service provider
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error('Instructor application error:', ['error' => $e->getMessage()]);
|
||||
Log::error('Instructor application error:', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
Session::flash('error', get_phrase('Error during application submission. Please try again.'));
|
||||
return redirect()->back()->withInput();
|
||||
} finally {
|
||||
$lock->release();
|
||||
}
|
||||
}
|
||||
|
||||
private function processInstructorApplication(Request $request, User $user): RedirectResponse
|
||||
private function processInstructorApplication(Request $request, User $user)
|
||||
{
|
||||
// Check if application already exists (redundant but safe)
|
||||
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');
|
||||
}
|
||||
|
||||
// Check if NIDN already exists in Instructors table with status = 1 (active)
|
||||
$nidn = $request->nidn;
|
||||
|
||||
// Check if NIDN already exists in Instructors table with status = 1 (active)
|
||||
$existingInstructor = Instructors::where('nidn', $nidn)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
|
||||
if ($existingInstructor) {
|
||||
Session::flash('error', get_phrase('This NIDN is already registered as an active instructor.'));
|
||||
return redirect()->back()->withInput();
|
||||
return ['success' => false, 'error' => get_phrase('This NIDN is already registered as an active instructor.')];
|
||||
}
|
||||
|
||||
// Check NIDN with the API
|
||||
$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 (strtolower($matched_dosen['nama']) != strtolower($user->name)) {
|
||||
Session::flash('error', get_phrase('Name does not match PDDikti records. Please check your name.'));
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
// Upload document
|
||||
$fileName = null;
|
||||
if ($request->hasFile('document') && $request->file('document')->isValid()) {
|
||||
$doc = $request->file('document');
|
||||
$fileName = 'uploads/applications/' . $user->id . Str::random(20) . '.' . $doc->getClientOriginalExtension();
|
||||
|
||||
$uploadResult = FileUploader::upload($doc, $fileName, null, null, 300);
|
||||
|
||||
if (!$uploadResult) {
|
||||
Session::flash('error', get_phrase('Document upload failed. Please try again.'));
|
||||
return redirect()->back()->withInput();
|
||||
Log::info('Calling API for NIDN: ' . $nidn);
|
||||
|
||||
try {
|
||||
$response = Http::timeout(30)->get($api_url);
|
||||
|
||||
if (!$response->successful()) {
|
||||
Log::error('API request failed', [
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body()
|
||||
]);
|
||||
return ['success' => false, 'error' => get_phrase('Unable to verify NIDN. Please try again later.')];
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', get_phrase('Document upload failed or no document selected.'));
|
||||
return redirect()->back()->withInput();
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
if (!isset($data['ok']) || $data['ok'] !== true || !isset($data['matched_dosen']) || !is_array($data['matched_dosen']) || count($data['matched_dosen']) == 0) {
|
||||
return ['success' => false, 'error' => get_phrase('NIDN not found in the system. Please check your NIDN.')];
|
||||
}
|
||||
|
||||
// Extract matched dosen data
|
||||
$matched_dosen = $data['matched_dosen'][0];
|
||||
|
||||
if (!isset($matched_dosen['nama'])) {
|
||||
Log::error('API response missing nama field', ['response' => $matched_dosen]);
|
||||
return ['success' => false, 'error' => get_phrase('Invalid API response. Please try again later.')];
|
||||
}
|
||||
|
||||
if (strtolower(trim($matched_dosen['nama'])) != strtolower(trim($user->name))) {
|
||||
Log::warning('Name mismatch', [
|
||||
'api_name' => $matched_dosen['nama'],
|
||||
'user_name' => $user->name
|
||||
]);
|
||||
return ['success' => false, 'error' => get_phrase('Name does not match PDDikti records. Please check your name.')];
|
||||
}
|
||||
|
||||
// Upload document
|
||||
$doc = $request->file('document');
|
||||
$fileName = 'uploads/applications/' . $user->id . '_' . time() . '_' . Str::random(10) . '.' . $doc->getClientOriginalExtension();
|
||||
|
||||
$uploadResult = FileUploader::upload($doc, $fileName, null, null, 300);
|
||||
|
||||
if (!$uploadResult) {
|
||||
return ['success' => false, 'error' => get_phrase('Document upload failed. Please try again.')];
|
||||
}
|
||||
|
||||
// Prepare instructor data
|
||||
$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,
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
// Prepare application data
|
||||
$application = [
|
||||
'user_id' => $user->id,
|
||||
'phone' => $request->phone,
|
||||
'description' => $request->description,
|
||||
'document' => $fileName,
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
// Create both application and instructor records
|
||||
$applicationRecord = Application::create($application);
|
||||
Instructors::create($instructor);
|
||||
|
||||
// Send notification to user
|
||||
try {
|
||||
$user->notify(new \App\Notifications\InstructorApplicant($applicationRecord));
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to send notification:', [
|
||||
'error' => $e->getMessage(),
|
||||
'user_id' => $user->id,
|
||||
'application_id' => $applicationRecord->id
|
||||
]);
|
||||
}
|
||||
|
||||
return ['success' => true, 'applicationRecord' => $applicationRecord];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Process instructor application error:', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
return ['success' => false, 'error' => get_phrase('Error processing application. Please try again.')];
|
||||
}
|
||||
|
||||
// Prepare instructor data
|
||||
$instructorData = [
|
||||
'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,
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
Log::info('Instructor data to be saved:', $instructorData);
|
||||
|
||||
// Prepare application data - INCLUDING DOCUMENT PATH
|
||||
$application = [
|
||||
'user_id' => $user->id,
|
||||
'nidn' => $nidn,
|
||||
'phone' => $request->phone,
|
||||
'description' => $request->description,
|
||||
'document' => $fileName,
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
//send notification to user
|
||||
$user->notify(new \App\Notifications\InstructorApplicant($application));
|
||||
|
||||
Log::info('Application data to be saved:', $application);
|
||||
|
||||
// Create both application and instructor records
|
||||
Application::create($application);
|
||||
Instructors::create($instructorData);
|
||||
|
||||
return redirect()->back(); // This return won't be used due to the try-catch structure
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,9 +18,13 @@ class InstructorApplicant extends Notification
|
||||
*/
|
||||
public function __construct($application)
|
||||
{
|
||||
$this->application = $application;
|
||||
// Convert array to object if it's an array
|
||||
if (is_array($application)) {
|
||||
$this->application = (object) $application;
|
||||
} else {
|
||||
$this->application = $application;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
|
||||
@ -64,8 +64,8 @@
|
||||
</div>
|
||||
|
||||
<div class="fpb-7 mb-3">
|
||||
<label class="form-label ol-form-label" for="address">{{ get_phrase('Link Google Maps') }}</label>
|
||||
<textarea name="address" id = "address" class="form-control ol-form-control" rows="1">{{ get_settings('link_gmaps') }}</textarea>
|
||||
<label class="form-label ol-form-label" for="link_gmaps">{{ get_phrase('Link Google Maps') }}</label>
|
||||
<textarea name="link_gmaps" id = "link_gmaps" class="form-control ol-form-control" rows="1">{{ get_settings('link_gmaps') }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="fpb-7 mb-3">
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
<p class="description">{{ get_phrase('Submit your account email address.') }} </p>
|
||||
<div class="form-group">
|
||||
<label for="email" class="form-label">{{ get_phrase('Email') }}</label>
|
||||
<input type="email" id="email" name="email" class="form-control" placeholder="{{ get_phrase('Enter Your Email') }}">
|
||||
<input type="email" id="email" name="email" class="form-control" placeholder="{{ get_phrase('Enter Your Email') }}" required>
|
||||
</div>
|
||||
<button type="submit" class="eBtn gradient w-100 mt-5">{{ get_phrase('Send Request') }}</button>
|
||||
<a href="{{route('login')}}" class="eBtn gradient w-100 mt-5 text-center">{{ get_phrase('Back to login page') }}</a>
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
<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="{{ get_phrase('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') }}" required>
|
||||
|
||||
|
||||
@error('name')
|
||||
@ -33,7 +33,7 @@
|
||||
</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="{{ get_phrase('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') }}" required>
|
||||
|
||||
|
||||
@error('email')
|
||||
@ -42,7 +42,7 @@
|
||||
</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="*********">
|
||||
<input type="password" name="password" class="form-control @error('password') is-invalid @enderror" placeholder="*********" required>
|
||||
|
||||
|
||||
@error('password')
|
||||
@ -150,4 +150,35 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const instructorCheckbox = document.getElementById("instructor");
|
||||
const fieldsWrapper = document.getElementById("become-instructor-fields");
|
||||
|
||||
const nidn = document.getElementById("nidn");
|
||||
const phone = document.getElementById("phone");
|
||||
const documentFile = document.getElementById("document");
|
||||
|
||||
function toggleRequiredFields() {
|
||||
if (instructorCheckbox.checked) {
|
||||
fieldsWrapper.classList.remove("d-none");
|
||||
|
||||
nidn.setAttribute("required", "required");
|
||||
phone.setAttribute("required", "required");
|
||||
documentFile.setAttribute("required", "required");
|
||||
} else {
|
||||
fieldsWrapper.classList.add("d-none");
|
||||
|
||||
nidn.removeAttribute("required");
|
||||
phone.removeAttribute("required");
|
||||
documentFile.removeAttribute("required");
|
||||
}
|
||||
}
|
||||
|
||||
instructorCheckbox.addEventListener("change", toggleRequiredFields);
|
||||
|
||||
// Run once on page load (if old value checked)
|
||||
toggleRequiredFields();
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
<div class="col-lg-12 mb-20">
|
||||
<div class="form-group">
|
||||
<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') }}">
|
||||
<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') }}" required>
|
||||
@error('nidn')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
@ -27,7 +27,7 @@
|
||||
<div class="col-lg-12 mb-20">
|
||||
<div class="form-group">
|
||||
<label for="phone" class="form-label">{{ get_phrase('Phone Number') }}</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') }}">
|
||||
<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') }}" required>
|
||||
@error('phone')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
@ -36,7 +36,7 @@
|
||||
<div class="col-lg-12 mb-20">
|
||||
<div class="form-group">
|
||||
<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)">
|
||||
<input class="form-control @error('document') is-invalid @enderror" id="document" type="file" name="document" accept=".doc,.docx,.pdf" onchange="validateFileSize(this)" required>
|
||||
@error('document')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
@ -45,8 +45,8 @@
|
||||
</div>
|
||||
<div class="col-lg-12 mb-20">
|
||||
<div class="form-group">
|
||||
<label for="description" class="form-label">{{ get_phrase('Description') }}</label>
|
||||
<textarea name="description" class="form-control @error('description') border border-danger @enderror" id="description" cols="30" rows="5" placeholder="{{ get_phrase('Your personal summary here...') }}"></textarea>
|
||||
<label for="description" class="form-label">{{ get_phrase('Personal Summary') }}</label>
|
||||
<textarea name="description" class="form-control @error('description') border border-danger @enderror" id="description" cols="30" rows="5" placeholder="{{ get_phrase('Your personal summary here...') }}" required></textarea>
|
||||
@error('description')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
|
||||
@ -87,13 +87,22 @@
|
||||
|
||||
<div class="application-details">
|
||||
<p><strong>{{ get_phrase('Application Details') }}:</strong></p>
|
||||
<p><strong>{{ get_phrase('Application ID') }}:</strong> {{ $application->id }}</p>
|
||||
<p><strong>{{ get_phrase('Application ID') }}:</strong>
|
||||
@php
|
||||
$applicationId = is_array($application) ? ($application['id'] ?? 'N/A') : ($application->id ?? 'N/A');
|
||||
echo $applicationId;
|
||||
@endphp
|
||||
</p>
|
||||
<p><strong>{{ get_phrase('Submission Date') }}:</strong>
|
||||
@if(method_exists($application->created_at, 'format'))
|
||||
{{ $application->created_at->format('F d, Y') }}
|
||||
@else
|
||||
{{ date('F d, Y') }}
|
||||
@endif
|
||||
@php
|
||||
$createdAt = is_array($application) ? ($application['created_at'] ?? now()) : ($application->created_at ?? now());
|
||||
|
||||
if (is_object($createdAt) && method_exists($createdAt, 'format')) {
|
||||
echo $createdAt->format('F d, Y');
|
||||
} else {
|
||||
echo date('F d, Y', strtotime($createdAt));
|
||||
}
|
||||
@endphp
|
||||
</p>
|
||||
<p><strong>{{ get_phrase('Current Status') }}:</strong>
|
||||
<span class="status-pending">{{ get_phrase('Under Review') }}</span>
|
||||
@ -124,8 +133,9 @@
|
||||
</div>
|
||||
<div class="email-footer">
|
||||
<p><strong>{{ config('app.name') }}</strong></p>
|
||||
<p>{{ get_phrase('Instructor Recruitment Team') }}</p>
|
||||
<p>{{ get_phrase('Grownesa Support Team') }}</p>
|
||||
<p><small>{{ get_phrase('This is an automated message. Please do not reply to this email.') }}</small></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@ -5,7 +5,6 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ get_phrase('Instructor Application Approved') }}</title>
|
||||
<style>
|
||||
/* Copy the same styles from your email.blade.php */
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f9f9f9;
|
||||
@ -21,8 +20,8 @@
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.email-header {
|
||||
background-color: #ffffff;
|
||||
color: #000;
|
||||
background-color: #2f57ef;
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
font-size: 24px;
|
||||
@ -47,6 +46,10 @@
|
||||
border-radius: 5px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
.email-body a.button:hover {
|
||||
background-color: #1e46d0;
|
||||
}
|
||||
.email-footer {
|
||||
background-color: #f0f3ff;
|
||||
@ -56,6 +59,48 @@
|
||||
font-size: 14px;
|
||||
border-top: 1px solid #dddddd;
|
||||
}
|
||||
.application-details {
|
||||
background-color: #f8f9fa;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin: 15px 0;
|
||||
border-left: 4px solid #2f57ef;
|
||||
}
|
||||
.thank-you {
|
||||
color: #2f57ef;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.status-approved {
|
||||
display: inline-block;
|
||||
background-color: #d4edda;
|
||||
color: #155724;
|
||||
padding: 5px 10px;
|
||||
border-radius: 15px;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
margin-left: 10px;
|
||||
}
|
||||
.notification-info {
|
||||
background-color: #e7f3ff;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin: 15px 0;
|
||||
border-left: 4px solid #2f57ef;
|
||||
}
|
||||
ul {
|
||||
margin: 10px 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
li {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.success-icon {
|
||||
color: #28a745;
|
||||
font-size: 20px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -64,17 +109,44 @@
|
||||
{{ get_phrase('Instructor Application Approved') }}
|
||||
</div>
|
||||
<div class="email-body">
|
||||
<p><strong>{{ get_phrase('Congratulations') }} {{ $user->name }}!</strong></p>
|
||||
<p>{{ get_phrase('We are pleased to inform you that your instructor application has been approved.') }}</p>
|
||||
<p><strong>{{ get_phrase('Application ID') }}:</strong> {{ $application->id }}</p>
|
||||
<div class="thank-you">
|
||||
{{ get_phrase('Congratulations') }}, {{ $user->name }}! 🎉
|
||||
</div>
|
||||
|
||||
<p>{{ get_phrase('You now have access to') }}:</p>
|
||||
<p>{{ get_phrase('We are pleased to inform you that your instructor application has been approved.') }}</p>
|
||||
|
||||
<div class="application-details">
|
||||
<p><strong>{{ get_phrase('Application Details') }}:</strong></p>
|
||||
<p><strong>{{ get_phrase('Application ID') }}:</strong>
|
||||
@php
|
||||
$applicationId = is_array($application) ? ($application['id'] ?? 'N/A') : ($application->id ?? 'N/A');
|
||||
echo $applicationId;
|
||||
@endphp
|
||||
</p>
|
||||
<p><strong>{{ get_phrase('Approval Date') }}:</strong>
|
||||
@php
|
||||
echo date('F d, Y');
|
||||
@endphp
|
||||
</p>
|
||||
<p><strong>{{ get_phrase('Current Status') }}:</strong>
|
||||
<span class="status-approved">{{ get_phrase('Approved') }}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="notification-info">
|
||||
<p><strong>{{ get_phrase('Welcome to Our Instructor Community!') }}</strong></p>
|
||||
<p>{{ get_phrase('As an approved instructor, you now have access to all instructor features and tools.') }}</p>
|
||||
</div>
|
||||
|
||||
<p><strong>{{ get_phrase('You now have access to') }}:</strong></p>
|
||||
<ul>
|
||||
<li>{{ get_phrase('Instructor Dashboard') }}</li>
|
||||
<li>{{ get_phrase('Course Creation Tools') }}</li>
|
||||
<li>{{ get_phrase('Bootcamp Creation Tools') }}</li>
|
||||
<li>{{ get_phrase('Blog Creation Tools') }}</li>
|
||||
<li>{{ get_phrase('Revenue Tracking and Analytics') }}</li>
|
||||
<li><span class="success-icon">✓</span> {{ get_phrase('Instructor Dashboard') }}</li>
|
||||
<li><span class="success-icon">✓</span> {{ get_phrase('Course Creation Tools') }}</li>
|
||||
<li><span class="success-icon">✓</span> {{ get_phrase('Bootcamp Creation Tools') }}</li>
|
||||
<li><span class="success-icon">✓</span> {{ get_phrase('Blog Creation Tools') }}</li>
|
||||
<li><span class="success-icon">✓</span> {{ get_phrase('Revenue Tracking and Analytics') }}</li>
|
||||
<li><span class="success-icon">✓</span> {{ get_phrase('Student Management') }}</li>
|
||||
<li><span class="success-icon">✓</span> {{ get_phrase('Certificate Generation') }}</li>
|
||||
</ul>
|
||||
|
||||
<div class="button-container">
|
||||
@ -83,12 +155,33 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<p>{{ get_phrase('If you have any questions, please contact our support team.') }}</p>
|
||||
<p>{{ get_phrase('Thank you for joining our instructor community!') }}</p>
|
||||
<p><strong>{{ get_phrase('Getting Started') }}:</strong></p>
|
||||
<ol>
|
||||
<li>{{ get_phrase('Log in to your account') }}</li>
|
||||
<li>{{ get_phrase('Access the instructor dashboard') }}</li>
|
||||
<li>{{ get_phrase('Create your first course or bootcamp') }}</li>
|
||||
<li>{{ get_phrase('Set up your instructor profile') }}</li>
|
||||
<li>{{ get_phrase('Start engaging with students') }}</li>
|
||||
</ol>
|
||||
|
||||
<div class="notification-info">
|
||||
<p><strong>{{ get_phrase('Important Information') }}:</strong></p>
|
||||
<p>{{ get_phrase('Make sure to complete your instructor profile to increase student trust.') }}</p>
|
||||
<p>{{ get_phrase('Review our instructor guidelines and best practices.') }}</p>
|
||||
<p>{{ get_phrase('Check our revenue sharing model and payment schedule.') }}</p>
|
||||
</div>
|
||||
|
||||
<p>{{ get_phrase('We are excited to have you as part of our instructor team and look forward to seeing the amazing content you will create!') }}</p>
|
||||
|
||||
<p>{{ get_phrase('If you have any questions or need assistance, please contact our instructor support team.') }}</p>
|
||||
|
||||
<p>{{ get_phrase('Once again, welcome aboard!') }}</p>
|
||||
</div>
|
||||
<div class="email-footer">
|
||||
<p>{{ config('app.name') }}</p>
|
||||
<p><strong>{{ config('app.name') }}</strong></p>
|
||||
<p>{{ get_phrase('Grownesa Support Team') }}</p>
|
||||
<p><small>{{ get_phrase('This is an automated message. Please do not reply to this email.') }}</small></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user