Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\AppSetting;
use App\Models\User;
use App\Models\UserAppreciation;
use App\Notifications\UserAppreciationNotification;
Expand All @@ -26,7 +27,11 @@ public function index()
return redirect()->route('me');
}

return Inertia::render('auth/Login');
$allowRegistration = (bool) AppSetting::get('allow_registration', true);

return Inertia::render('auth/Login', [
'allowRegistration' => $allowRegistration,
]);
}

public function redirectToGoogle(Request $request)
Expand Down Expand Up @@ -83,6 +88,11 @@ public function handleGoogleCallback(Request $request)
return redirect()->intended($defaultUrl);
}

$allowRegistration = (bool) AppSetting::get('allow_registration', true);
if (! $allowRegistration) {
return redirect()->route('login')->with('error', 'রেজিস্ট্রেশন সাময়িকভাবে স্থগিত রাখা হয়েছে। পূর্বে তৈরিকৃত অ্যাকাউন্ট দিয়ে লগইন করতে পারেন।');
}

$rawName = $googleUser->getName() ?? $googleUser->getNickname() ?? '';
$cleanGoogleName = ChatProfanityFilter::hasProfanity($rawName) ? 'Student' : $rawName;

Expand Down
63 changes: 51 additions & 12 deletions app/Http/Controllers/UserProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function show(string $username)
'facebook' => $user->facebook,
'instagram' => $user->instagram,
'github' => $user->github,
'website' => $user->website,
'created_at' => $user->created_at?->format('M Y') ?? '2026',
'is_verified' => $user->is_verified,
'is_online' => $user->isOnline(),
Expand Down Expand Up @@ -85,18 +86,39 @@ public function show(string $username)
}
}

$appreciators = $user->appreciators()
$authId = auth()->id();

$rawAppreciators = $user->appreciators()
->select(['users.id', 'users.name', 'users.username', 'users.image_path', 'users.institution', 'users.is_verified'])
->latest('user_appreciations.id')
->take(15)
->get();

$appreciating = $user->appreciatingUsers()
$rawAppreciating = $user->appreciatingUsers()
->select(['users.id', 'users.name', 'users.username', 'users.image_path', 'users.institution', 'users.is_verified'])
->latest('user_appreciations.id')
->take(15)
->get();

$allModalUserIds = $rawAppreciators->pluck('id')->concat($rawAppreciating->pluck('id'))->unique();
$myAppreciatingIds = $authId && $allModalUserIds->isNotEmpty()
? UserAppreciation::where('appreciator_id', $authId)->whereIn('user_id', $allModalUserIds)->pluck('user_id')->flip()->toArray()
: [];

$appreciators = $rawAppreciators->map(function ($u) use ($myAppreciatingIds) {
$data = $u->toArray();
$data['is_appreciated'] = isset($myAppreciatingIds[$u->id]);

return $data;
});

$appreciating = $rawAppreciating->map(function ($u) use ($myAppreciatingIds) {
$data = $u->toArray();
$data['is_appreciated'] = isset($myAppreciatingIds[$u->id]);

return $data;
});

$pokeEnabled = (bool) AppSetting::get('peer_poke_enabled', true);
$canPoke = $pokeEnabled && ! $isOwner && ($user->allow_pokes ?? true);
$isPokeOnCooldown = $canPoke && auth()->check() && Cache::has('study_poke:'.auth()->id().":{$user->id}");
Expand Down Expand Up @@ -281,9 +303,8 @@ private function getSyllabusProgress(User $user): array
$trackableSubjects = $subjectsQuery
->with(['nodes' => function ($query) {
$query->where('is_trackable', true)
->with('parent:id,name,sort_order')
->orderBy('sort_order', 'asc')
->select('id', 'subject_id', 'parent_id', 'name', 'slug', 'sort_order', 'weight');
->select('id', 'subject_id', 'name', 'slug', 'sort_order', 'weight');
}])
->get(['id', 'name', 'slug', 'course', 'tailwind_format', 'icon', 'sort_order']);

Expand Down Expand Up @@ -322,12 +343,6 @@ private function getSyllabusProgress(User $user): array
'name' => $node->name,
'weight' => $nodeWeight,
'is_completed' => $isDone,
'parent_id' => $node->parent_id,
'parent' => $node->parent ? [
'id' => $node->parent->id,
'name' => $node->parent->name,
'sort_order' => $node->parent->sort_order,
] : null,
];
}

Expand Down Expand Up @@ -376,8 +391,20 @@ public function appreciators(Request $request, User $user): JsonResponse
->latest('user_appreciations.id')
->simplePaginate(15);

$authId = auth()->id();
$myAppreciatingIds = $authId
? UserAppreciation::where('appreciator_id', $authId)->whereIn('user_id', $paginator->pluck('id'))->pluck('user_id')->flip()->toArray()
: [];

$items = collect($paginator->items())->map(function ($u) use ($myAppreciatingIds) {
$data = $u->toArray();
$data['is_appreciated'] = isset($myAppreciatingIds[$u->id]);

return $data;
})->all();

return response()->json([
'users' => $paginator->items(),
'users' => $items,
'has_more' => $paginator->hasMorePages(),
'current_page' => $paginator->currentPage(),
]);
Expand All @@ -393,8 +420,20 @@ public function appreciating(Request $request, User $user): JsonResponse
->latest('user_appreciations.id')
->simplePaginate(15);

$authId = auth()->id();
$myAppreciatingIds = $authId
? UserAppreciation::where('appreciator_id', $authId)->whereIn('user_id', $paginator->pluck('id'))->pluck('user_id')->flip()->toArray()
: [];

