Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2020-05-03, 08:47


NiczeQ







Wiek: 28
Na forum: 2752 dni
Posty: 2



Respekt: 40

Witajcie,

Mam logowanie, kt?re jest pod ACL a chcia?bym aby by?o pod pysa lub baze danych SQL.

Server.lua

function PlayerLogin(username, password, checksave)
    if not (username == "") then
        if not (password == "") then
            local account = getAccount ( username, password )
            if ( account ~= false ) then
                if checksave == true then
                    triggerClientEvent(source, "saveLoginToXML", getRootElement(), username, password)
                else
                    triggerClientEvent(source, "resetSaveXML", getRootElement(), username, password)
                end
                local chek = logIn(source, account, password)
                if chek then 
                    triggerClientEvent(source, "setLoginPanelVisible", getRootElement(), false)
                else
                    triggerClientEvent(source, "showWarning", getRootElement(), 1, false, "Konto jest ju? zarejestrowane.")
                end
            else
                triggerClientEvent(source, "showWarning", getRootElement(), 1, false, "B??d! Niepoprawne has?o lub login.")
                triggerClientEvent(source, "showWarning", getRootElement(), 2, false, "B??d! Niepoprawne has?o lub login.")
            end
        else
            triggerClientEvent(source, "showWarning", getRootElement(), 2, false, "Wpisz has?o")
        end
    else    
        triggerClientEvent(source, "showWarning", getRootElement(), 1, false, "    Wpisz login")

    end
end
addEvent("onRequestLogin", true)
addEventHandler("onRequestLogin", getRootElement(), PlayerLogin)

function outputChatBox (msg, pl)
exports.dpChat:message (pl, "global", msg)
end

function registerPlayer(username, email, password)
    if not (username == "") then
        if not (password == "") then
            if not (email == "") then
                local account = getAccount (username, password)
                if (account == false) then
                    if getEmailFromAllAccount(email) then
                        local accountID = #getAccounts() + 1
                        local accountAdded = addAccount(tostring(username),tostring(password))
                        if (accountAdded) then
                            triggerEvent("rmta_save.createNewAccount", root, accountAdded, accountID, email)
                            triggerClientEvent(source, "onAccountCreate", getRootElement())
                        else
                            triggerClientEvent(source, "showWarning", getRootElement(), 3, false, "Wypr?buj inne dane")
                            triggerClientEvent(source, "showWarning", getRootElement(), 4, false, "Wypr?buj inne dane")
                            triggerClientEvent(source, "showWarning", getRootElement(), 5, false, "Wypr?buj inne dane")
                        end
                    else
                        triggerClientEvent(source, "showWarning", getRootElement(), 4, false, "Ten e-mail jest ju? w u?yciu")
                
                    end
                else
                    triggerClientEvent(source, "showWarning", getRootElement(), 3, false, "Ten login jest w u?yciu")
                end
            else
                triggerClientEvent(source, "showWarning", getRootElement(), 4, false, "Wpisz email, przyk?ad: [email protected]")
            end
        else
            triggerClientEvent(source, "showWarning", getRootElement(), 5, false, "Wpisz has?o")
        end
    else
        triggerClientEvent(source, "showWarning", getRootElement(), 3, false, "Wpisz login")
    end
end
addEvent("onRequestRegister",true)
addEventHandler("onRequestRegister",getRootElement(),registerPlayer)

function getEmailFromAllAccount(email) 
    local accountTable = getAccounts ()
    for _, account in ipairs(accountTable) do
        if getAccountData(account, "account.email") == email then 
            return false 
        end
    end
    return true
end

function loggedOut()
    cancelEvent()
end
addEventHandler("onPlayerLogout",getRootElement(),loggedOut)


Login.lua

local screenX, screenY = guiGetScreenSize()

login = {}

login.font = {
    ["RB"] = guiCreateFont("RB.ttf", 12),
    ["RL"] = guiCreateFont("RL.ttf", 11),
    ["RR"] = guiCreateFont("RR.ttf", 10),
    ["chek_r"] = guiCreateFont("RR.ttf", 10),
    ["chek_b"] = guiCreateFont("RB.ttf", 10),
    ["RL_warning"] = guiCreateFont("RL.ttf", 10),
    ["RR_editbox"] = guiCreateFont("RR.ttf", 12)
}

function outputChatBox (msg, pl)
exports.dpChat:message (pl, "global", msg)
end

