Hr portal

This commit is contained in:
subhajit 2026-07-20 21:50:30 +05:30
parent 2d2d1e3322
commit d3fafe85a2
14 changed files with 1741 additions and 3 deletions

View File

@ -0,0 +1,282 @@
<?php
namespace App\Http\Controllers;
use App\Models\Interview;
use App\Models\InterviewWarning;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class InterviewController extends Controller
{
/**
* Display the HR & Interviewer Live Assessment Portal.
*/
public function index()
{
$user = Auth::user();
// Must be Admin, HR, or assigned interviewer
$interviews = Interview::with(['creator', 'warnings.sender'])
->orderBy('created_at', 'desc')
->get();
$interviewers = User::orderBy('name', 'asc')->get();
return view('interview.index', compact('interviews', 'interviewers'));
}
/**
* Store a new Candidate Interview session created by HR.
*/
public function store(Request $request)
{
$request->validate([
'candidate_name' => 'required|string|max:255',
'candidate_email' => 'required|email|max:255',
'candidate_phone' => 'required|string|max:50',
'valid_hours' => 'required|integer|min:1|max:72',
'language' => 'required|string',
'assigned_interviewers' => 'nullable|array',
]);
$tempPassword = 'Pass-' . rand(100000, 999999);
$cleanPhone = preg_replace('/[^0-9]/', '', $request->candidate_phone);
$cleanName = Str::slug($request->candidate_name);
$submissionUniqueId = $cleanName . '_' . $cleanPhone . '_' . time();
$expiresAt = now()->addHours((int)$request->valid_hours);
$interview = Interview::create([
'candidate_name' => $request->candidate_name,
'candidate_email' => strtolower(trim($request->candidate_email)),
'candidate_phone' => $request->candidate_phone,
'temp_password' => $tempPassword,
'expires_at' => $expiresAt,
'language' => $request->language,
'status' => 'scheduled',
'assigned_interviewers' => $request->assigned_interviewers ?? [],
'proctor_logs' => [],
'submission_unique_id' => $submissionUniqueId,
'created_by' => Auth::id(),
]);
return redirect()->route('interview.index')->with('success', 'Interview session created for ' . $request->candidate_name . '. Temporary login credentials generated!');
}
/**
* Show Candidate Login Screen.
*/
public function showCandidateLogin()
{
return view('interview.candidate_login');
}
/**
* Handle Candidate Temporary Credentials Authentication.
*/
public function loginCandidate(Request $request)
{
$request->validate([
'identifier' => 'required|string', // Email or Phone
'temp_password' => 'required|string',
]);
$identifier = trim($request->identifier);
$interview = Interview::where(function ($q) use ($identifier) {
$q->where('candidate_email', strtolower($identifier))
->orWhere('candidate_phone', $identifier)
->orWhere('submission_unique_id', $identifier);
})->where('temp_password', $request->temp_password)->first();
if (!$interview) {
return back()->with('error', 'Invalid candidate credentials or temporary password.');
}
if ($interview->isExpired()) {
$interview->update(['status' => 'expired']);
return back()->with('error', 'This candidate interview access window has expired. Please contact HR.');
}
// Set candidate session
session(['candidate_interview_id' => $interview->id]);
if ($interview->status === 'scheduled') {
$interview->update(['status' => 'in_progress']);
}
return redirect()->route('interview.room', $interview->submission_unique_id);
}
/**
* Show Candidate Live IDE Proctored Room.
*/
public function showCandidateRoom($uniqueId)
{
$interview = Interview::where('submission_unique_id', $uniqueId)->firstOrFail();
if ($interview->isExpired()) {
$interview->update(['status' => 'expired']);
return response()->view('interview.expired', compact('interview'), 403);
}
return view('interview.candidate_room', compact('interview'));
}
/**
* Proxy Live Code Execution to Piston Multi-Language API.
*/
public function executeCode(Request $request)
{
$request->validate([
'language' => 'required|string',
'code' => 'required|string',
]);
$langMap = [
'python' => ['language' => 'python', 'version' => '3.10.0'],
'c' => ['language' => 'c', 'version' => '10.2.0'],
'cpp' => ['language' => 'c++', 'version' => '10.2.0'],
'java' => ['language' => 'java', 'version' => '15.0.2'],
'php' => ['language' => 'php', 'version' => '8.2.3'],
'laravel' => ['language' => 'php', 'version' => '8.2.3'],
'javascript' => ['language' => 'javascript', 'version' => '18.15.0'],
];
$targetLang = $langMap[strtolower($request->language)] ?? ['language' => 'python', 'version' => '3.10.0'];
try {
$response = Http::post('https://emkc.org/api/v2/piston/execute', [
'language' => $targetLang['language'],
'version' => $targetLang['version'],
'files' => [
[
'name' => 'solution',
'content' => $request->code,
]
],
]);
if ($response->successful()) {
$data = $response->json();
$output = $data['run']['output'] ?? 'No output generated.';
return response()->json(['success' => true, 'output' => $output]);
}
return response()->json(['success' => false, 'output' => 'Execution engine error: ' . $response->status()]);
} catch (\Exception $e) {
return response()->json(['success' => false, 'output' => 'Code runner service error: ' . $e->getMessage()]);
}
}
/**
* Save Candidate Submitted Code & Execution Results.
*/
public function submitCode(Request $request, $id)
{
$interview = Interview::findOrFail($id);
$request->validate([
'code' => 'required|string',
'language' => 'required|string',
'output' => 'nullable|string',
]);
$interview->update([
'submitted_code' => $request->code,
'submitted_language' => $request->language,
'code_output' => $request->output,
'status' => 'completed',
]);
return response()->json([
'success' => true,
'message' => 'Code submitted successfully under unique ID: ' . $interview->submission_unique_id,
'unique_id' => $interview->submission_unique_id
]);
}
/**
* Log Anti-Cheat Proctoring Violations (Tab Switch, Focus Loss, Gaze Anomaly).
*/
public function logViolation(Request $request, $id)
{
$interview = Interview::findOrFail($id);
$type = $request->input('type'); // tab_switch, focus_lost, paste_event, gaze_anomaly
$details = $request->input('details', '');
$logs = $interview->proctor_logs ?? [];
$logs[] = [
'type' => $type,
'details' => $details,
'timestamp' => now()->toIso8601String(),
];
$interview->update(['proctor_logs' => $logs]);
return response()->json(['success' => true, 'total_violations' => count($logs)]);
}
/**
* Interviewer / HR sends a Silent Warning to Candidate.
*/
public function sendWarning(Request $request, $id)
{
$interview = Interview::findOrFail($id);
$request->validate([
'message' => 'required|string|max:500',
]);
$warning = InterviewWarning::create([
'interview_id' => $interview->id,
'message' => $request->message,
'sent_by' => Auth::id(),
]);
return response()->json(['success' => true, 'warning' => $warning]);
}
/**
* Live Polling Endpoint for Candidate Warnings & HR Monitoring.
*/
public function getPollData($id)
{
$interview = Interview::with(['warnings.sender'])->findOrFail($id);
return response()->json([
'status' => $interview->status,
'submitted_code' => $interview->submitted_code,
'submitted_language' => $interview->submitted_language,
'code_output' => $interview->code_output,
'proctor_logs' => $interview->proctor_logs ?? [],
'warnings' => $interview->warnings,
'is_expired' => $interview->isExpired(),
]);
}
/**
* Save Candidate Silent Video Recording Blob / Snapshot Stream.
*/
public function uploadRecording(Request $request, $id)
{
$interview = Interview::findOrFail($id);
if ($request->hasFile('video')) {
$file = $request->file('video');
$filename = 'interview_' . $interview->submission_unique_id . '_' . time() . '.webm';
$path = $file->storeAs('public/recordings', $filename);
$interview->update(['recording_path' => Storage::url($path)]);
return response()->json(['success' => true, 'path' => Storage::url($path)]);
}
return response()->json(['success' => false, 'message' => 'No video payload received']);
}
}

