CHANGE_BUSINESS_MAIL_CONFIG_TEST : AADHAVAN

This commit is contained in:
aadhavan valli 2024-07-15 16:29:14 +05:30
parent 6798357556
commit 2fb8c3fd78
6 changed files with 173 additions and 77 deletions

View File

@ -6,6 +6,8 @@ use CodeIgniter\Router\RouteCollection;
* @var RouteCollection $routes
*/
$routes->post('/check_mail_config','BusinessController::check_mail_config');
$routes->get('/set_business_in_session/(:num)','StaffController::set_business_in_session/$1');
// $routes->get('/home','Home::index');

View File

@ -5,6 +5,7 @@ namespace App\Controllers;
use App\Models\BusinessModel;
use App\Models\BranchModel;
use App\Models\StaffModel;
use App\Helpers\MailHelper;
use CodeIgniter\API\ResponseTrait;
@ -168,4 +169,17 @@ class BusinessController extends BaseController
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
}
}
public function check_mail_config()
{
try {
$mail_config = $this->request->getPost();
$r_mail = $this->request->getPost('r_email');
$MailHelper = new MailHelper();
print_r($MailHelper->check_mail_config($r_mail, $mail_config));die;
} catch (\Exception $exception) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
}
}
}

View File

@ -319,17 +319,22 @@ class StaffController extends BaseController
echo true;
}else{
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
$business_list = [];
foreach (json_decode($staffdata->business_id) as $key => $value) {
$business = $this->BusinessModel->where('business_id', $value)->first();
if ($business) {
$business_list[] = $business;
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
$business_list = [];
if($staffdata->role == 'Admin'){
$business_list = $this->BusinessModel->findAll();
}else{
foreach (json_decode($staffdata->business_id) as $key => $value) {
$business = $this->BusinessModel->where('business_id', $value)->first();
if ($business) {
$business_list[] = $business;
}
}
}
}
echo view('layout/header', ['Data'=>$staffdata]);
echo view('staff_profile',['staff'=>$staffdata, 'business_list'=> $business_list]);
echo view('layout/footer');
echo view('layout/header', ['Data'=>$staffdata]);
echo view('staff_profile',['staff'=>$staffdata, 'business_list'=> $business_list]);
echo view('layout/footer');
}
}
public function change_staff_password($staff_id)

View File

@ -96,5 +96,46 @@ class MailHelper
// }
}
public static function check_mail_config($r_email, $mail_config = [])
{
$default_config = [
'protocol' => 'smtp',
'SMTPHost' => 'mail.venbait.in',
'SMTPUser' => 'bbone@venbait.in',
'SMTPPass' => 'xk!L(N_-R#};',
'SMTPPort' => 465,
'mailType' => 'html',
'sender_email' => 'bbone@venbait.in',
'sender_name' => 'BB-Sign'
];
// Merge default config with provided config
$config = array_merge($default_config, $mail_config);
$email = \Config\Services::email();
$email->initialize([
'protocol' => $config['protocol'],
'SMTPHost' => $config['SMTPHost'],
'SMTPUser' => $config['SMTPUser'],
'SMTPPass' => $config['SMTPPass'],
'SMTPPort' => (int)$config['SMTPPort'],
'mailType' => $config['mailType']
]);
$email->setFrom($config['sender_email'], "Sender Name");
$email->setTo($r_email);
$email->setSubject("Test Mail Configuration");
$email->setMessage("Test Mail Configuration");
if ($email->send()) {
return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $r_email]);
} else {
log_message('error', 'Email sending failed: ' . $email->printDebugger(['headers']));
return ['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $r_email];
}
}
}
?>

View File