login.back_ground1 = guiCreateStaticImage(0, 0, screenX, screenY, "assets/main.png", false)
login.back_ground = guiCreateStaticImage(screenX/2-600/2, screenY/2-360/2, 600, 360, "assets/bg.png", false,login.back_ground1)
--login.logo = guiCreateStaticImage(0, 0, 240, 360, "assets/logo.png", false, login.back_ground)

login.label_nickname = guiCreateLabel(290, 30, 100, 20, "LOGIN", false, login.back_ground)
guiSetFont(login.label_nickname, login.font["RB"] )
guiLabelSetColor(login.label_nickname, 153, 156, 175)
createEditBox(1, 290, 50, "", login.back_ground, false)

login.label_password = guiCreateLabel(290, 100, 100, 20, "HAS?O", false, login.back_ground)
guiSetFont(login.label_password, login.font["RB"] )
guiLabelSetColor(login.label_password, 153, 156, 175)
createEditBox(2, 290, 120, "", login.back_ground, true)

login.button_login = guiCreateStaticImage(280, 200, 280, 50, "assets/button_login.png", false, login.back_ground)

login.label_first = guiCreateLabel(340, 260, 200, 20, "Nie posiadasz konta?", false, login.back_ground)
guiSetFont(login.label_first, login.font["RL"] )
guiLabelSetColor(login.label_first, 153, 156, 175)

guiCreateStaticImage(415, 290, 15, 10, "assets/iarrow.png", false, login.back_ground)
login.button_reg = guiCreateLabel(375, 310, 100, 20, "Zarejestruj", false, login.back_ground)
guiSetFont(login.button_reg, login.font["RB"] )
guiLabelSetColor(login.button_reg, 153, 156, 175)

createChekBox(1, 290, 170, login.back_ground)
login.label_chek = guiCreateLabel(310, 170, 200, 20, "Zapami?taj!", false, login.back_ground)
guiSetFont(login.label_chek, login.font["chek_r"] )
guiLabelSetColor(login.label_chek, 153, 156, 175)
--login.label_chek_two = guiCreateLabel(385, 170, 200, 20, "никнейм и пароль", false, login.back_ground)
--guiSetFont(login.label_chek_two, login.font["chek_b"] )
--guiLabelSetColor(login.label_chek_two, 255, 185, 41)

guiSetVisible(login.back_ground, false)
guiSetVisible(login.back_ground1, false)

addEventHandler("onClientMouseEnter", getRootElement(), function()
    if (source == login.button_reg) then
        guiLabelSetColor(login.button_reg, 255, 185, 41)
    elseif (source == login.button_login) then
        guiStaticImageLoadImage(source, "assets/button_login_a.png")
    end
end)
    
addEventHandler("onClientMouseLeave", getRootElement(), function()
    if (source == login.button_reg) then
        guiLabelSetColor(login.button_reg, 153, 156, 175)
    elseif (source == login.button_login) then
        guiStaticImageLoadImage(source, "assets/button_login.png")
    end
end)

addEventHandler ("onClientGUIClick", getRootElement(), function(button)
    if button == "left" then
        if source == login.button_login then
            triggerServerEvent("onRequestLogin", getLocalPlayer(), editBox[1].text, editBox[2].text, chekBox[1].active)
        elseif source == login.button_reg then
            guiSetVisible(login.back_ground, false)
            guiSetVisible(reg.back_ground, true)
        end
    end 
end)

local function showWarning(id, chek, message)
    setEditBoxWarning(id, message, chek)
end
addEvent("showWarning", true)
addEventHandler("showWarning", getRootElement(), showWarning)


state = true
guiSetVisible(login.back_ground, state)
guiSetVisible(login.back_ground1, state)
local sound = playSound("assets/loading.mp3") --Play wasted.mp3 from the sounds folder
setSoundVolume(sound, 0.3) -- set the sound volume to 50%
showCursor(state)

function onSoundStopped ( reason )
    if ( reason == "finished" ) and source == sound then
        sound = playSound("assets/loading.mp3")
        setSoundVolume(sound, 0.3)
    end
end
addEventHandler ( "onClientSoundStopped", getRootElement(), onSoundStopped )

local function loginPanelVisible(state) 
    guiSetVisible(login.back_ground, state)
    guiSetVisible(login.back_ground1, state)
    if state == false then
        stopSound(sound)
    end
    showCursor(state)
end
addEvent ("setLoginPanelVisible", true)
addEventHandler ( "setLoginPanelVisible", getRootElement(), loginPanelVisible)

