Search
Search
Search
Search
Information
Information
Light
Dark
Open actions menu
Basic upload method
Bypass upload method
Tips!
If you encounter an error (by firewall) while uploading using both methods,
try changing extension of the file before uploading it and rename it right after.
This uploader supports multiple file upload.
Submit
~
var
www
multi-event-cfp.bitkit.dk
httpdocs
app
Http
Controllers
File Content:
UserController.php
<?php namespace App\Http\Controllers; use App\Models\Abstracts; use App\Models\Event; use App\Models\Score; use App\Models\UserApiAccess; use App\Models\SpeakerNotes; use App\Repositories\AmendSpeakerTermsRepository; use Illuminate\Support\Facades\Log; use App\Models\User; use App\Models\Session; use App\Repositories\AbstractsRepository; use App\Repositories\AuthRepository; use App\Repositories\SlotRepository; use App\Repositories\UserRepository; use Exception; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; use App\Jobs\SendRegisterEventMail; use App\Models\Slot; use App\Models\EventUser; use App\Jobs\SendSpeakerTerms; use App\Models\File; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Str; use Illuminate\Support\Facades\DB; /** @OA\Info(title="DMG Events Conferences API", version="0.1", description="Endpoint: ") */ class UserController extends Controller { protected $repository; protected $amendSpeakerTermsRepository; public function __construct(UserRepository $userRepository, AmendSpeakerTermsRepository $amendSpeakerTermsRepository) { $this->repository = $userRepository; $this->amendSpeakerTermsRepository = $amendSpeakerTermsRepository; } public function checkEventUser(Request $request) { try { $input = $request->all(); $validator = Validator::make($input, [ 'slug_name' => 'required', 'email' => 'required', 'role' => 'required' ]); if ($validator->fails()) validationErrorResponse($validator->errors()); $event = Event::whereSlugName($input['slug_name'])->first(); if (!$event) validationErrorResponse(['Event not found']); return $this->repository->checkEventUserExists($event, $input['email'], $input['role']); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function checkUser(Request $request) { try { $email = $request->get('email'); $user = User::whereEmail($email)->first(); if (!$user) return response([ 'status' => false, 'message' => 'User not found' ]); $authEventUser = $request->get('event_user'); $user->contact_restricted = shouldRestrictContact($user, $authEventUser); return response([ 'status' => true, 'user' => $user ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function loginAndRegisterEvent(Request $request) { try { $authRepo = new AuthRepository(); $eventSlug = $request->get('event_slug'); $event = Event::whereSlugName($eventSlug)->first(); if (!$event) validationErrorResponse(['Event not found']); $platformSettings = $event->platform_settings->toArray(); if (!$platformSettings['submitter_registration']) return response([ 'status' => false, 'platform_disabled' => true, 'message' => 'Submitter registration disabled' ], 404); $authResponse = $authRepo->authenticate($request); $authResponseContent = json_decode($authResponse->getContent()); if (!$authResponseContent->status) { return $authResponse; } $user = authUser(); $eventUser = getEventUser($event, $user); if ($eventUser) { if ($eventUser->hasRole('event_submitter')) return response([ 'status' => false, 'message' => 'User already registered for event' ]); else $eventUser->assignRole('event_submitter'); } else { $this->repository->attachUserToEvent($event, $user, 'event_submitter'); // event user $eventUser = getEventUser($event->id, $user->id); // type $eventUser->type = "technical"; // user added via $eventUser->user_added_via = "Registration"; // save $eventUser->save(); if (!$user->valid) { $user->valid = true; $user->save(); } } $user->events = $user->getEventWithRoles()->get(); //sending event registration mail $this->dispatch(new SendRegisterEventMail($event, $user)); return response([ 'status' => true, 'message' => 'User registered to event', 'user' => $user ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * @param Request $request * @return \App\Support\Entity|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Illuminate\Http\Response * @throws Exception */ public function authUserRegisterEvent(Request $request) { try { $eventSlug = $request->get('event_slug'); $event = Event::whereSlugName($eventSlug)->first(); if (!$event) validationErrorResponse(['Event not found']); $user = authUser(); $eventUser = getEventUser($event, $user); if ($eventUser && $eventUser->hasRole('event_submitter')) return response([ 'status' => false, 'message' => "User already registered for the event as submitter" ]); $authRepo = new AuthRepository(); $email = $request->get('email'); $password = $request->get('password'); $authResponse = $authRepo->authenticateWithGuard($email, $password); if (!$authResponse) { if (!User::whereEmail($email)->first()) { return response()->json(["status" => false, "errors" => ["email" => ["The email address was not found. Please double check and try again"]]], 200); } else { return response()->json(["status" => false, "errors" => ["password" => ["Invalid credentials"]]], 200); } } //attaching user to event $this->repository->attachUserToEvent($event, $user, 'event_submitter'); // event user $eventUser = getEventUser($event->id, $user->id); // type $eventUser->type = "technical"; // user added via $eventUser->user_added_via = "Registration"; // save $eventUser->save(); if (!$user->valid) { $user->valid = true; $user->save(); } $user->events = $user->getEventWithRoles()->get(); //sending event registration mail $this->dispatch(new SendRegisterEventMail($event, $user)); return response([ 'status' => true, 'message' => 'User registered to event', 'user' => $user ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function registerEvent(Request $request) { try { $eventSlug = $request->get('event_slug'); $event = Event::whereSlugName($eventSlug)->first(); if (!$event) validationErrorResponse(['Event not found']); $platformSettings = $event->platform_settings->toArray(); if (!$platformSettings['submitter_registration']) return response([ 'status' => false, 'platform_disabled' => true, 'message' => 'Submitter registration disabled' ], 404); $data = $request->all(); $user = $this->repository->createUser($data); $this->repository->attachUserToEvent($event, $user, 'event_submitter'); // event user $eventUser = getEventUser($event->id, $user->id); // type $eventUser->type = "technical"; // user added via $eventUser->user_added_via = "Registration"; // save $eventUser->save(); Auth::loginUsingId($user->id, true); $user->events = $user->getEventWithRoles()->get(); //sending event registration mail $this->dispatch(new SendRegisterEventMail($event, $user)); return response([ 'status' => true, 'message' => "Successfully registered", 'user' => $user ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function updateSubmitter(Request $request) { try { $user = authUser(); $event = $request->get('event'); $data = $request->get('data'); $data = json_decode($data, true); if ($data['id'] != $user->id) validationErrorResponse(['User id not valid']); unset($data['email']); $this->repository->updateUser($data, $user, $request, $user->id, $event ? $event->id : null); $removeAvatar = $request->get('avatar') === "null"; $removeCompanyLogo = $request->get('company_logo') === "null"; $removeUserSecondaryImage = $request->get('user_secondary_image') === "null"; $this->repository->removeUserImages($user, $removeAvatar, $removeCompanyLogo, $removeUserSecondaryImage); $imageFiles = $request->allFiles(); $this->repository->updateUserImages($imageFiles, $user, $user->id, $event ? $event->id : null); $this->repository->handleUserFiles($request, $data, $user, $user->id, $event ? $event->id : null); $user->events = $user->getEventWithRoles()->get(); activity('user.update') ->performedOn($user) ->causedBy(authUser()) ->log('User updated'); return response([ 'status' => true, 'user' => $user ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function getCompanyNames() { try { $companies = User::all()->where('company', '!=', null)->pluck('company')->unique()->toArray(); $companies = array_values($companies); return response([ 'status' => true, 'companies' => $companies ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function getAuthUser(Request $request) { try { $user = authUser(); $user->events = $user->getEventWithRoles()->get(); return ["status" => true, "user" => $user]; } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function view(Request $request, $id) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); $user = User::find($id); if (!$user) return response([ 'status' => false, 'message' => 'User not found' ]); //check event user exists $event = $request->get('event'); $eventUser = getEventUser($event, $user); //attaching event profile data to user if ($eventUser) { $user->event_profile_data = $eventUser->event_profile_data; $user->confirmed_speaker = $eventUser->confirmed_speaker; $user->speaker_added_via = $eventUser->speaker_added_via; $user->agreement_status = $eventUser->agreement_status; $user->agreement_details = $eventUser->agreement_details; $user->verification_data = $eventUser->verification_data; $user->verified_data = $eventUser->verified_data; $user->verification_status = $eventUser->verification_status; $user->verification_date = $eventUser->verification_date; $user->verified_by = $eventUser->verified_by; $user->type = $eventUser->type; $eventWithRoles = $user->getEventWithRoles($eventUser->event->id)->first(); $eventRoles = $eventWithRoles->roles; $user->event_roles = $eventRoles; } // Get other events for this user (excluding current event) $otherEvents = $user->getEventWithRoles() ->where('events.id', '!=', $event->id) ->select([ 'events.id', 'events.event_name', 'events.year', 'event_user.confirmed_speaker', 'event_user.type', DB::raw("GROUP_CONCAT(distinct(r.name)) as roles") ]) ->groupBy('events.id') ->get() ->map(function($eventData) { return [ 'event_name' => $eventData->event_name, 'year' => $eventData->year, 'confirmed_speaker' => (bool) $eventData->confirmed_speaker, 'type' => $eventData->type, 'roles' => $eventData->roles ? (is_string($eventData->roles) ? explode(',', $eventData->roles) : $eventData->roles) : [] ]; }); $user->other_events = $otherEvents; // Check if contact should be restricted $authUser = authUser(); $authEventUser = getEventUser($event, $authUser); $user->contact_restricted = shouldRestrictContact($user, $authEventUser); // Expose vip_marked_by_name $vipMarkedByUser = $user->vipMarkedBy; $user->vip_marked_by_name = $vipMarkedByUser ? $vipMarkedByUser->name : null; if ($request->get('confirmed_speaker') ?? false) { $eventId = $event->id; $user->load([ 'slots' => function ($query) use ($eventId) { $query->where('slots.event_id', '=', $eventId); $query->join('sessions', 'sessions.id', '=', 'slots.session_id') ->addSelect(['slots.*', 'sessions.title as session_title']); } ]); $user->load([ 'sessions' => function ($query) use ($eventId) { $query->where('sessions.event_id', '=', $eventId); } ]); $user->load([ 'presentations' => function ($query) use ($eventId) { $query->where('presentations.event_id', '=', $eventId); } ]); } return response([ 'status' => true, 'user' => $user ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * @OA\Get( * path="/api/user/list", * summary="Get the list of users in an event", * tags={"User"}, * @OA\Parameter(name="role", * in="header", * required=true, * @OA\Schema(type="string") * ), * @OA\Parameter(name="slug-name", * in="header", * required=true, * @OA\Schema(type="string") * ), * @OA\Parameter(name="event_role", * in="query", * required=true, * description="This is used to filter out role of user in an event. values : event_admin,event_reviewer,event_co_chair,event_submitter", * @OA\Schema(type="string") * ), * @OA\Parameter(name="paging", * in="query", * required=false, * description="No. of records in a page. You can use 'All' to get all result", * @OA\Schema(type="string") * ), * @OA\Parameter(name="page", * in="query", * required=false, * @OA\Schema(type="integer") * ), * @OA\Parameter(name="search", * in="query", * required=false, * description="Search by any keyword", * @OA\Schema(type="string") * ), * @OA\Parameter(name="sort", * in="query", * required=false, * description="Sort the list by columns. eg. {""name"":""asc""}. Multisort available eg. {""name"":""asc"",""email"":""asc""}. Available column names id,first_name,last_name,email,name etc..", * @OA\Schema(type="json") * ), * @OA\Parameter(name="confirmed_speakers", * in="query", * required=false, * description="Filter confirmed speaker only", * @OA\Schema(type="boolean") * ), * @OA\Parameter(name="full_data", * in="query", * required=false, * description="To get full user details. Values true or false", * @OA\Schema(type="boolean") * ), * @OA\Parameter(name="filter", * in="query", * required=false, * description="Additional filters for user list. eg. {""biography"":[""set"",""not_set""],""avatar"":[""set"",""not_set""],""company_logo"":[""set"",""not_set""],""mobile"":[""set"",""not_set""],""last_synced_date"":""2025-01-25""}", * @OA\Schema(type="json") * ), * @OA\Response(response="200", * description="List of users", * ) * ) */ public function list(Request $request) { try { $role = $request->get('role'); // event role $eventRole = $request->get('event_role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); // Add flag to include contact restriction in repository query $request->merge(['include_contact_restriction' => true]); $data = $this->repository->listing($request, true); // query for add abstract assigned count and remaining score count if ($eventRole == 'event_reviewer' && $role = 'event_admin') { foreach ($data as $key => $result) { // abstract repository $abstractRepository = new AbstractsRepository(); // select event user $eventUser = EventUser::find($result->event_user_id); // abstract based on the event user $abstracts = $abstractRepository->getReviewerAbstract($eventUser, true, $request); // abstract ids $abstractIds = $abstracts->pluck('id')->all(); // scores $scores = Score::whereUserId($eventUser->user->id) ->whereEventId($eventUser->event->id) ->whereIn('abstract_id', $abstractIds) ->get(); // abstract count $abstractsCount = $abstracts->count(); // score count $scoresCount = $scores->count(); // adding already score count count to array $result->abstract_scored_count = $scoresCount; // adding abstract count to array $result->assigned_abstract_count = $abstractsCount; // adding remaining score count $result->remaining_score_count = $abstractsCount - (int) $scoresCount; // filter $filter = $request->get('filter'); // Decode the JSON string into an associative array $filterArray = json_decode($filter, true); // Check if assigned_abstract_count is zero, and remove the item from $data if it is, // and if 'category' key exists in the filter array if ($result->assigned_abstract_count === 0 && $filterArray && isset($filterArray['category'])) { unset($data[$key]); } } } $data = $data->toArray(); if ($eventRole == 'event_reviewer' && $role = 'event_admin') { //$data = array_values($data); } $paging = $request->get('paging', '10'); unset($data['links']); return response([ 'status' => true, 'users' => $paging == 'All' ? ['data' => $data, 'total' => count($data)] : $data, ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function speakerCount(Request $request) { try { $event = $request->get('event'); $speakerCount = $this->repository->getSpeakerCount($event); $slotRepository = new SlotRepository(); $slotCount = $slotRepository->getSlotCount($event); return response([ 'status' => true, 'speaker_count' => $speakerCount, 'slot_count' => $slotCount ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function eventUserCount(Request $request) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); $count = $this->repository->getEventUserCount($request->get('event')); return response([ 'status' => true, 'count' => $count ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * @OA\Post( * path="/api/user", * summary="Create a new user", * tags={"User"}, * @OA\Parameter(name="role", * in="header", * required=true, * @OA\Schema(type="string") * ), * @OA\Parameter(name="slug-name", * in="header", * required=true, * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * description="User Details", * @OA\JsonContent( * required={"email","roles","first_name","last_name","job_title","company","country","mobile","salutation"}, * @OA\Property(property="email", type="string", format="email", example="user2@mail.com"), * @OA\Property(property="salutation", type="string", example="Mr"), * @OA\Property(property="first_name", type="string", example="test first name"), * @OA\Property(property="last_name", type="string", example="test last name"), * @OA\Property(property="job_title", type="string", example="test job title"), * @OA\Property(property="linkedin_link", type="string", example="test link"), * @OA\Property(property="country", type="string", example="India"), * @OA\Property(property="mobile", type="string", example="8089584913"), * @OA\Property(property="phone", type="string", example="8089584913"), * @OA\Property(property="fax", type="string", example="1123546"), * @OA\Property(property="company", type="string", example="test company"), * @OA\Property(property="company_address", type="string", example="test company address"), * @OA\Property(property="company_country", type="string", example="India"), * @OA\Property(property="industry_code", type="string", example="Energy Producer"), * @OA\Property(property="post_code", type="string", example="673305"), * @OA\Property(property="state", type="string", example="test state"), * @OA\Property(property="city", type="string", example="test city"), * @OA\Property(property="street", type="string", example="test street"), * @OA\Property(property="biography", type="string", example="test bio"), * @OA\Property(property="do_not_send_emails", type="boolean", example="false"), * @OA\Property(property="cc_emails", type="string", example="tpjasar88@gmail.com,jojo@gmail.com"), * @OA\Property(property="send_login", type="boolean", example="true"), * @OA\Property(property="confirmed_speaker", type="boolean", example="true"), * @OA\Property(property="type", type="string", example="strategic,technical"), * @OA\Property(property="event_profile_data", type="object", example={"number_of_presentation": "5","presentation_submission": true, "send_adobe_contract" : true}), * @OA\Property(property="roles", type="array", @OA\Items(example="event_admin")), * @OA\Property(property="salesforce_opportunity_id", type="string", minLength=18, maxLength=18, example="0065g00000Nf1KIAAZ"), * ), * ), * @OA\Response(response="200", * description="Create a user", * ) * ) */ public function createOrUpdate(Request $request) { try { $role = $request->get('role'); $event = $request->get('event'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); $data = $request->get('data'); $data = $data ? json_decode($data, true) : json_decode($request->getContent(), true); // Prevent editing contact info for VIP users by limited access admins $authUser = authUser(); $authEventUser = getEventUser($event, $authUser); if (isset($data['id'])) { $existingUser = User::find($data['id']); if ($existingUser && shouldRestrictContact($existingUser, $authEventUser)) { unset($data['email'], $data['phone'], $data['mobile']); } } $modifiedBy = authUser()->id; [$user, $eventUser] = $this->repository->createOrUpdate($data, $request->get('event'), $modifiedBy, $event->id); $eventProfileData = $data['event_profile_data'] ?? null; if ($eventProfileData) { if (isset($eventProfileData['presentation_submission']) && isset($eventProfileData['number_of_presentation'])) { if ($eventProfileData['presentation_submission']) { $eventProfileData['number_of_presentation'] = $eventProfileData['number_of_presentation']; } else { $eventProfileData['number_of_presentation'] = null; } } } $eventUser->event_profile_data = $eventProfileData; $eventUser->confirmed_speaker = $data['confirmed_speaker'] ?? null; // Set access_level if admin role if (isset($eventProfileData['access_level'])) { $eventUser->access_level = $eventProfileData['access_level']; } if ($eventUser->confirmed_speaker && $eventUser->order == null) { $lastConfirmedSpeakerOrder = EventUser::where('event_id', $event->id) ->where('confirmed_speaker', 1) ->whereNotNull('confirmed_speaker') ->max('order'); // Set the order for the new confirmed speaker $eventUser->order = $lastConfirmedSpeakerOrder + 1; } if (($data['speaker_added_via'] ?? false) && !$eventUser->speaker_added_via) $eventUser->speaker_added_via = $data['speaker_added_via']; $eventUser->save(); $removeAvatar = $request->get('avatar') === "null"; $removeCompanyLogo = $request->get('company_logo') === "null"; $removeUserSecondaryImage = $request->get('user_secondary_image') === "null"; $this->repository->removeUserImages($user, $removeAvatar, $removeCompanyLogo, $removeUserSecondaryImage); $imageFiles = $request->allFiles(); $this->repository->updateUserImages($imageFiles, $user, $modifiedBy, $event->id); $this->repository->handleUserFiles($request, $data, $user, $modifiedBy, $event->id); $user->event_profile_data = $eventProfileData; activity('user.update') ->performedOn($user) ->causedBy(authUser()) ->log('User updated or created by admin'); //general settings $general_settings = $event->general_settings; // dtcm enabled or disabled $short_form_terms_option = $general_settings['speaker_terms_prefill']['terms_and_condition_status'] || false; // send speaker terms to the user // if the type is strategic and confirmed speaker is true and agreement status is null // send_adobe_contract should be true // short form terms option should be false if ( $role == 'event_admin' && !$short_form_terms_option && $eventUser->confirmed_speaker && !$eventUser->agreement_details && isset($eventUser->event_profile_data['send_adobe_contract']) && $eventUser->event_profile_data['send_adobe_contract'] ) { // send speaker terms dispatch(new SendSpeakerTerms([$eventUser])); } $user->vip_marked_by_name = $user->vipMarkedBy ? $user->vipMarkedBy->name : null; return response([ 'status' => true, 'user' => $user ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function deleteUser(Request $request, $id) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); $user = User::find($id); if (!$user) return response([ 'status' => false, 'message' => 'User not found' ]); $event = $request->get('event'); $eventUser = getEventUser($event, $user); $removeRole = $request->get('remove_role'); if (!$eventUser) return response([ 'status' => false, 'message' => 'Cannot delete user of other event' ]); return $this->repository->deleteUser($user, $eventUser, $removeRole); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function resetPassword(Request $request) { try { return $this->repository->resetPassword($request); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function sendLoginInfo(Request $request) { try { return $this->repository->sendLoginInfo($request); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function importUserTemplate(Request $request) { try { $role = $request->get('role'); $event = Event::whereSlugName($request->get('slug'))->first(); //event form settings $form_settings = $event->form_settings; //general settings $general_settings = $event->general_settings; // dtcm enabled or disabled $dtcm_fields_enabled = $general_settings['dtcm_form_fields_section']['dtcm_form_fields'] || false; // dtcm enabled or disabled $short_form_terms_option = $general_settings['speaker_terms_prefill']['terms_and_condition_status'] || false; if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } return $this->repository->importUserTemplate($form_settings, $dtcm_fields_enabled, $short_form_terms_option); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function importUser(Request $request) { try { $role = $request->get('role'); if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } $event = $request->get('event'); return $this->repository->importUser($request, $event); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function fetchAgreementStatus(Request $request, $id) { try { $role = $request->get('role'); if ($role != 'event_admin' && $role != 'event_submitter' && $role != 'event_reviewer') return response([ 'status' => false, 'message' => 'Access denied' ]); $event = $request->get('event'); $eventUser = getEventUser($event->id, (int) $id); if (!$eventUser) return response([ 'status' => false, 'message' => "User not found" ]); $eventUser = $this->repository->fetchAgreementStatus($eventUser); return response([ 'status' => true, 'agreement_status' => $eventUser->agreement_status ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function fetchMultipleSpeakerAgreementStatus(Request $request) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); // event $event = $request->get('event'); // speaker ids $speakerIds = $request->get('speakerIds'); foreach ($speakerIds as $speakerId) { try { $eventUser = getEventUser($event->id, (int) $speakerId); if (!$eventUser) return response([ 'status' => false, 'message' => "User not found" ]); $eventUser = $this->repository->fetchAgreementStatus($eventUser); } catch (Exception $e) { continue; // Skip to the next speaker } } return response([ 'status' => true, 'message' => "Success" ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function fetchMultipleSpeakerRemindMail(Request $request) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); // event $event = $request->get('event'); // speaker ids $speakerIds = $request->get('speakerIds'); foreach ($speakerIds as $speakerId) { try { $eventUser = getEventUser($event->id, (int) $speakerId); if (!$eventUser) return response([ 'status' => false, 'message' => "User not found" ]); $this->repository->remindAgreementToSign($eventUser); } catch (Exception $e) { continue; // Skip to the next speaker } } return response([ 'status' => true, 'message' => "Success" ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function downloadAgreement(Request $request, $id) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); $event = $request->get('event'); $eventUser = getEventUser($event->id, (int) $id); if (!$eventUser) return response([ 'status' => false, 'message' => "User not found" ]); if ($eventUser->agreement_status != "SIGNED") return response([ 'status' => false, 'message' => "Agreement not yet signed" ]); [$headers, $streamFileData] = $this->repository->downloadAgreement($eventUser); return response($streamFileData, 200, $headers); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function remindAgreement(Request $request, $id) { try { $role = $request->get('role'); if ($role != 'event_admin' && $role != 'event_submitter') return response([ 'status' => false, 'message' => 'Access denied' ]); $event = $request->get('event'); $eventUser = getEventUser($event->id, (int) $id); if (!$eventUser) return response([ 'status' => false, 'message' => "User not found" ]); $this->repository->remindAgreementToSign($eventUser); return response([ 'status' => true, 'message' => "Successfully resend/reminded agreement" ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function cancelAgreement(Request $request, $id) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); $event = $request->get('event'); $eventUser = getEventUser($event->id, (int) $id); if (!$eventUser) return response([ 'status' => false, 'message' => "User not found" ]); $this->repository->cancelAgreement($eventUser, $event); return response([ 'status' => true, 'message' => "Successfully cancelled" ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function listToken(Request $request) { try { $role = $request->get('role'); $user = authUser(); if ($role != 'event_admin' && !$user->hasRole($role)) return response([ 'status' => false, 'message' => "Access denied" ]); $event = $request->get('event'); $eventUser = getEventUser($event, $user); if (!$eventUser->developer_options) return response([ 'status' => false, 'message' => "Access denied" ]); $tokens = $user->tokens()->get(); return response([ 'status' => true, 'tokens' => $tokens ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function deleteToken(Request $request, $id) { try { $role = $request->get('role'); $user = authUser(); if ($role != 'event_admin' && !$user->hasRole($role)) return response([ 'status' => false, 'message' => "Access denied" ]); $event = $request->get('event'); $eventUser = getEventUser($event, $user); if (!$eventUser->developer_options) return response([ 'status' => false, 'message' => "Access denied" ]); $token = $user->tokens()->where('id', '=', $id)->first(); if (!$token) return response([ 'status' => false, 'message' => "Token not found" ]); $token->delete(); return response([ 'status' => true, 'message' => 'Token deleted successfully' ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function generateToken(Request $request) { try { $role = $request->get('role'); $user = authUser(); if ($role != 'event_admin' && !$user->hasRole($role)) return response([ 'status' => false, 'message' => "Access denied" ]); $event = $request->get('event'); $eventUser = getEventUser($event, $user); if (!$eventUser->developer_options) return response([ 'status' => false, 'message' => "Access denied" ]); $name = $request->get('name'); $token = $this->repository->generateToken($name); return response([ 'status' => true, 'token' => $token->accessToken ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } // Downloading user files public function downloadUserFiles(Request $request) { try { // role $role = $request->get('role'); // download mode, default to multiple $downloadMode = $request->get('download_mode', 'multiple'); // event admin if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); // all user ids $userIds = $request['user_ids']; // dtcm form status $dtcmFormStatus = $request['dtcm_form']; if (!$userIds) return response([ 'status' => false, 'message' => 'Users not found' ]); $users = User::findMany($userIds); if (!$users) { return response([ 'status' => false, 'message' => 'No files' ]); } // add files to zip return $this->repository->addingToZip($users, $request, $downloadMode); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } public function export(Request $request) { try { ini_set('memory_limit', '-1'); // role $role = $request->get('role'); // event $event = $request->get('event'); // confirmed speaker $confirmedSpeaker = $request->get('confirmed_speakers'); //general settings $generalSettings = $event->general_settings; if ($role != 'event_admin') return response([ 'status' => false, 'message' => "Access denied" ]); $userIds = $request->get('user_ids', false); if (!$userIds) { // user list with all score counts $usersData = $this->list($request); // Extract the content from the response $content = json_decode($usersData->getContent()); // User data $userCollection = collect($content->users->data); // Speaker ordering if request is confirmed speaker if ($confirmedSpeaker) { // Sort the confirmed speakers based on speaker_order $sortedConfirmedSpeakers = $userCollection->sortBy('speaker_order'); // Use pluck to extract user IDs $userIds = $sortedConfirmedSpeakers->pluck('id')->toArray(); } else { // If $confirmedSpeaker is false, just use all user IDs $userIds = $userCollection->pluck('id')->toArray(); } } if (!empty($userIds)) { // users $users = User::whereIn('id', $userIds) ->orderByRaw('FIELD(id, ' . implode(',', $userIds) . ')') ->get(); } else { // Handle the case when $userIds is empty $users = []; } if (!$users) return response([ 'status' => false, 'message' => "No Users" ]); return $this->repository->exportUsers($users, $event, $generalSettings, $confirmedSpeaker); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } //update speaker order public function updateSpeakerOrder(Request $request) { try { // Retrieve request parameters $role = $request->get('role'); $event = $request->get('event'); $speakerIds = $request->get('reorderedSpeakers'); $page = $request->get('page'); $paging = $request->get('paging'); $speakerCurrentOrder = $request->get('speakerCurrentOrder'); $speakerNewOrder = $request->get('speakerNewOrder'); // Check user role if ($role != 'event_admin') return response([ 'status' => false, 'message' => "Access denied" ]); // Handle manual editing of speaker order if ($speakerCurrentOrder !== null && $speakerNewOrder !== null) { // update speaker order manually return $this->updateManualSpeakerOrder($event, $speakerCurrentOrder, $speakerNewOrder); } // Update entire order based on drag and drop return $this->updateDragAndDropSpeakerOrder($event, $speakerIds, $page, $paging); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } // update speaker order when manually editing public function updateManualSpeakerOrder($event, $speakerCurrentOrder, $speakerNewOrder) { // Fetch all confirmed speakers $request = new Request(); $request->replace([ 'paging' => 'all', 'role' => 'event_admin', 'event' => $event, 'confirmed_speakers' => true ]); // speakers $speakers = $this->repository->listing($request, false)->toArray(); // Check if new order exceeds the number of speakers if ($speakerNewOrder > count($speakers)) { return response()->json(['status' => false, 'message' => 'The new order exceeds the total number of speakers.']); } foreach ($speakers as $speaker) { // event user $eventUser = EventUser::where('event_id', $event->id) ->where('user_id', $speaker['id']) ->first(); if ($eventUser) { // change speaker order $this->changeSpeakerOrder($eventUser, $speaker, $speakerCurrentOrder, $speakerNewOrder); } } return response()->json(['status' => true, 'message' => 'Speaker order updated successfully']); } // change speaker order public function changeSpeakerOrder($eventUser, $speaker, $speakerCurrentOrder, $speakerNewOrder) { if ($speaker['speaker_order'] == $speakerCurrentOrder) { $eventUser->order = $speakerNewOrder; } elseif ($speaker['speaker_order'] >= $speakerNewOrder && $speaker['speaker_order'] < $speakerCurrentOrder) { $eventUser->order = $speaker['speaker_order'] + 1; } elseif ($speaker['speaker_order'] <= $speakerNewOrder && $speaker['speaker_order'] > $speakerCurrentOrder) { $eventUser->order = $speaker['speaker_order'] - 1; } $eventUser->save(); } // update speaker order when drag and drop applied public function updateDragAndDropSpeakerOrder($event, $speakerIds, $page, $paging) { foreach ($speakerIds as $index => $speakerId) { $eventUser = EventUser::where('event_id', $event->id) ->where('user_id', $speakerId) ->first(); if ($eventUser) { $eventUser->order = ($paging == 'All') ? ($index + 1) : ($index + 1 + $page * $paging); $eventUser->save(); } } return response()->json(['status' => true, 'message' => 'Speaker order updated successfully']); } // Downloading user files // public function downloadUserFiles(Request $request) // { // try { // // role // $role = $request->get('role'); // // event admin // if ($role != 'event_admin') // return response([ // 'status' => false, // 'message' => 'Access denied' // ]); // // // all user ids // $userIds = $request['user_ids']; // // dtcm form status // $dtcmFormStatus = $request['dtcm_form']; // // if (!$userIds) // return response([ // 'status' => false, // 'message' => 'Users not found' // ]); // // $users = User::findMany($userIds); // // if (!$users) { // return response([ // 'status' => false, // 'message' => 'No files' // ]); // } // // add files to zip // return $this->repository->addingToZip($users, $request); // } catch (Exception $exception) { // return $this->handleException($exception, __FUNCTION__, __CLASS__); // } // } // user verification public function userVerification(Request $request) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); return $this->repository->userVerification($request); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } // create speaker note public function createSpeakerNotes(Request $request) { try { $role = $request->get('role'); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); // speaker note $speakerNote = $this->repository->getSpeakerNotesRepository()->createSpeakerNotes($request); $speakerNote->load('user'); return response([ 'status' => true, 'speaker_notes' => $speakerNote ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } // list speaker notes public function listSpeakerNotes(Request $request, $speakerId) { try { $role = $request->get('role'); // merge speaker id $request->merge(['speaker_id' => $speakerId]); if ($role != 'event_admin') return response([ 'status' => false, 'message' => 'Access denied' ]); // speaker note $speakerNotes = $this->repository->getSpeakerNotesRepository()->listing($request, true); return response([ 'status' => true, 'speaker_notes' => $speakerNotes ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } // download note file public function downloadNoteFIle(Request $request, $noteId, $fileId) { try { $file = File::whereId($fileId) ->whereModelId($noteId) ->whereModel(SpeakerNotes::class) ->first(); if (!$file) return response([ 'status' => false, 'message' => "File not found" ]); $filePath = $file->filepath . $file->save_name; return Storage::download($filePath, $file->filename); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * Create a new API access token for a user. * Only users with the 'event_admin' role are allowed to create tokens. */ public function createAllUserAccessApiToken(Request $request) { try { // Check if the user has the 'event_admin' role $role = $request->get('role'); if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } // Validate request data $request->validate([ 'name' => 'required|string|max:255', ]); // Get the user ID and name $userId = Auth::id(); $name = $request->name; // Encrypt the plain text token (name) $encryptedToken = Str::substr(Crypt::encryptString($name), 0, 32); // Hash the name and store it in the token field $hashedToken = Str::substr(Hash::make($name), 0, 32); // Create and save the API token record $apiToken = UserApiAccess::create([ 'user_id' => $userId, 'name' => $name, 'plain_text_token' => $encryptedToken, 'token' => $hashedToken, 'last_used_at' => null, ]); // Return the created API token return response([ 'status' => true, 'message' => 'Token created successfully', 'token' => $apiToken ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * List all user API access tokens. * Only users with the 'event_admin' role are allowed to view the tokens. */ public function listAllUserAccessApiTokens(Request $request) { try { // Check if the user has the 'event_admin' role $role = $request->get('role'); // Get the user ID and name $userId = Auth::id(); if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } // Retrieve and return all user API tokens with user info $tokens = UserApiAccess::with('user')->where('user_id', '=', $userId)->get(); return response([ 'status' => true, 'tokens' => $tokens ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * Delete all user API access token. * Only users with the 'event_admin' role are allowed to view the tokens. */ public function deleteAllUserAccessApiToken(Request $request, $id) { try { // Check if the user has the 'event_admin' role $role = $request->get('role'); if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } // Find all tokens associated with the user $token = UserApiAccess::where('id', '=', $id)->first(); if (!$token) return response([ 'status' => false, 'message' => "Token not found" ]); $token->delete(); return response([ 'status' => true, 'message' => 'Token deleted successfully' ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * @OA\Get( * path="/api/user/events/users", * summary="Get the list of users in all events", * tags={"User"}, * @OA\Parameter(name="role", * in="header", * required=true, * @OA\Schema(type="string") * ), * @OA\Parameter(name="access-token", * in="query", * required=true, * description="Add the Token for get access to this API", * @OA\Schema(type="string") * ), * @OA\Parameter(name="paging", * in="query", * required=false, * description="No. of records in a page. You can use 'All' to get all result", * @OA\Schema(type="string") * ), * @OA\Parameter(name="page", * in="query", * required=false, * @OA\Schema(type="integer") * ), * @OA\Parameter(name="search", * in="query", * required=false, * description="Search by any keyword", * @OA\Schema(type="string") * ), * @OA\Parameter(name="filter", * in="query", * required=false, * description="Additional filters for user list. eg. {""biography"":[""set"",""not_set""],""avatar"":[""set"",""not_set""],""company_logo"":[""set"",""not_set""],""mobile"":[""set"",""not_set""]}", * @OA\Schema(type="json") * ), * @OA\Response(response="200", * description="List of users", * ) * ) */ public function listAllEventsUsers(Request $request) { try { // Check if the 'role' is 'event_admin' $role = $request->get('role'); if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } // Get the token from the request $token = $request->get('access-token'); // Check if the token is provided in the request if (!$token) { return response([ 'status' => false, 'message' => 'Token is required' ]); } // Validate if the token exists in the UserApiAccess table $apiToken = UserApiAccess::where('plain_text_token', $token)->first(); // If the token is not found, return an error response if (!$apiToken) { return response([ 'status' => false, 'message' => 'Invalid token' ]); } // auth user $userId = Auth::id(); // all events the user belongs to $eventUsers = EventUser::where('user_id', '=', $userId)->get(); // Check if all events have 'all_user_api_access' set to false if ( $eventUsers->every(function ($eventUser) { return $eventUser->all_user_api_access == false; }) ) { // If all events have 'all_user_api_access' set to false, deny access return response([ 'status' => false, 'message' => 'Access denied' ]); } if ($apiToken) { $apiToken->last_used_at = now(); // Set current timestamp $apiToken->save(); // Save the record to the database } // fetching users and their events if token is valid $query = User::select(['id', 'first_name', 'last_name', 'email', 'company', 'job_title']); // Arguments and search filtering $arguments = $this->repository->arguments($request); $this->repository->applySearch($query, $arguments); $this->repository->applyFilter($query, $arguments); // Pagination logic to handle 'All' or specific page sizes $paginate = true; $users = ($paginate && $arguments->paging != 'All') ? $query->paginate($arguments->paging, ['*'], 'page', $arguments->page) : $query->get(); // Map the user's events with roles and additional details $data = $users->map(function ($user) { $user->events = $user->getEventWithRoles() ->select([ 'events.id', 'events.event_name', 'events.slug_name', 'events.year', 'event_user.type', 'event_user.confirmed_speaker', DB::raw("GROUP_CONCAT(distinct(r.name)) as roles") ]) ->get(); return $user; }); // paging logic and return the response $paging = $request->get('paging', '10'); return response([ 'status' => true, 'users' => $paging == 'All' ? ['data' => $data, 'total' => count($data)] : $data, ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } // public function createCancelPresentationRequest(Request $request) // { // try { // $role = $request->get('role'); // // create presentation request count without abstract // $createPresentationRequestCount = $request->get('presentation_request_count'); // if ($role != 'event_submitter') // return response([ // 'status' => false, // 'message' => 'Access denied' // ]); // // auth user // $user = authUser(); // // event // $event = $request->get('event'); // // event user // $eventUser = EventUser::whereEventId($event->id) // ->whereUserId($user->id) // ->first(); // if ($eventUser) { // // presentation request count // $eventUser->presentation_request_count = $createPresentationRequestCount; // // save // $eventUser->save(); // // response // return response([ // 'status' => true, // 'user' => $user // ]); // } // // response // return response([ // 'status' => false, // 'user' => $user // ]); // } // catch (Exception $exception) { // return $this->handleException($exception, __FUNCTION__, __CLASS__); // } // } /** * Global Users Directory - Search users across all events * Accessible to all admins regardless of event * * @param Request $request * @return \Illuminate\Http\Response */ public function globalUserSearch(Request $request) { try { $role = $request->get('role'); if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } // Validate at least one search field is provided $validator = Validator::make($request->all(), [ 'name' => 'nullable|string|max:255', 'email' => 'nullable|email|max:255', 'company' => 'nullable|string|max:255', 'job_title' => 'nullable|string|max:255', 'country' => 'nullable|string|max:255' ]); if ($validator->fails()) { return response([ 'status' => false, 'errors' => $validator->errors() ], 422); } // Check at least one field is filled $searchFields = ['name', 'email', 'company', 'job_title', 'country']; $hasSearchCriteria = collect($searchFields)->some(fn($field) => !empty($request->get($field))); if (!$hasSearchCriteria) { return response([ 'status' => false, 'message' => 'At least one search field must be filled' ], 422); } // Get current event for "Add to Event" logic $currentEvent = $request->get('event'); // Use repository for global search $users = $this->repository->globalUserSearch($request, $currentEvent); return response([ 'status' => true, 'users' => $users ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * Add user to current event as submitter * * @param Request $request * @param int $userId * @return \Illuminate\Http\Response */ public function addUserToEvent(Request $request, $userId) { try { $role = $request->get('role'); if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } $user = User::find($userId); $event = $request->get('event'); if (!$user || !$event) { return response([ 'status' => false, 'message' => 'User or event not found' ]); } // Check if user already in event $eventUser = getEventUser($event, $user); if ($eventUser) { return response([ 'status' => false, 'message' => 'User already in this event' ]); } // Add user to event as submitter $eventUser = $this->repository->attachUserToEvent($event, $user, 'event_submitter'); $eventUser->user_added_via = "Global Directory"; $eventUser->save(); return response([ 'status' => true, 'message' => 'User added to event successfully' ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * Get autocomplete suggestions for global search * * @param Request $request * @return \Illuminate\Http\Response */ public function getAutocompleteData(Request $request) { try { $role = $request->get('role'); if ($role != 'event_admin') { return response([ 'status' => false, 'message' => 'Access denied' ]); } $field = $request->get('field'); $query = $request->get('query', ''); if (!in_array($field, ['name', 'email', 'company'])) { return response([ 'status' => false, 'message' => 'Invalid field' ]); } $suggestions = $this->repository->getAutocompleteData($field, $query); return response([ 'status' => true, 'suggestions' => $suggestions ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } /** * Update user email for super admin * * @param Request $request * @return \Illuminate\Http\Response */ public function updateUserEmail(Request $request) { try { // Only allow super admin to access this endpoint $isSuperAdmin = DB::table('model_has_roles') ->join('roles', 'roles.id', '=', 'model_has_roles.role_id') ->where('model_has_roles.model_id', Auth::id()) ->where('model_has_roles.model_type', User::class) ->where('roles.name', 'super_admin') ->exists(); if (!$isSuperAdmin) { return response([ 'status' => false, 'message' => 'Access denied. Super admin only.' ], 403); } $validator = Validator::make($request->all(), [ 'id' => 'required|exists:users,id', 'current_email' => 'required|email', 'new_email' => 'required|email' ]); if ($validator->fails()) { return response([ 'status' => false, 'message' => 'Validation failed', 'errors' => $validator->errors() ], 422); } $user = User::find($request->id); // Check if current and new email are the same if ($request->current_email === $request->new_email) { return response([ 'status' => false, 'message' => 'Same email given' ], 422); } // Verify current email matches if ($user->email !== $request->current_email) { return response([ 'status' => false, 'message' => 'Current email does not match' ], 422); } // Check if new email already exists $existingUser = User::where('email', $request->new_email)->first(); if ($existingUser) { return response([ 'status' => false, 'message' => 'User already exists' ], 422); } // Update the email $user->email = $request->new_email; $user->save(); return response([ 'status' => true, 'message' => 'Email updated successfully', 'user' => $user ]); } catch (Exception $exception) { return $this->handleException($exception, __FUNCTION__, __CLASS__); } } }
Edit
Download
Unzip
Chmod
Delete