myLogger = \Config\Services::mylogger(); $this->employeeModel = new EmployeeModel(); $this->authHistoryModel = new AuthHistoryModel(); $this->hrModel = new LevelContactModel(); $this->hrAccessControlModel = new HRAccessControlModel(); } public function index() { $this->myLogger->logme('error','Rest Authentication function called'); $data =["id"=>"2", "role"=>"staff"]; print_r(JWTToken::encode($data)); } public function logined() { $this->myLogger->logme('error','Rest Authentication function called'); echo "Rest Authentication Logined Success........"; } public function verifyEmployeeWithMobileNumber() { try { $mobile_number = $this->request->getJSON()->mobile_number; $employeeData = $this->employeeModel->select('employees.relationship,EP.employee_id') ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner') ->where('employees.is_active', 1) ->where('employees.relationship', 'self') ->where('employees.emp_status !=', 'truncated') ->where('employees.mobile', $mobile_number) ->where('EP.is_active', 1) ->whereIn('EP.status', ['active', 'expired']) ->first(); if (isset($employeeData['employee_id'])) { $result = ['user_verification' => true ,'message' => "Verified Successfully"]; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { $result = ['user_verification' => false , 'message' => "User not found"]; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } public function verifyEmployeeWithEmailId() { try { $email = $this->request->getJSON()->email; $employeeData = $this->employeeModel->select(' employees.relationship, EP.employee_id, employees.client_id, employees.client_branch_id, employees.email_corporate ') ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner') ->where('employees.is_active', 1) ->where('employees.relationship', 'Self') ->where('employees.emp_status !=', 'truncated') ->where('employees.email_corporate', $email) ->where('EP.is_active', 1) ->whereIn('EP.status', ['active', 'expired']) ->first(); if (isset($employeeData['employee_id'])) { $otp = random_int(100000, 999999); $update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'Self') ->where('is_active', 1)->set(array('otp' => $otp)) ->update(); if ($update) { $common = [ 'client_id' => $employeeData['client_id'], 'client_branch_id' => $employeeData['client_branch_id'], 'client_policy_id' => null, 'employee_policy_id' => null, 'employee_id' => $employeeData['employee_id'], 'mail_type' => 'otp_mail', ]; $subject = 'Nhance user verification - OTP'; $mail_content = $otp . ' is your verification code for Nhance.'; $res = MailHelper::send_email(['mail' => $employeeData['email_corporate'], 'subject' => $subject, 'common' => $common, 'message' => $mail_content]); $this->myLogger->logme("info", $res); if (json_decode($res)->status == 'success') { $result = ['user_verification' => true, 'message' => "Verified Successfully"]; return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); } else { $result = ['user_verification' => false, 'message' => "Mail sending failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } else { $result = ['user_verification' => false, 'message' => "Verification failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } else { $result = ['user_verification' => false, 'message' => "User not found"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } catch (\Throwable $th) { return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); } } public function updateEmpOTP() { $email = $this->request->getJSON()->email; $otp = $this->request->getJSON()->otp; $this->employeeModel->where('email_corporate', $email)->where('relationship', 'Self') ->where('is_active', 1)->set(array('otp' => $otp)) ->update(); return true; } // public function updateEmpMPIN() // { // $requestData = $this->request->getJSON(); // print_r($requestData); die; // $mobile_number = $requestData->mobile_number ?? null; // $email_id = $requestData->email_id ?? null; // $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null; // $old_mpin = $requestData->old_mpin ?? null; // $is_mpin_skipped = $requestData->is_mpin_skipped ?? null; // $is_biometric_enabled = $requestData->is_biometric_enabled ?? null; // if (!$new_mpin) { // return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']); // } // $query = $this->employeeModel->where('relationship', 'self'); // if ($mobile_number) { // $query->where('mobile', $mobile_number); // } elseif ($email_id) { // $query->where('email_corporate', $email_id); // } else { // return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']); // } // if (!empty($old_mpin)) { // $query->where('mpin', $old_mpin); // } // // Fetch employee data // $employeeData = $query->first(); // if (!$employeeData) { // return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']); // } // if(!empty($is_mpin_skipped) && !empty($is_biometric_enabled)){ // $mpin_data_to_updata = [ // 'mpin' => $new_mpin, // 'is_mpin_skipped' => $is_mpin_skipped, // 'is_biometric_enabled' => $is_biometric_enabled // ]; // }else{ // $mpin_data_to_updata = ['mpin' => $new_mpin]; // } // // Update MPIN // $updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_updata); // return true; // } public function updateEmpMPIN() { try { log_message('info', 'MPIN update request received.'); $requestData = $this->request->getJSON(); log_message('debug', 'Request data: ' . json_encode($requestData)); $mobile_number = $requestData->mobile_number ?? null; $email_id = $requestData->email_id ?? null; $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null; $old_mpin = $requestData->old_mpin ?? null; $is_mpin_skipped = $requestData->is_mpin_skipped ?? null; $is_biometric_enabled = $requestData->is_biometric_enabled ?? null; if (!$new_mpin) { log_message('warning', 'MPIN is missing.'); return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']); } $query = $this->employeeModel->where('relationship', 'self'); log_message('info', 'Query initialized with relationship=self'); if ($mobile_number) { $query->where('mobile', $mobile_number); log_message('info', "Filtering by mobile number: {$mobile_number}"); } elseif ($email_id) { $query->where('email_corporate', $email_id); log_message('info', "Filtering by email ID: {$email_id}"); } else { log_message('warning', 'Neither mobile number nor email ID provided.'); return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']); } if (!empty($old_mpin)) { $query->where('mpin', $old_mpin); log_message('info', "Verifying old MPIN: {$old_mpin}"); } $employeeData = $query->first(); log_message('debug', 'Employee lookup result: ' . json_encode($employeeData)); if (!$employeeData) { log_message('warning', 'Employee not found or invalid old MPIN.'); return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']); } $mpin_data_to_update = ['mpin' => $new_mpin]; if ($is_mpin_skipped != null && $is_biometric_enabled != null) { $mpin_data_to_update['is_mpin_skipped'] = $is_mpin_skipped; $mpin_data_to_update['is_biometric_enabled'] = $is_biometric_enabled; log_message('info', 'Updating MPIN, MPIN skip flag, and biometric flag.'); } else { log_message('info', 'Updating MPIN only.'); } $updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_update); if ($updated) { log_message('info', "MPIN updated successfully for employee ID: {$employeeData['id']}"); return $this->response->setJSON([ 'status' => true, 'message' => 'MPIN updated successfully.' ]); } else { log_message('error', "Failed to update MPIN for employee ID: {$employeeData['id']}"); return $this->response->setJSON([ 'status' => false, 'message' => 'Failed to update MPIN.' ]); } } catch (\Exception $e) { log_message('critical', 'Exception in updateEmpMPIN: ' . $e->getMessage()); return $this->response->setJSON([ 'status' => false, 'message' => 'Unexpected error occurred.', 'error' => $e->getMessage() ]); } } public function getVerifiedUserData() { try { $otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null; $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; $otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; if (isset($this->request->getJSON()->login_by_hr)) { $employeeData = $this->employeeModel->where('id', $this->request->getJSON()->employee_id)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); }else{ if (isset($mobile_number)) { $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); } else { $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); } } if ($employeeData && $otp_verification == true || $employeeData && isset($this->request->getJSON()->login_by_hr) || $employeeData && isset($this->request->getJSON()->otp) ) { $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { $data = [ 'user_id' => $employeeData['id'], 'user_type' => 'employee', 'ip' => $auth['ip'], 'platform' => $auth['platform'], 'broswer' => $auth['browser'], ]; $this->authHistoryModel->insert($data); } $result = JWTToken::encode($employeeData); if(isset($this->request->getJSON()->otp)){ $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update(); } return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); } } public function verifyHrWithMobileNumber() { try { $mobile_number = $this->request->getJSON()->mobile_number; $HrData = $this->hrModel->where('mobile', $mobile_number) ->where('contact_type', 'client') ->where('is_active', 1) ->first(); if ($HrData) { $result = ['user_verification' => true ,'message' => "Verified Successfully"]; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { $result = ['user_verification' => false , 'message' => "User not found"]; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } public function verifyHrWithEmail() { try { $data = $this->request->getJSON(); $email = $data->email; $HrData = $this->hrModel->where('email', $email) ->where('contact_type', 'client') ->where('is_active', 1) ->first(); if ($HrData) { $otp = random_int(100000, 999999); $sql = " UPDATE level_contacts SET otp = ? WHERE email = ? AND contact_type = 'client' AND is_active = 1 "; $db = db_connect(); $update = $db->query($sql, [$otp, $email]); if($update) { $data->otp = $otp; $common = [ 'login_type' => 'HR login', 'login_email' => $email, 'mail_type' => 'otp_mail' ]; $subject = 'Nhance user verification - OTP'; $mail_content = $otp . ' is your verification code for Nhance.'; $res = MailHelper::send_email(['mail' => $email, 'subject' => $subject, 'common' => $common, 'message' => $mail_content]); $this->myLogger->logme("info", $res); if (json_decode($res)->status == 'success') { $result = ['user_verification' => true, 'message' => "Verified Successfully"]; return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); } else { $result = ['user_verification' => false, 'message' => "Mail sending failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } else { $result = ['user_verification' => false, 'message' => "Verification failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } else { $result = ['user_verification' => false, 'message' => "User not found"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } public function updateHROTP() { $email = $this->request->getJSON()->email; $otp = $this->request->getJSON()->otp; $this->hrModel->where('email', $email) ->where('contact_type', 'client') ->where('is_active', 1)->set(array('otp' => $otp)) ->update(); return true; } public function getVerifiedHrData() { try { // mobile number $otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null; $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; // email id $otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null; $email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : null; if (isset($mobile_number)) { $hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first(); }else{ $hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('otp', $otp)->first(); } if ($hrData && $otp_verification == true || $hrData && isset($this->request->getJSON()->otp) ) { $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { $data = [ 'user_id' => $hrData['id'], 'user_type' => 'hr', 'ip' => $auth['ip'], 'platform' => $auth['platform'], 'broswer' => $auth['browser'], ]; $this->authHistoryModel->insert($data); } if(isset($this->request->getJSON()->mobile_number)){ $hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id') ->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left') ->where('level_contacts.mobile', $mobile_number ) ->where('level_contacts.contact_type', 'client') ->find(); }else if(isset($this->request->getJSON()->otp)){ $this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update(); $hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id') ->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left') ->where('level_contacts.email', $email ) ->where('level_contacts.contact_type', 'client') ->find(); } $HRAccessData = $this->getHRAccessData( $hrData['0']['id'] , 'post_enrollment'); if(isset($HRAccessData['allowed_modules'])){ $hrData['0']['allowed_modules'] = json_decode($HRAccessData['allowed_modules'],true)['post']; }else{ $hrData['0']['allowed_modules'] = []; } $result = JWTToken::encode($hrData['0']); return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200); } else { return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP" ],200); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); } } public function getHRAccessData( $hr_id = null , $request_for = 'post_enrollment') { $hr_id = $this->request->getGet('hr_id') ?? $hr_id; $request_for = $this->request->getGet('request_for') ?? $request_for; if($request_for == 'pre_enrollment'){ $idField = 'pre_hr_id'; }else{ $idField = 'post_hr_id'; } $data = $this->hrAccessControlModel->where($idField , $hr_id)->where('is_active' , 1)->first(); if($request_for == 'post_enrollment'){ return $data ?? []; } return $this->respond(['status' => (($data) ? 'success' : 'failed'),'code' => (($data) ? 200 : 404),'data' => $data ], 200); } public function getUserIdFromToken() { $id = JWTToken::getUserIdFromToken(); // echo $id['id']; echo "Id----> "; print_r($id); $role = JWTToken::getUserRoleFromToken(); echo " Role----> "; echo $role; $tokenArray = JWTToken::decodeToken(); echo " TokenArray----> "; print_r($tokenArray); } public function saveMpin() { try { $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; if (isset($mobile_number)) { $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); } else { $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); } $mpin = $this->request->getJSON()->mpin; $is_mpin_skipped = $this->request->getJSON()->is_mpin_skipped; $is_biometric_enabled = $this->request->getJSON()->is_biometric_enabled; $mpin_data_to_updata = [ 'mpin' => $mpin, 'is_mpin_skipped' => $is_mpin_skipped, 'is_biometric_enabled' => $is_biometric_enabled ]; if ($employeeData) { $id= $employeeData["id"]; $updateMpin = $this->employeeModel->where('id', $id)->set( $mpin_data_to_updata)->update(); if($updateMpin){ $result = ['user_verification' => true , 'message' => "Mpin Updated"]; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); }else{ $result = ['user_verification' => true , 'message' => "Mpin Not Updated"]; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); } } else { $result = ['user_verification' => false , 'message' => "User not found"]; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } public function updateMpin() { try { $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; $old_mpin = $this->request->getJSON()->old_mpin; $mpin = $this->request->getJSON()->new_mpin; if (isset($mobile_number)) { $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); }else{ $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); } if ($employeeData) { $id= $employeeData["id"]; $updateMpin = $this->employeeModel->where('id', $id)->set('mpin', $mpin)->update(); if($updateMpin){ $result = ['mpin_verification' => true , 'message' => "Mpin Updated"]; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); }else{ $result = ['mpin_verification' => true , 'message' => "Mpin Not Updated"]; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); } } else { $result = ['mpin_verification' => false , 'message' => "Wrong Mpin"]; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } public function verifyMpin() { try { $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; $mpin = $this->request->getJSON()->mpin; if (isset($mobile_number)) { $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); }else{ $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); } if ($employeeData && $mpin == $employeeData["mpin"]) { $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { $data = [ 'user_id' => $employeeData['id'], 'user_type' => 'employee', 'ip' => $auth['ip'], 'platform' => $auth['platform'], 'broswer' => $auth['browser'], ]; $authdata= $this->authHistoryModel->insert($data); } $result = JWTToken::encode($employeeData); // $result = $employeeData; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); } } public function checkMpin() { try { $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; // $mpin = $this->request->getJSON()->mpin; if (isset($mobile_number)) { $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); }else{ $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); } if ($employeeData && $employeeData["mpin"] != null) { return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist" , 'Mpin' =>$employeeData["mpin"], 'is_mpin_skipped' => $employeeData['is_mpin_skipped'], 'is_biometric_enabled' => $employeeData['is_biometric_enabled']],200); } else { return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); } } public function forgotMPIN() { try { log_message('info', 'forgotMPIN() called.'); $json = $this->request->getJSON(); $mobile_number = $json->mobile_number ?? null; $email_id = $json->email_id ?? null; log_message('info', 'Received input - Mobile: ' . var_export($mobile_number, true) . ', Email: ' . var_export($email_id, true)); // Step 1: Check input if (!$mobile_number && !$email_id) { log_message('error', 'Mobile number and email ID are both missing.'); return $this->respond([ 'status' => 'failed', 'code' => 400, 'message' => 'Mobile number or email ID is required.' ], 400); } // Step 2: Fetch employee data if ($mobile_number) { log_message('info', 'Looking up employee by mobile number: ' . $mobile_number); $employeeData = $this->employeeModel ->where('mobile', $mobile_number) ->where('relationship', 'self') ->first(); } else { log_message('info', 'Looking up employee by email: ' . $email_id); $employeeData = $this->employeeModel ->where('email_corporate', $email_id) ->where('relationship', 'self') ->first(); } // Step 3: Found employee if (!empty($employeeData)) { log_message('info', 'Employee found: ID = ' . $employeeData['id']); $updateData = [ 'mpin' => null, 'is_mpin_skipped' => null, 'is_biometric_enabled' => null ]; log_message('info', 'Updating employee MPIN fields to null for ID: ' . $employeeData['id']); $updated = $this->employeeModel ->where('id', $employeeData['id']) ->set($updateData) ->update(); if ($updated) { log_message('info', 'MPIN reset successful for employee ID: ' . $employeeData['id']); return $this->respond([ 'status' => 'success', 'code' => 200, 'message' => 'MPIN reset successfully.' ], 200); } else { log_message('error', 'Failed to update MPIN fields for employee ID: ' . $employeeData['id']); return $this->respond([ 'status' => 'failed', 'code' => 500, 'message' => 'Could not reset MPIN values.', ], 500); } } else { // Step 4: Not found in local DB — call external fallback log_message('warning', 'Employee not found locally. Falling back to third-party API.'); return $this->respond(['status' => 'failed','code' => 404,'data' => "Employee not found"],200); } } catch (\Throwable $e) { log_message('error', 'Exception in forgotMPIN(): ' . $e->getMessage()); return $this->respond([ 'status' => 'failed', 'code' => 500, 'message' => 'Server error: ' . $e->getMessage() ], 500); } } // TokenController.php public function bookstackLoginToken() { $session = \Config\Services::session(); $user_data = session()->get('userData'); $user = $user_data->email; $secret = getenv('bookstack.token'); // $user = 'staff@staff.com'; $name = $user_data->first_name ?? 'User'; $payload = [ 'email' => $user, 'name' => $name, 'exp' => time() + (60 * 60 * 24) // expires in 1 day ]; // dd($payload); $token = base64_encode(json_encode($payload)); $signature = hash_hmac('sha256', $token, $secret); $bookStackUrl = getenv('bookstack.baseURL'); $url = $bookStackUrl . urlencode($token) . '&sig=' . $signature; return redirect()->to($url); } }