@ -54,7 +54,7 @@
</div>
</div>
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-bell mr-1"></i> Mail Settings</h5>
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-envelope mr-1"></i> Mail Settings</h5>
<div class="form-row">
<div class="form-group col-md-6">
<label for="subject-input">Email</label>
@ -76,16 +76,34 @@
<label for="subject-input">Port</label>
<input type="text" id="port" class="form-control" value="<?= isset($business['smtp_port']) ? $business['smtp_port'] : '' ?>">
</div>
</div>
<?php if(!isset($business['business_id'])){ ?>
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-bell mr-1"></i>Test Mail</h5>
<div class="form-row" id="test_mail_config_div">
<div class="form-group col-md-6">
<label for="">Test Config Mail</label>
<input type="mail" class="form-control" id="r_email">
</div>
<?php }else{ ?>
<div class="form-row">
<div class="form-group col-md-6">
<!-- <label for="">Test Config Mail</label> -->
<!-- <input type="mail" class="form-control" id="r_email"> -->
</div>
<?php } ?>
</div>
</form>
<input type="hidden" id="business_id" name="business_id" value="<?= isset($business['business_id']) ? $business['business_id'] : '' ?>">
<input type="hidden" id="header_html" value='<?= isset($business['business_id']) ? $business['header_html'] : '' ?>'>
<input type="hidden" id="footer_html" value='<?= isset($business['business_id']) ? $business['footer_html'] : '' ?>'>
<button type="submit" id="savedata" class="btn btn-primary">Submit</button>
<input type="hidden" id="footer_html" value='<?= isset($business['business_id']) ? $business['footer_html'] : '' ?>'>
<?php if(isset($business['business_id'])){?>
<button type="submit" id="savedata" class="btn btn-primary">Submit</button>
<?php }else{ ?>
<button class="btn btn-primary" id="test-email-btn" type="button">Test Email</button>
<button type="submit" id="savedata" class="btn btn-primary" style="display:none;">Submit</button>
<?php } ?>
</div>
</div> <!-- end card -->
</div>
@ -148,65 +166,81 @@ $(document).ready(function() {
});
$("#savedata").on("click", function()
{
var headerContent = $('#summernote-header').summernote('code');
var footerContent = $('#summernote-footer').summernote('code');
formData ={
business_id : $('#business_id').val(),
business_name : $('#business_name').val(),
header_html : headerContent,
footer_html : footerContent,
email : $('#email').val(),
smtp_host : $('#host').val(),
smtp_user : $('#user_name').val(),
smtp_pass : $('#password').val(),
smtp_port : $('#port').val(),
};
console.log(formData);
$.ajax({
url: '<?= base_url()."add_business"; ?>',
type: 'POST',
data: formData,
json: true,
success: function(response) {
if(response.success){
toastr.success('Data saved successfully ', 'Success');
window.location.href = '<?= base_url()."business_list"; ?>';
$("#test-email-btn").on("click", function()
{
formData ={
sender_email : $('#email').val(),
r_email : $('#r_email').val(),
smtp_host : $('#host').val(),
smtp_user : $('#user_name').val(),
smtp_pass : $('#password').val(),
smtp_port : $('#port').val(),
};
// console.log(formData);
$.ajax({
url: '<?= base_url()."check_mail_config"; ?>',
type: 'POST',
data: formData,
json: true,
success: function(response) {
}else{
toastr.warning('Something went wrong', 'Warning');
}
},
error: function(xhr, status, error) {
// Handle errors here
console.error(xhr.responseText);
}
console.log(JSON.parse(response));
if(JSON.parse(response).status == 'success'){
$('#savedata').css('display','');
$('#test-email-btn').css('display','none');
toastr.success('Data saved successfully ', 'Success');
// window.location.href = '<?= base_url()."business_list"; ?>';
}else{
toastr.warning('Something went wrong', 'Warning');
}
},
error: function(xhr, status, error) {
// Handle errors here
console.error(xhr.responseText);
}
});
})
$("#savedata").on("click", function()
{
var headerContent = $('#summernote-header').summernote('code');
var footerContent = $('#summernote-footer').summernote('code');
formData ={
business_id : $('#business_id').val(),
business_name : $('#business_name').val(),
header_html : headerContent,
footer_html : footerContent,
email : $('#email').val(),
smtp_host : $('#host').val(),
smtp_user : $('#user_name').val(),
smtp_pass : $('#password').val(),
smtp_port : $('#port').val(),
};
$.ajax({
url: '<?= base_url()."add_business"; ?>',
type: 'POST',
data: formData,
json: true,
success: function(response) {
if(response.success){
toastr.success('Data saved successfully ', 'Success');
window.location.href = '<?= base_url()."business_list"; ?>';
}else{
toastr.warning('Something went wrong', 'Warning');
}
},
error: function(xhr, status, error) {
// Handle errors here
console.error(xhr.responseText);
}
});
});
});
</script>

View File

@ -242,11 +242,11 @@
$.getJSON('https://api.ipify.org?format=json', function(data) {
var clientIp = data.ip;
var formData ={
otp : $('#otp').val(),
doc_id : $('#doc_id').val(),
is_approved: 1,
clientIp : clientIp
}
otp : $('#otp').val(),
doc_id : $('#doc_id').val(),
is_approved: 1,
clientIp : clientIp
}
$.ajax({
type: 'POST',
url: '<?php echo base_url()."doc_verify_otp"?>',