Signup form

This commit is contained in:
2020-08-15 17:42:49 -04:00
parent a5363ac8dd
commit 089013e985
22 changed files with 7547 additions and 7 deletions

View File

@ -0,0 +1,64 @@
extends Popup
export(NodePath) var usernamePath
export(NodePath) var passwordPath
export(NodePath) var confirmPasswordPath
export(NodePath) var buttonPath
export(NodePath) var errorPath
var usernameEdit : LineEdit
var passwordEdit : LineEdit
var cPasswordEdit : LineEdit
var errorLabel : Label
var button : Button
const MIN_PASSWORD_LENGTH = 8
func _ready():
# Get nodes
usernameEdit = get_node(usernamePath)
passwordEdit = get_node(passwordPath)
cPasswordEdit = get_node(confirmPasswordPath)
errorLabel = get_node(errorPath)
button = get_node(buttonPath)
# Set forms to validate on value chagne
usernameEdit.connect("text_changed", self, "validate_fields")
passwordEdit.connect("text_changed", self, "validate_fields")
cPasswordEdit.connect("text_changed", self, "validate_fields")
# Connect submission button
button.connect("button_down", self, "signup")
# Clear error message
errorLabel.text = ""
func signup():
var error : NakamaException = yield(ServerConnection.signup_async(usernameEdit.text, passwordEdit.text), "completed")
# Check for error
if error:
errorLabel.text = error.message
else:
print("Signed up successfully!")
# Close signup form
hide()
func validate_fields(_text=""):
var valid : bool = check_email(usernameEdit.text) and passwords_valid(passwordEdit.text, cPasswordEdit.text)
button.disabled = !valid
return valid
func passwords_valid(password, cpassword):
return password == cpassword and len(password) >= MIN_PASSWORD_LENGTH
func check_email(email) -> bool:
# Use regex to validate email
var regex = RegEx.new()
regex.compile("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}")
var result = regex.search(email)
if result:
return true
return false

View File

@ -0,0 +1,31 @@
extends Node
const KEY := "defaultkey"
const SERVER_ENDPOINT := "nakama.cloudsumu.com"
var _session : NakamaSession
var _client : NakamaClient = Nakama.create_client(KEY, SERVER_ENDPOINT, 7350, "http")
func authenticate_async(email : String, password : String) -> NakamaException:
var result : NakamaException = null
var new_session : NakamaSession = yield(_client.authenticate_email_async(email, password, null, false), "completed")
if not new_session.is_exception():
_session = new_session
else:
result = new_session.get_exception()
return result
func signup_async(email : String, password : String) -> NakamaException:
var result : NakamaException = null
var new_session : NakamaSession = yield(_client.authenticate_email_async(email, password, null, true), "completed")
if not new_session.is_exception():
_session = new_session
else:
result = new_session.get_exception()
return result