$items = collect($paginator->items())->map(function ($u) use ($myAppreciatingIds) {
$data = $u->toArray();
$data['is_appreciated'] = isset($myAppreciatingIds[$u->id]);

return $data;
})->all();

return response()->json([
'users' => $paginator->items(),
'users' => $items,
'has_more' => $paginator->hasMorePages(),
'current_page' => $paginator->currentPage(),
]);
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/Profile/UpdateProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ public function rules(): array
'about' => ['sometimes', 'nullable', 'string', 'max:255', new CleanText],
'institution' => ['sometimes', 'nullable', 'string', 'max:255', new CleanText],
'activity_privacy' => ['sometimes', 'string', Rule::in(['public', 'appreciators_only', 'private'])],
'batch' => ['sometimes', 'nullable', 'string', 'max:32'],
'allow_pokes' => ['sometimes', 'boolean'],
'facebook' => ['sometimes', 'nullable', 'string', 'max:255'],
'instagram' => ['sometimes', 'nullable', 'string', 'max:255'],
'github' => ['sometimes', 'nullable', 'string', 'max:255'],
'website' => ['sometimes', 'nullable', 'string', 'max:255'],
'receive_emails' => ['sometimes', 'boolean'],
];
}
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/User/StoreUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function rules(): array
'username' => ['nullable', 'string', 'min:3', 'max:30', 'regex:/^[a-zA-Z0-9_]+$/', 'unique:users,username', new CleanText],
'email' => ['required', 'email', 'unique:users,email'],
'is_verified' => ['sometimes', 'boolean'],
'is_board_member' => ['sometimes', 'boolean'],
'priority' => ['sometimes', 'nullable', 'integer', 'min:0', 'max:1000000'],
'role' => ['nullable', 'string'],
'permissions' => ['nullable', 'array'],
Expand All @@ -40,6 +41,7 @@ public function rules(): array
'facebook' => ['nullable', 'string', 'max:255'],
'instagram' => ['nullable', 'string', 'max:255'],
'github' => ['nullable', 'string', 'max:255'],
'website' => ['nullable', 'string', 'max:255'],
];
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/User/UpdateUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public function rules(): array
'facebook' => ['sometimes', 'nullable', 'string', 'max:255'],
'instagram' => ['sometimes', 'nullable', 'string', 'max:255'],
'github' => ['sometimes', 'nullable', 'string', 'max:255'],
'website' => ['sometimes', 'nullable', 'string', 'max:255'],
'is_verified' => ['sometimes', 'boolean'],
'is_board_member' => ['sometimes', 'boolean'],
'priority' => ['sometimes', 'nullable', 'integer', 'min:0', 'max:1000000'],
'role' => ['sometimes', 'nullable', 'string'],
'permissions' => ['sometimes', 'nullable', 'array'],
Expand Down
3 changes: 3 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class User extends Authenticatable
'email',
'receive_emails',
'is_verified',
'is_board_member',
'priority',
'google_id',
'email_verified_at',
Expand All @@ -55,10 +56,12 @@ class User extends Authenticatable
'activity_privacy',
'curriculum',
'group',
'batch',
'allow_pokes',
'facebook',
'instagram',
'github',
'website',
'optional_subject_ids',
'last_active_at',
'last_seen_at',
Expand Down
37 changes: 2 additions & 35 deletions app/Notifications/SupportTicketUpdatedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Models\SupportTicket;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;

Expand All @@ -18,45 +17,13 @@ public function __construct(
) {}

/**
* Get the notification's delivery channels.
* Get the notification's delivery channels (In-app database only).
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
$channels = ['database'];

if (! empty($notifiable->email) && ($notifiable->receive_emails ?? true)) {
$channels[] = 'mail';
}

return $channels;
}

/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$statusLabel = ucfirst(str_replace('_', ' ', $this->ticket->status));
$lines = [
"Your support ticket #{$this->ticket->ticket_number} (\"{$this->ticket->subject}\") has an update from our team.",
"Current Status: {$statusLabel}",
];

if ($this->ticket->admin_reply) {
$lines[] = "Staff Reply: \"{$this->ticket->admin_reply}\"";
}

return (new MailMessage)
->subject("Support Ticket #{$this->ticket->ticket_number} Updated 🎫")
->view('emails.default', [
'subject' => "Ticket #{$this->ticket->ticket_number} Updated",
'greeting' => "Hello {$notifiable->name},",
'lines' => $lines,
'actionText' => 'View My Tickets',
'actionUrl' => route('support.my-tickets'),
]);
return ['database'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/UserAppreciationNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function toArray(object $notifiable): array
'type' => 'user_appreciation',
'title' => "{$this->appreciator->name} appreciated you!",
'message' => "You have {$this->totalAppreciations} community appreciations.",
'url' => route('user.profile', $notifiable->username),
'url' => route('user.profile', $notifiable->username).'#appreciators',
'appreciator_id' => $this->appreciator->id,
'total_appreciations' => $this->totalAppreciations,
'count' => 1,
Expand Down
30 changes: 30 additions & 0 deletions database/migrations/2026_10_25_072530_add_batch_to_users_table.php
Original file line number Diff line number Diff line change
@@ -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::table('users', function (Blueprint $table) {
$table->string('batch', 32)->nullable()->after('group');
$table->index('batch');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropIndex(['batch']);
$table->dropColumn('batch');
});
}
};
Original file line number Diff line number Diff line change
@@ -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->string('website')->nullable()->after('github');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('website');
});
}
};
Original file line number Diff line number Diff line change
@@ -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->boolean('is_board_member')->default(false)->after('is_verified');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('is_board_member');
});
}
};
Loading
Loading