50
app/Models/Interview.php Normal file
View File

@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Interview extends Model
{
use HasFactory;
protected $fillable = [
'candidate_name',
'candidate_email',
'candidate_phone',
'temp_password',
'expires_at',
'language',
'status',
'assigned_interviewers',
'proctor_logs',
'submitted_code',
'submitted_language',
'code_output',
'recording_path',
'submission_unique_id',
'created_by',
];
protected $casts = [
'expires_at' => 'datetime',
'assigned_interviewers' => 'array',
'proctor_logs' => 'array',
];
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function warnings()
{
return $this->hasMany(InterviewWarning::class, 'interview_id');
}
public function isExpired(): bool
{
return now()->greaterThan($this->expires_at);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class InterviewWarning extends Model
{
use HasFactory;
protected $fillable = [
'interview_id',
'message',
'sent_by',
];
public function interview()
{
return $this->belongsTo(Interview::class, 'interview_id');
}
public function sender()
{
return $this->belongsTo(User::class, 'sent_by');
}
}

View File

@ -0,0 +1,42 @@
<?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('interviews', function (Blueprint $table) {
$table->id();
$table->string('candidate_name');
$table->string('candidate_email');
$table->string('candidate_phone');
$table->string('temp_password');
$table->timestamp('expires_at');
$table->string('language')->default('python'); // python, c, cpp, java, php, javascript
$table->string('status')->default('scheduled'); // scheduled, in_progress, completed, expired
$table->json('assigned_interviewers')->nullable();
$table->json('proctor_logs')->nullable();
$table->longText('submitted_code')->nullable();
$table->string('submitted_language')->nullable();
$table->longText('code_output')->nullable();
$table->string('recording_path')->nullable();
$table->string('submission_unique_id')->unique();
$table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('interviews');
}
};

View File

@ -0,0 +1,30 @@
<?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('interview_warnings', function (Blueprint $table) {
$table->id();
$table->foreignId('interview_id')->constrained('interviews')->onDelete('cascade');
$table->text('message');
$table->foreignId('sent_by')->nullable()->constrained('users')->onDelete('set null');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('interview_warnings');
}
};

View File

@ -0,0 +1,28 @@
<?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::table('users', function (Blueprint $table) {
$table->text('avatar')->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('avatar', 255)->nullable()->change();
});
}
};

View File

@ -813,6 +813,9 @@
</div>
<div class="nav-actions">
<!-- Allow Admin to view the User portal dashboard -->
<a href="{{ route('interview.index') }}" class="btn-nav" style="border-color: #22d3ee; color: #22d3ee; text-decoration: none;">
Assessment Hub
</a>
<a href="{{ route('onboarding.index') }}" class="btn-nav" style="border-color: #818cf8; color: #818cf8; text-decoration: none;">
🚀 Onboarding Hub
</a>

View File

@ -873,6 +873,10 @@
</svg>
</button>
<a href="{{ route('interview.index') }}" class="nav-action-btn" style="background: rgba(6,182,212,0.15); color: #22d3ee; border-color: rgba(6,182,212,0.3); text-decoration: none;" title="Candidate Live Assessment Portal">
Candidate Assessments
</a>
@if($user->canManageOnboarding())
<a href="{{ route('onboarding.index') }}" class="nav-action-btn" style="background: rgba(99,102,241,0.15); color: #818cf8; border-color: rgba(99,102,241,0.3); text-decoration: none;" title="Onboarding & Offboarding Hub">
🚀 Onboarding Hub

View File

