WapTrick360


Share Your Creativity For Wapka
Home » Wapmaster codes » [LUA] New user registration code
-- Checks if a continue URL has been defined. If not, it is defined as the Home page
continue = req.get.continue or "/"

-- Check if the user is already logged in. If yes, redirect to continue URL
if (env.userid ~= 0) then 
    url.redirect(continue)
end


-- Checks if the register form has been submitted
if (req.method == "POST" and req.post.process_register) then

    error_message = nil -- Starts error message as null

    email    = req.post.email    -- Gets the email from the POST request
    username = req.post.username -- Gets the username from the POST request
    password = req.post.password -- Gets the password from the POST request
    fullname = req.post.fullname -- Gets the full name as extra data to define a profile variable

    -- Checking whether the fields have been filled in
    if (email    == "" and
        username == "" and
        password == "" and
        fullname == "") then
        error_message = "You must enter all the fields."

    elseif (email    == "") then
        error_message = "You must enter your email."

    elseif (username == "") then
        error_message = "You must enter your username."

    elseif (username == "") then
        error_message = "You must enter your password."

    elseif (fullname == "") then
        error_message = "You must enter your full name."

    -- Continuing if all fields have been filled in
    else
        -- Sets the parameters for the API register method
        local param = {
            email    = email,
            username = username,
            password = password,
            var      = {
                fullname = fullname -- Sets the full name as a custom variable!
            }
        }
        local is_ok, register, info, error_register = api.user_create(param)

        -- Checks whether the registration was successful
        if (is_ok) then
            url.redirect(continue)

        else -- An error occurred while trying to register
            error_message = error_register -- Defines the error message as the one received in the register method
        end
    end

    -- Checks if any errors occurred and sets an error message div to display on the page
    if (error_message) then
        html_error = [=[<div class="error-message">%s</div>]=]
        error_message = string.format(html_error, error_message)
    end
end


local html_code = [=[
<h2>Register an account</h2>
%s <!-- This is where the error message will be -->

<form method="post">

<div class="input">
<label for="email">Email:</label><br>
<input type="email" name="email" value="%s" placeholder="Email" id="email">
</div>

<div class="input">
<label for="username">Username:</label><br>
<input type="text" name="username" value="%s" placeholder="Username" id="username">
</div>

<div class="input">
<label for="password">Password:</label><br>
<input type="password" name="password" value="%s" placeholder="Password" id="password">
</div>

<div class="input">
<label for="fullname">Fullname:</label><br>
<input type="text" name="fullname" value="%s" placeholder="Full name" id="fullname">
</div>

<div class="input-button">
<input type="submit" name="process_register" value="Register" class="input-button">
</div>

</form>

<div class="register-message">
Already have an account? <a href="/login">Login</a>
</div>
]=]

print(string.format(html_code, error_message or "", email or "", username or "", password or "", fullname or ""))



Total likes [3] admin , waptrick360 and AVENGER
For comment section please Login Or Registration Here
Recent Comments
There are no comments yet
2025 WapTrick360
Version 2.0