-- Загрузка данных
function loadLoginFromXML() --Загрузка логина и пароля из XML
    local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml")
    if not xml_save_log_File then
        xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login")
    end
    local usernameNode = xmlFindChild (xml_save_log_File, "username", 0)
    local passwordNode = xmlFindChild (xml_save_log_File, "password", 0)
    if usernameNode and passwordNode then
        return xmlNodeGetValue(usernameNode), xmlNodeGetValue(passwordNode)
    else
        return "", ""
    end
    xmlUnloadFile ( xml_save_log_File )
end

function saveLoginToXML(username, password) --Сохрание логина и пароля в XML
    local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml")
    if not xml_save_log_File then
        xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login")
    end
    if (username ~= "") then
        local usernameNode = xmlFindChild (xml_save_log_File, "username", 0)
        if not usernameNode then
            usernameNode = xmlCreateChild(xml_save_log_File, "username")
        end
        xmlNodeSetValue (usernameNode, tostring(username))
    end
    if (password ~= "") then
        local passwordNode = xmlFindChild (xml_save_log_File, "password", 0)
        if not passwordNode then
            passwordNode = xmlCreateChild(xml_save_log_File, "password")
        end        
        xmlNodeSetValue (passwordNode, tostring(password))
    end
    xmlSaveFile(xml_save_log_File)
    xmlUnloadFile (xml_save_log_File)
end
addEvent("saveLoginToXML", true)
addEventHandler("saveLoginToXML", getRootElement(), saveLoginToXML)

function resetSaveXML() --Сохрание логина и пароля в XML
    local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml")
    if not xml_save_log_File then
        xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login")
    end
    if (username ~= "") then
        local usernameNode = xmlFindChild (xml_save_log_File, "username", 0)
        if not usernameNode then
            usernameNode = xmlCreateChild(xml_save_log_File, "username")
        end
    end
    if (password ~= "") then
        local passwordNode = xmlFindChild (xml_save_log_File, "password", 0)
        if not passwordNode then
            passwordNode = xmlCreateChild(xml_save_log_File, "password")
        end        
        xmlNodeSetValue (passwordNode, "")
    end
    xmlSaveFile(xml_save_log_File)
    xmlUnloadFile(xml_save_log_File)
end
addEvent("resetSaveXML", true)
addEventHandler("resetSaveXML", getRootElement(), resetSaveXML)

local username, password = loadLoginFromXML()
if not( username == "" or password == "") then
    setChekBoxActive(1, true)
    setEditBoxText(1, tostring(username))
    setEditBoxText(2, tostring(password))
else
    setChekBoxActive(1, false)
end



Register.lua

local screenX, screenY = guiGetScreenSize()

reg = {}

reg.back_ground = guiCreateStaticImage(screenX/2-600/2, screenY/2-360/2, 600, 360, "assets/bg.png", false, login.back_ground1)
--reg.logo = guiCreateStaticImage(0, 0, 240, 360, "assets/logo.png", false, reg.back_ground)


reg.label_nickname = guiCreateLabel(290, 30, 100, 20, "LOGIN", false, reg.back_ground)
guiSetFont(reg.label_nickname, login.font["RB"] )
guiLabelSetColor(reg.label_nickname, 153, 156, 175)
createEditBox(3, 290, 50, "", reg.back_ground, false)

reg.label_email = guiCreateLabel(290, 100, 200, 20, "E-MAIL", false, reg.back_ground)
guiSetFont(reg.label_email, login.font["RB"] )
guiLabelSetColor(reg.label_email, 153, 156, 175)
createEditBox(4, 290, 120, "", reg.back_ground, false)

reg.label_password = guiCreateLabel(290, 170, 100, 20, "HAS?O", false, reg.back_ground)
guiSetFont(reg.label_password, login.font["RB"] )
guiLabelSetColor(reg.label_password, 153, 156, 175)
createEditBox(5, 290, 190, "", reg.back_ground, false)

reg.button_reg = guiCreateStaticImage(280, 235, 280, 50, "assets/button_reg.png", false, reg.back_ground)

reg.label_first = guiCreateLabel(320, 290, 200, 20, "Masz ju? konto?", false, reg.back_ground)
guiSetFont(reg.label_first, login.font["RL"])
guiLabelSetColor(reg.label_first, 153, 156, 175)
guiLabelSetHorizontalAlign(reg.label_first, "center")

reg.button_login = guiCreateLabel(320, 315, 200, 20, "Powr?t", false, reg.back_ground)
guiSetFont(reg.button_login, login.font["RB"] )
guiLabelSetColor(reg.button_login, 153, 156, 175)
guiLabelSetHorizontalAlign(reg.button_login, "center")