@ -0,0 +1,99 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Candidate Assessment Login | SingleLogin</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color: #0b0f19;
--card-bg: rgba(15, 23, 42, 0.7);
--card-border: rgba(255, 255, 255, 0.22);
--accent-primary: #6366f1;
--accent-secondary: #0078d4;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Instrument Sans', sans-serif;
background-color: var(--bg-color);
color: white;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
}
body::before {
content: '';
position: absolute;
top: -15%;
left: -15%;
width: 60%;
height: 60%;
background: radial-gradient(circle, rgba(99, 102, 241, 0.2) 0%, rgba(0,0,0,0) 70%);
z-index: 0;
}
.login-card {
background: var(--card-bg);
border: 1px solid var(--card-border);
border-radius: 24px;
padding: 36px;
width: 100%;
max-width: 440px;
backdrop-filter: blur(24px);
box-shadow: 0 25px 50px rgba(0,0,0,0.5);
z-index: 10;
}
.form-input {
width: 100%;
padding: 12px 14px;
background: rgba(255, 255, 255, 0.05);
border: 1px solid var(--card-border);
border-radius: 10px;
color: white;
font-size: 0.9rem;
outline: none;
margin-bottom: 16px;
}
.form-input:focus {
border-color: var(--accent-primary);
box-shadow: 0 0 12px rgba(99, 102, 241, 0.35);
}
</style>
</head>
<body>
<div class="login-card">
<div style="text-align: center; margin-bottom: 24px;">
<div style="width: 50px; height: 50px; border-radius: 14px; background: linear-gradient(135deg, #6366f1 0%, #0078d4 100%); display: flex; align-items: center; justify-content: center; font-size: 1.5rem; margin: 0 auto 12px auto;">
</div>
<h2 style="font-family: 'Outfit', sans-serif; font-size: 1.5rem; font-weight: 700; color: white;">Candidate Assessment Portal</h2>
<div style="font-size: 0.8rem; color: #94a3b8; margin-top: 4px;">Enter temporary login credentials provided by HR</div>
</div>
@if(session('error'))
<div style="margin-bottom: 16px; background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; padding: 10px 14px; border-radius: 10px; font-size: 0.8rem;">
{{ session('error') }}
</div>
@endif
<form action="{{ route('interview.candidate.login.submit') }}" method="POST">
@csrf
<label style="display:block; font-size:0.8rem; color:#cbd5e1; margin-bottom:6px; font-weight:500;">Email or Phone Number</label>
<input type="text" name="identifier" required placeholder="alex@company.com or 9876543210" class="form-input">
<label style="display:block; font-size:0.8rem; color:#cbd5e1; margin-bottom:6px; font-weight:500;">Temporary Password</label>
<input type="password" name="temp_password" required placeholder="e.g. Pass-829103" class="form-input">
<button type="submit" style="width: 100%; padding: 12px; border-radius: 10px; background: linear-gradient(135deg, #6366f1 0%, #0078d4 100%); color: white; border: none; font-weight: 700; font-size: 0.95rem; cursor: pointer; margin-top: 10px;">
Enter Proctored Assessment Room
</button>
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,453 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Assessment Room - {{ $interview->candidate_name }} | SingleLogin</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&family=Instrument+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<!-- Monaco Code Editor Loader -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/loader.min.js"></script>
<style>
:root {
--bg-color: #080c14;
--card-bg: #0f172a;
--card-border: rgba(255, 255, 255, 0.15);
--accent-primary: #6366f1;
}
/* Modern Custom Scrollbars */
html, body, *, ::-webkit-scrollbar {
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.4) rgba(15, 23, 42, 0.35);
}
::-webkit-scrollbar {
width: 5px;
height: 5px;
}
::-webkit-scrollbar-track {
background: rgba(15, 23, 42, 0.35);
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.4);
border-radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Instrument Sans', sans-serif;
background-color: var(--bg-color);
color: white;
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
.ide-header {
height: 60px;
background: #0d1322;
border-bottom: 1px solid var(--card-border);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
}
.ide-layout {
display: grid;
grid-template-columns: 1fr 340px;
height: calc(100vh - 60px);
width: 100%;
}
.editor-section {
display: flex;
flex-direction: column;
border-right: 1px solid var(--card-border);
height: 100%;
}
#monaco-editor-container {
flex: 1;
width: 100%;
height: 100%;
}
.terminal-section {
height: 220px;
background: #050811;
border-top: 1px solid var(--card-border);
display: flex;
flex-direction: column;
}
.terminal-header {
height: 36px;
background: #090e1a;
border-bottom: 1px solid rgba(255,255,255,0.08);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
font-size: 0.75rem;
color: #94a3b8;
font-weight: 600;
}
#terminal-output {
flex: 1;
padding: 12px 16px;
font-family: 'Fira Code', monospace;
font-size: 0.8rem;
color: #34d399;
overflow-y: auto;
white-space: pre-wrap;
}
.proctor-sidebar {
background: #0d1322;
padding: 16px;
display: flex;
flex-direction: column;
gap: 16px;
overflow-y: auto;
}
.webcam-box {
width: 100%;
height: 180px;
background: #000;
border-radius: 12px;
border: 2px solid var(--card-border);
overflow: hidden;
position: relative;
}
#webcam {
width: 100%;
height: 100%;
object-fit: cover;
}
.btn-ide {
padding: 8px 16px;
border-radius: 8px;
font-weight: 600;
font-size: 0.8rem;
cursor: pointer;
border: 1px solid var(--card-border);
background: rgba(255,255,255,0.05);
color: white;
transition: all 0.2s ease;
}
.btn-ide-primary {
background: #10b981;
border-color: #10b981;
color: white;
}
.btn-ide-run {
background: #6366f1;
border-color: #6366f1;
color: white;
}
/* Warning Popup Overlay */
#warning-banner {
position: fixed;
top: 70px;
left: 50%;
transform: translateX(-50%);
background: rgba(239, 68, 68, 0.95);
color: white;
padding: 12px 24px;
border-radius: 12px;
font-weight: 700;
font-size: 0.9rem;
box-shadow: 0 10px 30px rgba(239, 68, 68, 0.5);
z-index: 9999;
display: none;
backdrop-filter: blur(10px);
}
</style>
</head>
<body>
<!-- Silent Warning Banner -->
<div id="warning-banner">
🚨 ATTENTION: <span id="warning-text">Please keep your eyes on the screen during the assessment.</span>
</div>
<!-- IDE Header Bar -->
<header class="ide-header">
<div style="display: flex; align-items: center; gap: 12px;">
<div style="font-weight: 700; font-family: 'Outfit', sans-serif; font-size: 1.05rem; color: white;">
Candidate Assessment Room
</div>
<code style="background: rgba(255,255,255,0.06); padding: 4px 10px; border-radius: 6px; color: #38bdf8; font-size: 0.75rem;">
ID: {{ $interview->submission_unique_id }}
</code>
</div>
<div style="display: flex; align-items: center; gap: 14px;">
<div style="display: flex; align-items: center; gap: 8px;">
<label style="font-size: 0.75rem; color: #94a3b8; font-weight: 500;">Language:</label>
<select id="language-select" class="btn-ide" style="background: #151b2c;">
<option value="python" {{ strtolower($interview->language) === 'python' ? 'selected' : '' }}>Python 3</option>
<option value="cpp" {{ strtolower($interview->language) === 'cpp' ? 'selected' : '' }}>C++ (GCC)</option>
<option value="c" {{ strtolower($interview->language) === 'c' ? 'selected' : '' }}>C (GCC)</option>
<option value="java" {{ strtolower($interview->language) === 'java' ? 'selected' : '' }}>Java 15</option>
<option value="php" {{ strtolower($interview->language) === 'php' ? 'selected' : '' }}>PHP 8.2 / Laravel</option>
<option value="javascript" {{ strtolower($interview->language) === 'javascript' ? 'selected' : '' }}>JavaScript (Node.js)</option>
</select>
</div>
<button onclick="runCode()" class="btn-ide btn-ide-run">
Run Code
</button>
<button onclick="submitSolution()" class="btn-ide btn-ide-primary">
Submit Final Solution
</button>
</div>
</header>
<!-- IDE Room Layout -->
<div class="ide-layout">
<!-- Main Editor & Terminal Area -->
<div class="editor-section">
<div id="monaco-editor-container"></div>
<div class="terminal-section">
<div class="terminal-header">
<span>EXECUTION OUTPUT TERMINAL (STDOUT / STDERR)</span>
<span id="run-status" style="color: #94a3b8;">Ready</span>
</div>
<div id="terminal-output">// Press 'Run Code' to execute candidate solution live...</div>
</div>
</div>
<!-- Sidebar: Proctored Video Feed & Candidate Info -->
<div class="proctor-sidebar">
<div class="webcam-box">
<video id="webcam" autoplay muted playsinline></video>
<div style="position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,0.6); padding: 2px 8px; border-radius: 4px; font-size: 0.65rem; color: #34d399; font-weight: 600;">
PROCTORED REC
</div>
</div>
<canvas id="proctor-canvas" style="display: none;" width="320" height="240"></canvas>
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--card-border); border-radius: 12px; padding: 14px; font-size: 0.8rem;">
<div style="font-weight: 700; color: white; margin-bottom: 6px;">Candidate Profile</div>
<div style="color: #94a3b8;">Name: <strong style="color: white;">{{ $interview->candidate_name }}</strong></div>
<div style="color: #94a3b8;">Email: <span style="color: white;">{{ $interview->candidate_email }}</span></div>
<div style="color: #94a3b8; margin-top: 6px;">Access Expires: <span style="color: #fca5a5;">{{ $interview->expires_at->format('H:i:s T') }}</span></div>
</div>
<div style="background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.25); border-radius: 12px; padding: 14px; font-size: 0.75rem; color: #fca5a5;">
<strong>🛡️ Proctored Assessment Rules:</strong>
<ul style="margin-top: 6px; padding-left: 16px; line-height: 1.5;">
<li>Do not switch tabs or minimize the browser window.</li>
<li>Ensure your face is clearly visible in the camera.</li>
<li>External AI overlays or screen sharing will trigger an alert.</li>
</ul>
</div>
</div>
</div>
<script>
let editor;
let interviewId = {{ $interview->id }};
let mediaRecorder;
let recordedChunks = [];
let previousFrameData = null;
// Default Code Snippets for Languages
const defaultCode = {
python: `# Python 3 Assessment Solution\ndef main():\n print("Hello from SingleLogin Assessment!")\n num = 42\n print(f"Computed Result: {num * 2}")\n\nif __name__ == "__main__":\n main()`,
cpp: `// C++ Assessment Solution\n#include <iostream>\nusing namespace std;\n\nint main() {\n cout << "Hello from SingleLogin Assessment!" << endl;\n return 0;\n}`,
c: `// C Assessment Solution\n#include <stdio.h>\n\nint main() {\n printf("Hello from SingleLogin Assessment!\\n");\n return 0;\n}`,
java: `// Java Assessment Solution\npublic class Solution {\n public static void main(String[] args) {\n System.out.println("Hello from SingleLogin Assessment!");\n }\n}`,
php: `<?php\n// PHP / Laravel Assessment Solution\necho "Hello from SingleLogin Assessment!\\n";\n$data = [1, 2, 3, 4, 5];\necho "Sum: " . array_sum($data);`,
javascript: `// JavaScript (Node.js) Solution\nconsole.log("Hello from SingleLogin Assessment!");\nconst nums = [10, 20, 30];\nconsole.log("Total:", nums.reduce((a, b) => a + b, 0));`
};
// Initialize Monaco Editor
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs' } });
require(['vs/editor/editor.main'], function () {
const initialLang = '{{ strtolower($interview->language) }}';
const initialCode = {!! json_encode($interview->submitted_code) !!} || defaultCode[initialLang] || defaultCode.python;
editor = monaco.editor.create(document.getElementById('monaco-editor-container'), {
value: initialCode,
language: initialLang === 'cpp' ? 'cpp' : (initialLang === 'c' ? 'c' : initialLang),
theme: 'vs-dark',
fontSize: 14,
fontFamily: 'Fira Code, monospace',
automaticLayout: true,
minimap: { enabled: true }
});
});
// Handle Language Switch
document.getElementById('language-select').addEventListener('change', function () {
const lang = this.value;
const monacoLang = lang === 'cpp' ? 'cpp' : (lang === 'c' ? 'c' : lang);
monaco.editor.setModelLanguage(editor.getModel(), monacoLang);
if (!editor.getValue() || editor.getValue() === defaultCode[lang]) {
editor.setValue(defaultCode[lang] || '');
}
});
// Execute Code live via Piston API
function runCode() {
document.getElementById('run-status').innerText = 'Running...';
document.getElementById('terminal-output').innerText = 'Executing solution on code engine...';
const lang = document.getElementById('language-select').value;
const code = editor.getValue();
fetch('{{ route("interview.execute") }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
body: JSON.stringify({ language: lang, code: code })
})
.then(r => r.json())
.then(data => {
document.getElementById('run-status').innerText = 'Ready';
if (data.success) {
document.getElementById('terminal-output').innerText = data.output;
} else {
document.getElementById('terminal-output').innerText = 'Error: ' + data.output;
}
})
.catch(err => {
document.getElementById('run-status').innerText = 'Error';
document.getElementById('terminal-output').innerText = 'Failed to reach code runner service.';
});
}
// Submit Solution
function submitSolution() {
const code = editor.getValue();
const lang = document.getElementById('language-select').value;
const output = document.getElementById('terminal-output').innerText;
fetch(`{{ route('interview.submit', $interview->id) }}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
body: JSON.stringify({ code: code, language: lang, output: output })
})
.then(r => r.json())
.then(data => {
alert('✓ ' + data.message);
});
}
// --- ANTI-CHEAT & PROCTORING ENGINE ---
// 1. Tab Switch Detection
document.addEventListener('visibilitychange', function () {
if (document.hidden) {
logViolation('tab_switch', 'Candidate switched browser tab or minimized window');
}
});
// 2. Window Focus Loss / External Screen Overlap Detection
window.addEventListener('blur', function () {
logViolation('focus_lost', 'Window lost focus (possible external AI overlay or screen overlap)');
});
// 3. Code Copy-Paste Detection
document.addEventListener('paste', function (e) {
logViolation('paste_event', 'Candidate pasted content into editor window');
});
function logViolation(type, details) {
fetch(`{{ route('interview.violation', $interview->id) }}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
body: JSON.stringify({ type: type, details: details })
});
}
// 4. WebRTC Camera Setup & Eye Gaze Analysis
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
.then(stream => {
const videoEl = document.getElementById('webcam');
videoEl.srcObject = stream;
// MediaRecorder silent video recording
try {
mediaRecorder = new MediaRecorder(stream, { mimeType: 'video/webm' });
mediaRecorder.ondataavailable = e => {
if (e.data.size > 0) recordedChunks.push(e.data);
};
mediaRecorder.start(10000); // 10s chunks
} catch (err) {}
// Client-side Eye Gaze & Camera Absence Motion Analysis
setInterval(analyzeCameraFrame, 3000);
})
.catch(err => {
logViolation('gaze_anomaly', 'Camera permission denied or video stream disabled');
});
function analyzeCameraFrame() {
const video = document.getElementById('webcam');
const canvas = document.getElementById('proctor-canvas');
if (!video || !canvas || video.readyState !== 4) return;
const ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
const imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
// Compute brightness / pixel motion difference
let sum = 0;
for (let i = 0; i < imgData.data.length; i += 4) {
sum += (imgData.data[i] + imgData.data[i+1] + imgData.data[i+2]) / 3;
}
const avgBrightness = sum / (imgData.data.length / 4);
if (avgBrightness < 15) {
logViolation('gaze_anomaly', 'Camera lens covered or room completely dark');
}
}
// 5. Silent Warning Polling
setInterval(() => {
fetch(`{{ route('interview.poll', $interview->id) }}`)
.then(r => r.json())
.then(data => {
if (data.warnings && data.warnings.length > 0) {
const lastWarn = data.warnings[data.warnings.length - 1];
document.getElementById('warning-text').innerText = lastWarn.message;
const banner = document.getElementById('warning-banner');
banner.style.display = 'block';
setTimeout(() => { banner.style.display = 'none'; }, 6000);
}
});
}, 5000);
</script>
</body>
</html>

