Jump to content

[FIXED] Problem with login/register


justn

Recommended Posts

I have a problem with a login/register script. No errors in debugscript here you go.

Client:

function loginPlayer() 
    local username, password = guiGetText(myUsernameEdit), guiGetText(myPasswordEdit) 
    if (password:len() <= 4) then 
        exports["TopBarChat"]:sendClientMessage("Invalid Password", "Your password must be\nlonger than 4 characters!") 
        return 
    end 
    if (username:len() <= 4) then 
        exports["TopBarChat"]:sendClientMessage("Invalid Username", "Your username must be\nlonger than 4 characters!") 
        return 
    end 
    --triggerServerEvent("onRequestLogin",getLocalPlayer(),username,password) 
    triggerServerEvent("UIPaccounts.loginPlayer", root, username, password, guiCheckBoxGetSelected(rememberMyUsernameCheck), guiCheckBoxGetSelected(rememberMyPasswordCheck)) 
    triggerServerEvent("IfNewPlayerJoin",getLocalPlayer()) 
end 
  
function registerPlayer() 
    local username = guiGetText(registerEdit[1]) 
    local password = guiGetText(registerEdit[2]) 
    local queSelected = guiComboBoxGetSelected(questionsCombo) 
    local answer = guiGetText(registerEdit[4]) 
    local question = guiComboBoxGetItemText(questionsCombo, queSelected) 
    if (not question) then 
        exports["TopBarChat"]:sendClientMessage("You must select a question") 
        return 
    end 
    if (username:len() <= 4) then 
        exports["TopBarChat"]:sendClientMessage("Your username must be longer than 4 characters!") 
        return 
    end 
    if (password:len() <= 4) then 
        exports["TopBarChat"]:sendClientMessage("Your password must be longer than 4 characters!") 
        return 
    end 
    triggerServerEvent("UIPaccounts.registerPlayer",getLocalPlayer(),username,password) 
end 
  

Server:

function loginPlayer(username, password, boolRememberUsername, boolRememberPassword) 
    local currentAccount = getPlayerAccount(client) 
    if (not isPlayerGuest(client)) then return end 
    if (not isGuestAccount(currentAccount)) then 
    exports["TopBarChat"]:sendClientMessage  ("#0000FF* #FFFFFFYou're already logged in!",client,255,255,255,true) 
        return 
    end 
    if (getAccount(username) and not getAccount(username, password)) then 
         exports["TopBarChat"]:sendClientMessage  ("#0000FF* #FFFFFFThe password you submitted is wrong!",client,255,255,255,true) 
        return 
    end 
    if (not getAccount(username)) then 
         exports["TopBarChat"]:sendClientMessage  ("#0000FF* #FFFFFFThe account name you submitted does not exist!",client,255,255,255,true) 
        return 
    end 
  
    local theAccount = getAccount(username, password) 
     
    for i, player in pairs(getElementsByType("player")) do 
        local theirAccount = getPlayerAccount(player) 
        if (theirAccount == theAccount) then 
             exports["TopBarChat"]:sendClientMessage  ("#0000FF* #FFFFFFAlready in-use!", "The account you submitted\nis already used by another player!",client,255,255,255,true) 
            return 
        end 
    end 
  
    local loginStatus = logIn(client, theAccount, password) 
    if (loginStatus) then 
        triggerClientEvent(client, "UIPaccounts.remove", client) 
        spawnPlayer2(client) 
         
        local user = getAccountName(theAccount) 
        if (boolRememberUsername and boolRememberPassword) then 
            status = "both" 
        elseif (boolRememberUsername and not boolRememberPassword) then 
            status = "password" 
        elseif (not boolRememberUsername and  boolRememberPassword) then 
            status = "username" 
        elseif (not boolRememberUsername and not boolRememberPassword) then 
            status = "destroyBoth" 
        end 
        triggerClientEvent(client, "UIPaccounts.saveAccountDetails", client, user, password, status) 
    end 
