87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Backend;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Models\User;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use CodeIgniter\RESTful\ResourceController;
|
|
|
|
class UserRegisterController extends ResourceController
|
|
{
|
|
|
|
private $registerUser;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->registerUser = new User();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
//Create User Function
|
|
public function create()
|
|
{
|
|
$validationRules = [
|
|
// Register User Data
|
|
'username'=> 'required',
|
|
'name'=> 'required',
|
|
'password_hash' => 'required',
|
|
'role' => 'required',
|
|
'status' => 'required',
|
|
];
|
|
|
|
$validation = $this->validate($validationRules);
|
|
|
|
if (!$validation) {
|
|
return $this->failValidationErrors($this->validator->getErrors());
|
|
}
|
|
|
|
$registerUserData = [
|
|
'username' => $this->request->getVar('username'),
|
|
'name' => $this->request->getVar('name'),
|
|
'password_hash' => md5($this->request->getVar('password_hash')),
|
|
'role' => $this->request->getVar('role'),
|
|
'status' => $this->request->getVar('statuss'),
|
|
];
|
|
|
|
if ($registerUserData)
|
|
{
|
|
$id = $this->registerUser->insert($registerUserData);
|
|
|
|
if ($id) {
|
|
$result = [
|
|
'id' => $id,
|
|
'username' => $this->request->getVar('username'),
|
|
'name' => $this->request->getVar('name'),
|
|
'password_hash' => md5($this->request->getVar('password_hash')),
|
|
'role' => $this->request->getVar('role'),
|
|
'status' => $this->request->getVar('status'),
|
|
];
|
|
|
|
$name = $this->request->getVar('register_user_name');
|
|
// $cemail = $this->request->getVar('register_user_email');
|
|
|
|
$message = "Hello $name,<br><br>";
|
|
$message .= "Thank you for your registration! We have received your registration form. Please allow us up to <strong>12 working hours</strong> to process your request. Our staff members will reach out to you shortly.<br><br>";
|
|
$message .= "<br><br>Thank you,<br>US PIZZA Sdn. Bhd.";
|
|
$subject = "Registration Submission Confirmation";
|
|
|
|
// $emailSent = SendMail::sendMail($name, $cemail, $message, $subject);
|
|
|
|
// if ($emailSent) {
|
|
// return $this->respond(['status' => 200, 'message' => 'Register user created successfully and Email sent successfully.', 'result' => $result]);
|
|
// } else {
|
|
// return $this->respond(['status' => 500, 'message' => 'Failed to send email.']);
|
|
// }
|
|
|
|
return $this->respond(['status' => 200, 'message' => 'User created successfully.', 'result' => $result]);
|
|
}
|
|
return $this->respond(['status' => 400, 'message' => 'Sorry! No user created.']);
|
|
}
|
|
}
|
|
}
|