View File

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Assessment Access Expired | SingleLogin</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Instrument Sans', sans-serif;
background-color: #0b0f19;
color: white;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.card {
background: rgba(15, 23, 42, 0.7);
border: 1px solid rgba(239, 68, 68, 0.3);
border-radius: 20px;
padding: 36px;
text-align: center;
max-width: 450px;
backdrop-filter: blur(20px);
}
</style>
</head>
<body>
<div class="card">
<div style="font-size: 3rem; margin-bottom: 16px;"></div>
<h2 style="font-family: 'Outfit', sans-serif; font-size: 1.4rem; color: #ef4444; margin-bottom: 8px;">Assessment Access Expired</h2>
<p style="font-size: 0.85rem; color: #94a3b8; margin-bottom: 20px;">
The temporary access window for <strong>{{ $interview->candidate_name }}</strong> expired on {{ $interview->expires_at->format('Y-m-d H:i T') }}.
</p>
<div style="font-size: 0.8rem; color: #cbd5e1; background: rgba(255,255,255,0.05); padding: 10px; border-radius: 8px;">
Unique Submission ID: <code style="color: #38bdf8;">{{ $interview->submission_unique_id }}</code>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,497 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Candidate Live Assessment Portal | SingleLogin</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<style>
:root {
--bg-color: #0b0f19;
--card-bg: rgba(15, 23, 42, 0.65);
--card-border: rgba(255, 255, 255, 0.22);
--accent-primary: #6366f1;
--accent-secondary: #0078d4;
--text-main: #ffffff;
--text-muted: #d1d5db;
}
/* Scrollbars */
html, body, *, ::-webkit-scrollbar {
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.4) rgba(15, 23, 42, 0.35);
}
::-webkit-scrollbar {
width: 5px;
height: 5px;
}
::-webkit-scrollbar-track {
background: rgba(15, 23, 42, 0.35);
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.4);
border-radius: 10px;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Instrument Sans', sans-serif;
background-color: var(--bg-color);
color: var(--text-main);
min-height: 100vh;
display: flex;
flex-direction: column;
}
.navbar {
height: 70px;
background: rgba(15, 23, 42, 0.8);
backdrop-filter: blur(16px);
border-bottom: 1px solid var(--card-border);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 4%;
position: sticky;
top: 0;
z-index: 100;
}
.btn-nav {
color: #e5e7eb;
text-decoration: none;
font-size: 0.85rem;
font-weight: 500;
padding: 8px 16px;
border-radius: 8px;
border: 1px solid var(--card-border);
background: rgba(255, 255, 255, 0.03);
transition: all 0.25s ease;
}
.btn-nav:hover {
background: rgba(255, 255, 255, 0.08);
color: white;
}
.assessment-card {
background: var(--card-bg);
border: 1px solid var(--card-border);
border-radius: 20px;
padding: 28px;
backdrop-filter: blur(20px);
box-shadow: 0 20px 40px rgba(0,0,0,0.4);
margin-bottom: 24px;
}
.table-responsive {
overflow-x: auto;
width: 100%;
}
.users-table {
width: 100%;
border-collapse: collapse;
font-size: 0.85rem;
text-align: left;
}
.users-table th {
padding: 12px 16px;
border-bottom: 1px solid var(--card-border);
color: var(--text-muted);
font-size: 0.75rem;
text-transform: uppercase;
}
.users-table td {
padding: 14px 16px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
vertical-align: middle;
}
.badge {
display: inline-flex;
align-items: center;
padding: 4px 8px;
border-radius: 9999px;
font-size: 0.7rem;
font-weight: 600;
}
.admin-modal {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(11, 15, 25, 0.85);
backdrop-filter: blur(12px);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
opacity: 0;
pointer-events: none;
transition: all 0.3s ease;
}
.admin-modal.active {
opacity: 1;
pointer-events: auto;
}
.admin-modal-content {
background-color: #151b2c;
border: 1px solid var(--card-border);
border-radius: 20px;
width: 90%;
max-width: 900px;
padding: 28px;
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
color: white;
max-height: 90vh;
overflow-y: auto;
}
.form-input {
width: 100%;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.05);
border: 1px solid var(--card-border);
border-radius: 8px;
color: white;
font-size: 0.85rem;
outline: none;
}
</style>
</head>
<body>
<!-- Header Navbar -->
<header class="navbar">
<div style="display: flex; align-items: center; gap: 12px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #6366f1 0%, #0078d4 100%); display: flex; align-items: center; justify-content: center; font-weight: 700;">
</div>
<div>
<h1 style="font-family: 'Outfit', sans-serif; font-size: 1.15rem; font-weight: 700; color: white; margin: 0;">Candidate Live Assessment Portal</h1>
<div style="font-size: 0.7rem; color: var(--text-muted);">Proctored IDE & Code Submissions</div>
</div>
</div>
<div style="display: flex; gap: 12px;">
@if(Auth::user()->isAdmin())
<a href="{{ route('admin.dashboard') }}" class="btn-nav" style="border-color: #818cf8; color: #818cf8;">Control Panel</a>
@endif
<a href="{{ route('onboarding.index') }}" class="btn-nav">Onboarding Hub</a>
<a href="{{ route('dashboard') }}" class="btn-nav">User Portal</a>
</div>
</header>
<main style="max-width: 1400px; width: 100%; margin: 30px auto; padding: 0 4%; flex: 1;">
@if(session('success'))
<div style="margin-bottom: 24px; background: rgba(16,185,129,0.15); border: 1px solid rgba(16,185,129,0.3); color: #34d399; padding: 12px 20px; border-radius: 12px; font-size: 0.9rem;">
{{ session('success') }}
</div>
@endif
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px;">
<div>
<h2 style="font-family: 'Outfit', sans-serif; font-size: 1.4rem; font-weight: 700; color: white; margin: 0;">Live Interview Assessments</h2>
<div style="font-size: 0.8rem; color: var(--text-muted);">Temporary Candidate Access, Real-Time Proctored IDE, and Unique Code Records</div>
</div>
<button onclick="document.getElementById('create-interview-modal').classList.add('active')" class="btn-nav" style="background-color: var(--accent-primary); color: white; border-color: transparent; font-weight: 600; padding: 10px 18px; cursor: pointer;">
+ Schedule Candidate Interview
</button>
</div>
<div class="assessment-card">
<div class="table-responsive">
<table class="users-table">
<thead>
<tr>
<th>Candidate & Temp Pass</th>
<th>Unique Submission ID</th>
<th>Status & Validity</th>
<th>Language</th>
<th>Proctoring Alerts</th>
<th style="text-align: right;">Review & Actions</th>
</tr>
</thead>
<tbody>
@forelse($interviews as $inv)
@php
$logs = $inv->proctor_logs ?? [];
$tabSwitches = count(array_filter($logs, fn($l) => ($l['type'] ?? '') === 'tab_switch'));
$focusLost = count(array_filter($logs, fn($l) => ($l['type'] ?? '') === 'focus_lost'));
$gazeAlerts = count(array_filter($logs, fn($l) => ($l['type'] ?? '') === 'gaze_anomaly'));
@endphp
<tr>
<td>
<div>
<strong style="color: white; font-size: 0.9rem;">{{ $inv->candidate_name }}</strong>
<div style="font-size: 0.75rem; color: var(--text-muted);">{{ $inv->candidate_email }} &bull; {{ $inv->candidate_phone }}</div>
<div style="margin-top: 4px; font-size: 0.75rem; color: #a7f3d0; background: rgba(16,185,129,0.1); padding: 2px 8px; border-radius: 6px; display: inline-block;">
🔑 Temp Password: <strong>{{ $inv->temp_password }}</strong>
</div>
</div>
</td>
<td>
<code style="background: rgba(255,255,255,0.06); padding: 4px 8px; border-radius: 6px; color: #38bdf8; font-size: 0.75rem;">
{{ $inv->submission_unique_id }}
</code>
</td>
<td>
@if($inv->isExpired())
<span class="badge" style="background: rgba(239,68,68,0.15); color: #fca5a5; border: 1px solid rgba(239,68,68,0.3);">
EXPIRED
</span>
@elseif($inv->status === 'completed')
<span class="badge" style="background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3);">
COMPLETED
</span>
@elseif($inv->status === 'in_progress')
<span class="badge" style="background: rgba(99,102,241,0.15); color: #818cf8; border: 1px solid rgba(99,102,241,0.3);">
IN PROGRESS
</span>
@else
<span class="badge" style="background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3);">
SCHEDULED
</span>
@endif
<div style="font-size: 0.7rem; color: var(--text-muted); margin-top: 4px;">
Expires: {{ $inv->expires_at->diffForHumans() }}
</div>
</td>
<td>
<span class="badge" style="background: rgba(255,255,255,0.05); color: white; border: 1px solid var(--card-border); text-transform: uppercase;">
{{ $inv->language }}
</span>
</td>
<td>
<div style="display: flex; flex-direction: column; gap: 2px; font-size: 0.75rem;">
<span style="color: {{ $tabSwitches > 0 ? '#ef4444' : 'var(--text-muted)' }}; font-weight: {{ $tabSwitches > 0 ? '700' : '400' }};">
🔴 Tab Switches: {{ $tabSwitches }}
</span>
<span style="color: {{ $focusLost > 0 ? '#fbbf24' : 'var(--text-muted)' }};">
🟡 Focus Loss / Overlay: {{ $focusLost }}
</span>
<span style="color: {{ $gazeAlerts > 0 ? '#f43f5e' : 'var(--text-muted)' }};">
👁️ Eye Gaze Anomaly: {{ $gazeAlerts }}
</span>
</div>
</td>
<td style="text-align: right; white-space: nowrap;">
<button onclick="openReviewModal({{ $inv->id }}, '{{ addslashes($inv->candidate_name) }}', '{{ $inv->submission_unique_id }}')" class="btn-nav" style="background: rgba(99,102,241,0.15); color: #818cf8; border-color: rgba(99,102,241,0.3); font-weight: 600; padding: 6px 12px; margin-right: 4px; cursor: pointer;">
🔍 Review Code & Proctor Logs
</button>
<a href="{{ route('interview.room', $inv->submission_unique_id) }}" target="_blank" class="btn-nav" style="padding: 6px 10px; font-size: 0.75rem;">
Open IDE Link
</a>
</td>
</tr>
@empty
<tr>
<td colspan="6" style="text-align: center; color: var(--text-muted); padding: 30px;">
No candidate interview sessions found. Click "+ Schedule Candidate Interview" above to create one.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</main>
<!-- Modal: Schedule Candidate Interview -->
<div id="create-interview-modal" class="admin-modal">
<div class="admin-modal-content" style="max-width: 600px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h3 style="font-family: 'Outfit', sans-serif; font-size: 1.25rem; font-weight: 700; color: white; margin: 0;">Schedule Candidate Assessment</h3>
<button onclick="document.getElementById('create-interview-modal').classList.remove('active')" style="background:none; border:none; color:var(--text-muted); font-size:1.5rem; cursor:pointer;">&times;</button>
</div>
<form action="{{ route('interview.store') }}" method="POST">
@csrf
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px;">
<div>
<label style="display:block; font-size:0.75rem; color:var(--text-muted); margin-bottom:4px; font-weight:500;">Candidate Name <span style="color:#ef4444;">*</span></label>
<input type="text" name="candidate_name" required placeholder="e.g. John Doe" class="form-input">
</div>
<div>
<label style="display:block; font-size:0.75rem; color:var(--text-muted); margin-bottom:4px; font-weight:500;">Candidate Email <span style="color:#ef4444;">*</span></label>
<input type="email" name="candidate_email" required placeholder="john@gmail.com" class="form-input">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px;">
<div>
<label style="display:block; font-size:0.75rem; color:var(--text-muted); margin-bottom:4px; font-weight:500;">Phone Number <span style="color:#ef4444;">*</span></label>
<input type="text" name="candidate_phone" required placeholder="9876543210" class="form-input">
</div>
<div>
<label style="display:block; font-size:0.75rem; color:var(--text-muted); margin-bottom:4px; font-weight:500;">Access Validity (Hours) <span style="color:#ef4444;">*</span></label>
<select name="valid_hours" required class="form-input" style="background: #151b2c;">
<option value="1">1 Hour</option>
<option value="2" selected>2 Hours</option>
<option value="4">4 Hours</option>
<option value="12">12 Hours</option>
<option value="24">24 Hours</option>
</select>
</div>
</div>
<div style="margin-bottom: 14px;">
<label style="display:block; font-size:0.75rem; color:var(--text-muted); margin-bottom:4px; font-weight:500;">Coding Language <span style="color:#ef4444;">*</span></label>
<select name="language" required class="form-input" style="background: #151b2c;">
<option value="python">Python 3</option>
<option value="cpp">C++ (GCC)</option>
<option value="c">C (GCC)</option>
<option value="java">Java 15</option>
<option value="php">PHP 8.2 / Laravel</option>
<option value="javascript">JavaScript (Node.js)</option>
</select>
</div>
<div style="margin-bottom: 16px;">
<label style="display:block; font-size:0.75rem; color:var(--text-muted); margin-bottom:6px; font-weight:500;">Assign Internal Interviewers / Panelists</label>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-height: 120px; overflow-y: auto; background: rgba(0,0,0,0.3); padding: 10px; border-radius: 8px; border: 1px solid var(--card-border);">
@foreach($interviewers as $usr)
<label style="display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: white; cursor: pointer;">
<input type="checkbox" name="assigned_interviewers[]" value="{{ $usr->id }}" style="accent-color: #6366f1;">
{{ $usr->name }} ({{ $usr->email }})
</label>
@endforeach
</div>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px;">
<button type="button" onclick="document.getElementById('create-interview-modal').classList.remove('active')" class="btn-nav">Cancel</button>
<button type="submit" class="btn-nav" style="background: var(--accent-primary); color: white; border-color: transparent; font-weight: 600;">Create Session & Password</button>
</div>
</form>
</div>
</div>
<!-- Modal: Live Review & Code Inspection -->
<div id="review-modal" class="admin-modal">
<div class="admin-modal-content">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 12px;">
<div>
<h3 id="modal-cand-name" style="font-family: 'Outfit', sans-serif; font-size: 1.25rem; font-weight: 700; color: white; margin: 0;">Review Candidate Session</h3>
<div id="modal-cand-uid" style="font-size: 0.75rem; color: #38bdf8;"></div>
</div>
<button onclick="document.getElementById('review-modal').classList.remove('active')" style="background:none; border:none; color:var(--text-muted); font-size:1.5rem; cursor:pointer;">&times;</button>
</div>
<div style="display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-bottom: 20px;">
<!-- Left: Code Editor & Execution Output -->
<div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;">
<span style="font-size: 0.8rem; font-weight: 600; color: white;">Submitted Code Solution:</span>
<span id="modal-code-lang" class="badge" style="background: rgba(99,102,241,0.2); color: #818cf8; font-size: 0.65rem;">PYTHON</span>
</div>
<pre id="modal-code-display" style="background: #090d16; border: 1px solid var(--card-border); border-radius: 10px; padding: 14px; font-family: monospace; font-size: 0.8rem; color: #e2e8f0; max-height: 250px; overflow-y: auto; white-space: pre-wrap; margin-bottom: 14px;"></pre>
<span style="font-size: 0.8rem; font-weight: 600; color: white;">Execution Stdout / Stderr Output:</span>
<pre id="modal-output-display" style="background: #050811; border: 1px solid var(--card-border); border-radius: 10px; padding: 12px; font-family: monospace; font-size: 0.75rem; color: #34d399; max-height: 120px; overflow-y: auto; white-space: pre-wrap;"></pre>
</div>
<!-- Right: Proctoring Logs & Silent Warning Sender -->
<div>
<span style="font-size: 0.8rem; font-weight: 600; color: white;">Proctoring Violation Audit:</span>
<div id="modal-logs-display" style="background: rgba(0,0,0,0.3); border: 1px solid var(--card-border); border-radius: 10px; padding: 10px; max-height: 200px; overflow-y: auto; margin-bottom: 14px; font-size: 0.7rem; color: var(--text-muted);">
No proctoring violations recorded.
</div>
<!-- Silent Warning Form -->
<div style="background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.25); border-radius: 12px; padding: 12px;">
<div style="font-size: 0.75rem; color: #fca5a5; font-weight: 600; margin-bottom: 6px;">Send Silent Warning to Candidate:</div>
<input type="text" id="warning-input" placeholder="e.g. Please keep your camera centered." class="form-input" style="font-size: 0.75rem; margin-bottom: 8px;">
<button onclick="sendSilentWarning()" class="btn-nav" style="width: 100%; background: #ef4444; color: white; border: none; font-size: 0.75rem; font-weight: 600; padding: 6px; cursor: pointer;">
🚨 Send Warning Message
</button>
</div>
</div>
</div>
<div style="display: flex; justify-content: flex-end;">
<button type="button" onclick="document.getElementById('review-modal').classList.remove('active')" class="btn-nav">Close</button>
</div>
</div>
</div>
<script>
let currentInterviewId = null;
function openReviewModal(id, name, uid) {
currentInterviewId = id;
document.getElementById('modal-cand-name').innerText = name;
document.getElementById('modal-cand-uid').innerText = 'Unique Submission ID: ' + uid;
document.getElementById('review-modal').classList.add('active');
// Fetch live poll data
fetch(`{{ route('interview.poll', ':id') }}`.replace(':id', id))
.then(r => r.json())
.then(data => {
document.getElementById('modal-code-lang').innerText = (data.submitted_language || 'UNKNOWN').toUpperCase();
document.getElementById('modal-code-display').innerText = data.submitted_code || '// Candidate has not submitted code yet.';
document.getElementById('modal-output-display').innerText = data.code_output || 'No execution output.';
let logsHtml = '';
if (data.proctor_logs && data.proctor_logs.length > 0) {
data.proctor_logs.forEach(l => {
let icon = '🔴';
if (l.type === 'focus_lost') icon = '🟡';
if (l.type === 'gaze_anomaly') icon = '👁️';
logsHtml += `<div style="margin-bottom:6px; border-bottom:1px solid rgba(255,255,255,0.05); padding-bottom:4px;">
<strong>${icon} ${l.type.toUpperCase()}:</strong> ${l.details || ''}
<div style="font-size:0.65rem; color:#94a3b8;">${new Date(l.timestamp).toLocaleTimeString()}</div>
</div>`;
});
} else {
logsHtml = '<div style="color:#34d399;">✅ Zero proctoring violations recorded.</div>';
}
document.getElementById('modal-logs-display').innerHTML = logsHtml;
});
}
function sendSilentWarning() {
const msg = document.getElementById('warning-input').value.trim();
if (!msg || !currentInterviewId) return;
fetch(`{{ route('interview.warning', ':id') }}`.replace(':id', currentInterviewId), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
body: JSON.stringify({ message: msg })
})
.then(r => r.json())
.then(res => {
if (res.success) {
alert('Silent warning sent to candidate screen!');
document.getElementById('warning-input').value = '';
}
});
}
</script>
</body>
</html>

