Hi, guest!
More
Chat
If you get an error during the chat, please Reload the page !
Simple login page code using Lua scripting
<div class="content">Hello! I would like to share a simple code for a login page using Lua scripting. You are free to style the HTML codes however you want.<br> The code can be a little challenging to understand at first, but feel free to ask if you don't understand any part.<br> See also: <a href="https://forum.wapka.org/viewtopic.php?t=2057" class="postlink">Simple register page code using Lua scripting</a><br> <br> How to use it: <ol style="list-style-type:decimal"> <li>Log in to the Wapka Dashboard (<a href="https://web.wapka.org/dashboard" class="postlink">https://web.wapka.org/dashboard</a>);</li> <li>Select your website from the "Your services" list;</li> <li>Now create a new page called "login" (Basic Function &gt; New Page) - you can skip this step if you already have a login page and want to use it.</li> <li>Now open the login page we created and go to Advanced function &gt; Script, and finally paste the following Lua code into the textarea:</li> </ol> <div class="codebox"><p>Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>if (env.userid ~= 0) then -- Check if the user is already logged in

url.redirect("/") -- If yes, redirect to the main page end if (req.method == "POST") then -- Checks if the login form has been submitted

error_message = nil -- Starts error message as null

username = req.post.username -- Gets the username from the POST request

password = req.post.password -- Gets the password from the POST request

continue = req.get.continue -- Useful if the user came from another page

if continue == nil then continue = "/" end -- Checks if a continue URL has been defined, if not, it is defined as the home page

if (username == "" and password == "") then -- Checks if the username and password are empty



error_message = "You must enter your username and password."

elseif (username == "") then -- Checks if username is empty



error_message = "You must enter your username."

elseif (password == "") then -- Checks if password is empty



error_message = "You must enter your password."

else -- Continue with login if username and password have been filled in



local param = { -- Sets the parameters for the API login method





username = username,





password = password



}



local is_ok, login, info, error_login = api.user_login(param)



if (is_ok) then -- Username and password are correct and login was successful





url.redirect(continue) -- Redirects to the destination defined in continue



else -- An error occurred while trying to login





error_message = error_login -- defines the error message as the one received in the login method



end

end

if (error_message) then -- Checks if any errors occurred and sets an error message div to display on the page



html_error = [=[&lt;div class="error-message"&gt;%s&lt;/div&gt;]=]



error_message = string.format(html_error, error_message)

end end local html_code = [=[ &lt;h2&gt;Log-in to your account&lt;/h2&gt; %s &lt;!-- This is where the error message will be --&gt; &lt;form method="post"&gt; &lt;div class="input"&gt; &lt;label for="username"&gt;Username:&lt;/label&gt;&lt;br&gt; &lt;input type="text" name="username" value="%s" placeholder="Username" id="username"&gt; &lt;/div&gt; &lt;div class="input"&gt; &lt;label for="password"&gt;Password:&lt;/label&gt;&lt;br&gt; &lt;input type="password" name="password" value="%s" placeholder="Password" id="password"&gt; &lt;/div&gt; &lt;div class="input-button"&gt; &lt;input type="submit" class="input-button" value="Login"&gt; &lt;/div&gt; &lt;/form&gt; &lt;div class="register-message"&gt; Not registered yet? &lt;a href="/register"&gt;Register&lt;/a&gt; &lt;/div&gt; ]=] print(string.format(html_code, error_message or "", username or "", password or "")) </code></pre></div></div> <div class="notice"> Credit - <a href="/view/135624?q=francisco&id=135624&uid=135624" class="username">francisco</a> </div>
comment
Media Post - Mobile Friendly
Panel Mode1653456113
webmash Published on 2022-05-25 05:21:53 4 years ago
comment
Media Post - Mobile Friendly
sajeevscg Published on 2022-05-12 04:40:53 4 years ago
comment
Mobile Friendly Post Widget
I need updates code of like this site
L Like the above image... Please, thank you.
comment
Mobile Friendly Post Widget
News Feed
Yahaan jaen.. 👉 www.ifunwap.cf
comment
Mobile Friendly Post Widget
News Feed
How to use cookies in Wapka ? :COOCKIE(name); ??
comment
Mobile Friendly Post Widget
Profile Page Code of Forum.wapka.org
I need a profile page code like forum.wapka.org where user can change or update avatar.
comment
Mobile Friendly Post Widget
How To Set User Avatar On Wapka
Hello. I am new to wapka, and I just found this forum. I need help, in user profile setup during registration or editing profile. What is the configuration code to set user profile picture or avatar.
comment
Mobile Friendly Post Widget
News Feed
how to save last search into data api and delete it after 50 search data saved
comment
Mobile Friendly Post Widget
News Feed
domain .tk don't active add domain wapka.org =(. doing can't add domain .tk =(
comment
Mobile Friendly Post Widget
News Feed
comment
Mobile Friendly Post Widget
News Feed
ifunwap.cf
comment
Mobile Friendly Post Widget
News Feed
how can i add a .com .net domain to my website ? https://mysite.com => https://mysite.wapka.site?
comment
News Feed News Feed [ ] (hypesloaded)
News Feed News Feed [ ] (itshenry002)
News Feed News Feed [ ] (hypesloaded)
Category
Statistics
Total posts 839 •Total Files 172 •Total members 393 •Our newest member weefewfwe4w