403Webshell
Server IP : 158.247.231.215  /  Your IP : 216.73.217.83
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux CTMS 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User : www-data ( 33)
PHP Version : 8.0.30
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /mnt/blockstorage/ctms/api/custom-api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /mnt/blockstorage/ctms/api/custom-api/user-register.php
<?php
/**
 * User Registration API
 * POST /api/custom-api/user-register.php
 * Body: {username, email, password}
 */

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Authorization");
header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit();
}

// Load WordPress
require_once('/mnt/blockstorage/ctms/wp-load.php');
require_once('auth-helper.php');

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    send_error_response('Only POST requests are allowed', 405);
}

// Get POST data
$input = file_get_contents('php://input');
$data = json_decode($input, true);

if (!$data) {
    $data = $_POST;
}

$username = isset($data['username']) ? sanitize_user($data['username']) : '';
$email = isset($data['email']) ? sanitize_email($data['email']) : '';
$password = isset($data['password']) ? $data['password'] : '';

// Validation
if (empty($username) || empty($email) || empty($password)) {
    send_error_response('Username, email, and password are required', 400);
}

if (!is_email($email)) {
    send_error_response('Invalid email address', 400);
}

if (username_exists($username)) {
    send_error_response('Username already exists', 400);
}

if (email_exists($email)) {
    send_error_response('Email already exists', 400);
}

if (strlen($password) < 6) {
    send_error_response('Password must be at least 6 characters', 400);
}

// Create user
$user_id = wp_create_user($username, $password, $email);

if (is_wp_error($user_id)) {
    send_error_response($user_id->get_error_message(), 500);
}

$user = get_user_by('id', $user_id);
wp_set_current_user($user_id);

// Try to get JWT token
$token = null;
if (function_exists('rest_do_request')) {
    $token_request = new WP_REST_Request('POST', '/jwt-auth/v1/token');
    $token_request->set_param('username', $username);
    $token_request->set_param('password', $password);
    $token_response = rest_do_request($token_request);

    if (!$token_response->is_error()) {
        $token_data = $token_response->get_data();
        $token = isset($token_data['token']) ? $token_data['token'] : null;
    }
}

$response = array(
    'success' => true,
    'message' => $token ? 'User created and logged in successfully' : 'User created successfully',
    'user_id' => $user_id,
    'username' => $username,
    'email' => $email,
);

if ($token) {
    $response['token'] = $token;
}

send_json_response($response, 201);
?>

Youez - 2016 - github.com/yon3zu
LinuXploit