View File

@ -2,6 +2,7 @@
use App\Http\Controllers\AdminController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\InterviewController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\OnboardingController;
use Illuminate\Support\Facades\Route;
@ -23,12 +24,21 @@
Route::get('/auth/microsoft/callback', [LoginController::class, 'handleMicrosoftCallback'])->name('auth.microsoft.callback');
Route::get('/auth/microsoft/logout', [LoginController::class, 'frontChannelLogout'])->name('auth.microsoft.logout');
// User Dashboard Portal (requires standard user role or admin access)
// Candidate Assessment Portal Routes (Public & Temporary Credentials Auth)
Route::get('/candidate/login', [InterviewController::class, 'showCandidateLogin'])->name('interview.candidate.login');
Route::post('/candidate/login', [InterviewController::class, 'loginCandidate'])->name('interview.candidate.login.submit');
Route::get('/candidate/test/{uniqueId}', [InterviewController::class, 'showCandidateRoom'])->name('interview.room');
Route::post('/candidate/execute-code', [InterviewController::class, 'executeCode'])->name('interview.execute');
Route::post('/candidate/submit-code/{id}', [InterviewController::class, 'submitCode'])->name('interview.submit');
Route::post('/candidate/log-violation/{id}', [InterviewController::class, 'logViolation'])->name('interview.violation');
Route::post('/candidate/upload-recording/{id}', [InterviewController::class, 'uploadRecording'])->name('interview.upload-recording');
// User Dashboard Portal (requires authenticated user)
Route::middleware(['auth', 'role:user', 'verify-ms-session'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
});
Route::middleware(['auth', 'role:user'])->group(function () {
Route::middleware(['auth'])->group(function () {
Route::get('/sso/launch/{id}', [DashboardController::class, 'launchSSO'])->name('sso.launch');
Route::get('/sso/personal-launch/{id}', [DashboardController::class, 'launchPersonalSSO'])->name('sso.personal-launch');
Route::get('/sso/callback', [DashboardController::class, 'handleSSOCallback'])->name('sso.callback');
@ -39,13 +49,19 @@
Route::post('/dashboard/personal-apps/{id}/update', [DashboardController::class, 'updatePersonalApp'])->name('dashboard.personal-apps.update');
Route::delete('/dashboard/personal-apps/{id}', [DashboardController::class, 'destroyPersonalApp'])->name('dashboard.personal-apps.destroy');
// Onboarding & Offboarding Management Routes (accessible by Admin, HR, or authorized roles)
// Onboarding & Offboarding Management Routes
Route::get('/onboarding', [OnboardingController::class, 'index'])->name('onboarding.index');
Route::post('/onboarding', [OnboardingController::class, 'store'])->name('onboarding.store');
Route::post('/onboarding/{id}/activate', [OnboardingController::class, 'activate'])->name('onboarding.activate');
Route::post('/onboarding/{id}/offboard', [OnboardingController::class, 'offboard'])->name('onboarding.offboard');
Route::post('/onboarding/{id}/checklist', [OnboardingController::class, 'updateChecklist'])->name('onboarding.checklist');
Route::delete('/onboarding/{id}', [OnboardingController::class, 'destroy'])->name('onboarding.destroy');
// Candidate Assessment Management for HR & Panelists
Route::get('/interviews', [InterviewController::class, 'index'])->name('interview.index');
Route::post('/interviews', [InterviewController::class, 'store'])->name('interview.store');
Route::post('/interviews/{id}/warning', [InterviewController::class, 'sendWarning'])->name('interview.warning');
Route::get('/interviews/{id}/poll', [InterviewController::class, 'getPollData'])->name('interview.poll');
});
// Admin Control Panel (requires admin role)

View File

@ -0,0 +1,163 @@
<?php
namespace Tests\Feature;
use App\Models\Interview;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class CandidateInterviewPortalTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware();
}
public function test_hr_can_create_candidate_interview_and_generate_temp_credentials(): void
{
$hr = User::create([
'name' => 'HR Manager',
'email' => 'hr@company.com',
'role' => 'user',
]);
$response = $this->actingAs($hr)
->post(route('interview.store'), [
'candidate_name' => 'Alex Candidate',
'candidate_email' => 'alex.cand@gmail.com',
'candidate_phone' => '9876543210',
'valid_hours' => 2,
'language' => 'python',
]);
$response->assertRedirect(route('interview.index'));
$this->assertDatabaseHas('interviews', [
'candidate_name' => 'Alex Candidate',
'candidate_email' => 'alex.cand@gmail.com',
'candidate_phone' => '9876543210',
'status' => 'scheduled',
]);
}
public function test_candidate_can_login_with_temp_credentials_and_access_ide_room(): void
{
$interview = Interview::create([
'candidate_name' => 'Sarah Candidate',
'candidate_email' => 'sarah@gmail.com',
'candidate_phone' => '9123456789',
'temp_password' => 'Pass-123456',
'expires_at' => now()->addHours(2),
'language' => 'cpp',
'status' => 'scheduled',
'submission_unique_id' => 'sarah-candidate_9123456789_1752000000',
]);
$response = $this->post(route('interview.candidate.login.submit'), [
'identifier' => 'sarah@gmail.com',
'temp_password' => 'Pass-123456',
]);
$response->assertRedirect(route('interview.room', $interview->submission_unique_id));
$this->get(route('interview.room', $interview->submission_unique_id))
->assertStatus(200)
->assertSee('Sarah Candidate')
->assertSee('sarah-candidate_9123456789_1752000000');
}
public function test_live_code_execution_via_piston_api_proxy(): void
{
Http::fake([
'https://emkc.org/api/v2/piston/execute' => Http::response([
'run' => [
'output' => "Hello from SingleLogin Assessment!\nComputed Result: 84\n"
]
], 200)
]);
$response = $this->post(route('interview.execute'), [
'language' => 'python',
'code' => 'print("Hello from SingleLogin Assessment!")',
]);
$response->assertStatus(200)
->assertJson([
'success' => true,
'output' => "Hello from SingleLogin Assessment!\nComputed Result: 84\n"
]);
}
public function test_candidate_code_submission_saves_under_unique_submission_id(): void
{
$interview = Interview::create([
'candidate_name' => 'Michael Dev',
'candidate_email' => 'michael@gmail.com',
'candidate_phone' => '9988776655',
'temp_password' => 'Pass-654321',
'expires_at' => now()->addHours(2),
'language' => 'php',
'status' => 'in_progress',
'submission_unique_id' => 'michael-dev_9988776655_1752000001',
]);
$response = $this->post(route('interview.submit', $interview->id), [
'code' => '<?php echo "Solution completed";',
'language' => 'php',
'output' => 'Solution completed',
]);
$response->assertStatus(200)
->assertJson([
'success' => true,
'unique_id' => 'michael-dev_9988776655_1752000001'
]);
$interview->refresh();
$this->assertEquals('completed', $interview->status);
$this->assertEquals('<?php echo "Solution completed";', $interview->submitted_code);
}
public function test_proctoring_violation_logging_and_silent_warning(): void
{
$hr = User::create([
'name' => 'Interviewer HR',
'email' => 'hrpanel@company.com',
'role' => 'admin',
]);
$interview = Interview::create([
'candidate_name' => 'Test Candidate',
'candidate_email' => 'test@gmail.com',
'candidate_phone' => '9111111111',
'temp_password' => 'Pass-111111',
'expires_at' => now()->addHours(2),
'language' => 'python',
'status' => 'in_progress',
'submission_unique_id' => 'test-candidate_9111111111_1752000002',
]);
// Log tab switch violation
$this->post(route('interview.violation', $interview->id), [
'type' => 'tab_switch',
'details' => 'Candidate switched tab',
])->assertStatus(200);
// Send silent warning from HR
$this->actingAs($hr)
->post(route('interview.warning', $interview->id), [
'message' => 'Please stay on the test tab.',
])->assertStatus(200);
// Verify poll endpoint returns violation and warning
$pollResponse = $this->get(route('interview.poll', $interview->id));
$pollResponse->assertStatus(200)
->assertJsonFragment(['type' => 'tab_switch'])
->assertJsonFragment(['message' => 'Please stay on the test tab.']);
}
}