end 
addEvent("UIPaccounts.loginPlayer", true) 
addEventHandler("UIPaccounts.loginPlayer", root, loginPlayer) 
  
function registerPlayer(username, password, question, answer, city) 
    if (not isPlayerGuest(client)) then return end 
    if (getAccount(username)) then 
    exports["TopBarChat"]:sendClientMessage("#0000FF* #FFFFFFThis account name is already taken!",client,255,255,255,true) 
        return 
    end 
    local acc = addAccount(username, password) 
    if (acc) then 
        local skins = getSkinsTable() 
        logIn(client, acc, password) 
        setAccountData(acc, "UIPaccounts.securityQuestion", question) 
        setAccountData(acc, "UIPaccounts.securityAnswer", answer) 
    end 
end 
addEvent("UIPaccounts.registerPlayer", true) 
addEventHandler("UIPaccounts.registerPlayer", root, registerPlayer) 

Edited by Guest
Link to comment

Are the events triggering to the server side?

(you can test with this)

function loginPlayer(username, password, boolRememberUsername, boolRememberPassword) 
    outputChatBox ( "Got event: UIPaccounts.loginPlayer" ) 
    local currentAccount = getPlayerAccount(client) 
    if (not isPlayerGuest(client)) then return end 
    if (not isGuestAccount(currentAccount)) then 
    exports["TopBarChat"]:sendClientMessage  ("#0000FF* #FFFFFFYou're already logged in!",client,255,255,255,true) 
        return 
    end 
    if (getAccount(username) and not getAccount(username, password)) then 
         exports["TopBarChat"]:sendClientMessage  ("#0000FF* #FFFFFFThe password you submitted is wrong!",client,255,255,255,true) 
        return 
    end 
    if (not getAccount(username)) then 
         exports["TopBarChat"]:sendClientMessage  ("#0000FF* #FFFFFFThe account name you submitted does not exist!",client,255,255,255,true) 
        return 
    end 
  
    local theAccount = getAccount(username, password) 
    
    for i, player in pairs(getElementsByType("player")) do 
        local theirAccount = getPlayerAccount(player) 
        if (theirAccount == theAccount) then 
             exports["TopBarChat"]:sendClientMessage  ("#0000FF* #FFFFFFAlready in-use!", "The account you submitted\nis already used by another player!",client,255,255,255,true) 
            return 
        end 
    end 
  
    local loginStatus = logIn(client, theAccount, password) 
    if (loginStatus) then 
        triggerClientEvent(client, "UIPaccounts.remove", client) 
        spawnPlayer2(client) 
        
        local user = getAccountName(theAccount) 
        if (boolRememberUsername and boolRememberPassword) then 
            status = "both" 
        elseif (boolRememberUsername and not boolRememberPassword) then 
            status = "password" 
        elseif (not boolRememberUsername and  boolRememberPassword) then 
            status = "username" 
        elseif (not boolRememberUsername and not boolRememberPassword) then 
            status = "destroyBoth" 
        end 
        triggerClientEvent(client, "UIPaccounts.saveAccountDetails", client, user, password, status) 
    end 
end 
addEvent("UIPaccounts.loginPlayer", true) 
addEventHandler("UIPaccounts.loginPlayer", root, loginPlayer) 
  
function registerPlayer(username, password, question, answer, city) 
    outputChatBox ( "Got event: UIPaccounts.registerPlayer" ) 
    if (not isPlayerGuest(client)) then return end 
    if (getAccount(username)) then 
    exports["TopBarChat"]:sendClientMessage("#0000FF* #FFFFFFThis account name is already taken!",client,255,255,255,true) 
        return 
    end 
    local acc = addAccount(username, password) 
    if (acc) then 
        local skins = getSkinsTable() 
        logIn(client, acc, password) 
        setAccountData(acc, "UIPaccounts.securityQuestion", question) 
        setAccountData(acc, "UIPaccounts.securityAnswer", answer) 
    end 
end 
addEvent("UIPaccounts.registerPlayer", true) 
addEventHandler("UIPaccounts.registerPlayer", root, registerPlayer) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...