guiSetVisible(reg.back_ground, false)

addEventHandler("onClientMouseEnter", getRootElement(), function()
    if (source == reg.button_login) then
        guiLabelSetColor(reg.button_login, 255, 185, 41)
    elseif (source == reg.button_reg) then
        guiStaticImageLoadImage(source, "assets/button_reg_a.png")
    end
end)
    
addEventHandler("onClientMouseLeave", getRootElement(), function()
    if (source == reg.button_login) then
        guiLabelSetColor(reg.button_login, 153, 156, 175)
    elseif (source == reg.button_reg) then
        guiStaticImageLoadImage(source, "assets/button_reg.png")
    end
end)

function outputChatBox (msg, pl)
exports.dpChat:message (pl, "global", msg)
end

function onAccountCreate()
    guiSetVisible(reg.button_reg, false)
    
    guiCreateStaticImage(415, 300, 15, 10, "assets/iarrow.png", false, reg.back_ground)
    local x, y = guiGetPosition (reg.label_first, false) 
    guiSetPosition (reg.label_first, x, y-20, false)
    
    guiSetText(reg.label_first, "Konto utworzone!")
    guiSetFont(reg.label_first, login.font["RB"])
    guiLabelSetColor(reg.label_first, 255, 168, 0)
    
    guiSetText(reg.button_login, "Powr?t")
    
    setEditBoxWarning(3, "", true)
    setEditBoxWarning(4, "", true)
    setEditBoxWarning(5, "", true)
end
addEvent("onAccountCreate", true)
addEventHandler("onAccountCreate", getRootElement(), onAccountCreate)


addEventHandler ("onClientGUIClick", getRootElement(), function(button)
    if button == "left" then
        if source == reg.button_login then -- назад
            guiSetVisible(reg.back_ground, false)
            guiSetVisible(login.back_ground, true)
        elseif source == reg.button_reg then
            -- Никнейм
            local errorChek = false
            
            local nickname = guiGetText(editBox[3].label_text)
            local email = guiGetText(editBox[4].label_text)
            local password = guiGetText(editBox[5].label_text)
            
            local nicknameLen = nickname:len()
            local passwordLen = password:len()
            
            if (nicknameLen > 2 and nicknameLen < 11) then
                if not string.find(nickname, "^%w+$") then
                    errorChek = true
                    setEditBoxWarning(3, "Erro! Caracteres inv?lidos digitados.", false)
                end
            else
                errorChek = true
                setEditBoxWarning(3, "B??d! Minimalne znaki: 2, maksymalne: 10", false)
            end
            
            if not string.find(email, "^%w+@%w+.%w+$") then
                errorChek = true
                setEditBoxWarning(4, "B??d! Czy e-mail jest poprawny?.", false)
            end
            
            if (passwordLen < 6) then
                errorChek = true
                setEditBoxWarning(5, "B??d! Minimalna liczba znak?w: 6", false)
            end
            
            if not errorChek then
                triggerServerEvent("onRequestRegister", getLocalPlayer(), editBox[3].text, editBox[4].text, editBox[5].text)
            end
        end
    end 
end) 


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-05-03, 11:28


Wilq







Wiek: 24
Na forum: 4569 dni
Posty: 3409

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Wykonujesz zapytanie do bazy danych, w kt?rym weryfikujesz wprowadzone dane. Wtedy ustawiasz jak?? element dat? okre?laj?c? zalogowanie.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-05-03, 11:48


NiczeQ







Wiek: 28
Na forum: 2752 dni
Posty: 2



Respekt: 40

"Wilq" napisał/a:

Wykonujesz zapytanie do bazy danych, w kt?rym weryfikujesz wprowadzone dane. Wtedy ustawiasz jak?? element dat? okre?laj?c? zalogowanie.



A pom?g?by? z tym ?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-05-03, 12:22


Wilq







Wiek: 24
Na forum: 4569 dni
Posty: 3409

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Szukasz osoby, kt?ra wykona tak? konwersj?? Pisz ?mia?o do mnie na PW - zerknij do podpisu.
Natomiast je?li szukasz gotowego skryptu, musisz posili? si? tym dzia?em: https://gtao.pl/szukam-skryptu-modelu-mta-vt5443,3330.htm

Postaw piwo autorowi tego posta
 

 
Tagi: jak :: zrobić :: aby :: acl :: było :: mysql?
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Odpowiedz do tematu

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku