128 lines
3.5 KiB
PHP
128 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Models\StudentPortalLog ;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
|
|
|
|
class StudentPortalController extends Controller
|
|
{
|
|
public function studentlogin(Request $request)
|
|
{
|
|
$request->validate([
|
|
'username' => 'required',
|
|
'password' => 'required',
|
|
'pin' => 'required|numeric',
|
|
]);
|
|
|
|
$student = DB::table('student_portal_logs')
|
|
->where('email', $request->username)
|
|
->first();
|
|
|
|
if ($student && Hash::check($request->password, $student->password) && $student->pin == $request->pin) {
|
|
if ($student->status !== 'active' && $student->status !== '') {
|
|
return redirect('/')->with('error', 'Your account is inactive!');
|
|
}
|
|
$request->session()->put('student_id', $student->studentid);
|
|
return redirect()->route('student.portal')->with('success', 'Logged in successfully!');
|
|
}
|
|
return redirect('/')->with('error', 'Invalid Email, Password, or PIN!');
|
|
}
|
|
|
|
|
|
|
|
public function showProfile(Request $request)
|
|
{
|
|
|
|
$log_id = $request->session()->get('student_log_id');
|
|
$student_code = $request->session()->get('student_id');
|
|
|
|
if (!$log_id && !$student_code) {
|
|
return redirect('/')->with('error', 'Please login first!');
|
|
}
|
|
|
|
|
|
$student = DB::table('student_details')
|
|
->where('student_portal_log_id', $log_id)
|
|
->orWhere('student_id', $student_code)
|
|
->first();
|
|
|
|
|
|
if (!$student) {
|
|
return redirect()->back()->with('error', 'Student details not found in database!');
|
|
}
|
|
|
|
return view('StudentProfile', compact('student'));
|
|
}
|
|
|
|
|
|
// public function showProfile(Request $request)
|
|
// {
|
|
|
|
// $log_id = $request->session()->get('student_log_id');
|
|
// $student_code = $request->session()->get('student_id');
|
|
|
|
// if (!$log_id && !$student_code) {
|
|
// return redirect('/')->with('error', 'Please login first!');
|
|
// }
|
|
|
|
|
|
// $student = DB::table('student_details')
|
|
// ->where('student_portal_log_id', $log_id)
|
|
// ->orWhere('student_id', $student_code)
|
|
// ->first();
|
|
|
|
|
|
// if (!$student) {
|
|
// return redirect()->back()->with('error', 'Student details not found in database!');
|
|
// }
|
|
|
|
// return view('StudentProfile', compact('student'));
|
|
// }
|
|
|
|
|
|
|
|
// public function showProfile(Request $request)
|
|
// {
|
|
|
|
// $log_id = $request->session()->get('student_id');
|
|
|
|
// if (!$log_id) {
|
|
// return redirect('/')->with('error', 'Please login first!');
|
|
// }
|
|
|
|
|
|
// $student = DB::table('student_details')
|
|
// ->where('student_id', $log_id)
|
|
// ->orWhere('student_portal_log_id', $log_id)
|
|
// ->first();
|
|
|
|
|
|
// if (!$student) {
|
|
// $student = (object)[
|
|
// 'image' => '',
|
|
// 'full_name' => 'Data Not Found (Check DB)',
|
|
// 'student_id' => $log_id,
|
|
// 'nic_passport' => 'N/A',
|
|
// 'date_of_birth' => '2000-01-01',
|
|
// 'gender' => 'N/A',
|
|
// 'email' => 'N/A',
|
|
// 'phone' => 'N/A',
|
|
// 'qualification' => 'N/A',
|
|
// 'institute' => 'N/A',
|
|
// 'year_completed' => 'N/A',
|
|
// 'course_name' => 'N/A',
|
|
// 'duration' => 'N/A',
|
|
// 'current_semester' => 'N/A',
|
|
// 'trainer_name' => 'N/A'
|
|
// ];
|
|
// }
|
|
|
|
// return view('StudentProfile', compact('student'));
|
|
// }
|
|
}
|