test-client-godot/gui_scene/GUI/login/register_menu.gd

203 lines
9.3 KiB
GDScript

extends Control
signal sound_button_toggled( button_pressed )
signal cancel_button_pressed
signal license_button_pressed
signal register_account_created
func _on_sound_button_toggled( button_pressed ):
emit_signal( "sound_button_toggled", button_pressed )
func _on_cancel_button_pressed():
emit_signal( "cancel_button_pressed" )
func _on_license_button_pressed():
emit_signal( "license_button_pressed" )
func _on_check_box_pressed():
do_enable_register_button();
func do_enable_register_button():
var username = get_node("h_box_container/v_box_container/center_container/register_box/login_box/login_edit").get_text();
var register = get_node('h_box_container/v_box_container/center_container/register_box/h_box_container/register_button2')
var password = get_node("h_box_container/v_box_container/center_container/register_box/password_box/password_edit").get_text();
var confirmed = get_node("h_box_container/v_box_container/center_container/register_box/password_confirm_box/password_edit").get_text();
var email = get_node("h_box_container/v_box_container/center_container/register_box/email_box/email_edit").get_text();
var cur_state = get_node('h_box_container/v_box_container/center_container/register_box/license_box/check_box').is_pressed()
if username == null or username == "":
#print("Register : username empty");
register.disabled = true
elif password == null or password == "":
#print("Register : password empty");
register.disabled = true
elif confirmed == null or confirmed == "":
#print("Register : confirmed empty");
register.disabled = true
elif password != confirmed:
#print("Register : password != confirmed");
register.disabled = true
elif email == null or email == "":
#print("Register : email empty");
register.disabled = true
elif cur_state == false:
#print("Register : unchecked condition");
register.disabled = true
else:
register.disabled = false
func _on_play_button_pressed():
var username = $h_box_container/v_box_container/center_container/register_box/login_box/login_edit.get_text();
var password = $h_box_container/v_box_container/center_container/register_box/password_box/password_edit.get_text();
var confirmed = $h_box_container/v_box_container/center_container/register_box/password_confirm_box/password_edit.get_text();
var email = $h_box_container/v_box_container/center_container/register_box/email_box/email_edit.get_text();
var cur_state = $h_box_container/v_box_container/center_container/register_box/license_box/check_box.is_pressed()
var enregister = $h_box_container/v_box_container/center_container/register_box/h_box_container/register_button2
var tac = "off";
if cur_state == true:
tac = "on";
if username != null and username != "" and password != null and password != "" and confirmed != null and confirmed != "" and email != null and email != "":
do_request(username, password, confirmed, email, tac)
func do_request(username, password, confirmed, email, tac):
var script_register = load("res://assets/Scripts/Models/nel_register.gd")
var script_connexion = load("res://assets/Scripts/Config/connexion.gd")
var connexion = script_connexion.connexion.new()
var url_register = connexion.get_url_register()
var valid_certificate = connexion.get_valid_certificate()
var request_data = script_register.nel_register.new(username, password, confirmed, email, tac)
#print("url:" + str(url_register))
#print("headers:" + str(request_data.get_headers()))
#print("data:" + str(request_data.get_param_add_user_string()))
# Ignore redirect 302 (because khaganat response 302 when account is created !)
$HTTPRequest.set_max_redirects(0)
var err = $HTTPRequest.request(url_register,
request_data.get_headers(),
valid_certificate,
HTTPClient.METHOD_POST,
request_data.get_param_add_user_string()
);
match err:
0:
print("[Register] Send command")
get_node("wait_dialog").popup_centered()
_:
print("[Register] Command not sended : Failure! (code:" + str(err) + ")")
var comment_last = get_node('h_box_container/v_box_container/center_container/register_box/comment_last')
comment_last.text = "Impossible de créer votre compte (Erreur dans l'envoie de la requette)"
comment_last.add_color_override("font_color", "b51111")
get_node("wait_dialog").hide()
get_node("error_dialog/v_box_container/label").text = "Impossible de créer votre compte\nErreur dans l'envoie de la requette\n"
get_node("error_dialog").popup_centered()
func _on_HTTPRequest_request_completed( result, response_code, headers, body ):
var pos
var search
var enregister = $h_box_container/v_box_container/center_container/register_box/h_box_container/register_button2
var comment_last = $h_box_container/v_box_container/center_container/register_box/comment_last
var comment_username = $h_box_container/v_box_container/center_container/register_box/login_box/comment
var comment_password = $h_box_container/v_box_container/center_container/register_box/password_box/comment
var comment_confirm_password = $h_box_container/v_box_container/center_container/register_box/password_confirm_box/comment
var comment_email = $h_box_container/v_box_container/center_container/register_box/email_box/comment
var regex = RegEx.new()
comment_username.text = ""
comment_password.text = ""
comment_confirm_password.text = ""
comment_email.text = ""
comment_last.text = ""
comment_last.add_color_override("font_color", "000000")
print("[Register] result:" + str(result) + ", response_code:" + str(response_code))
if result == HTTPRequest.RESULT_REDIRECT_LIMIT_REACHED and response_code == 302:
get_node("wait_dialog").hide()
get_node("info_dialog/v_box_container/label").text = "Compte créé"
get_node("info_dialog").popup_centered()
return
if result == HTTPRequest.RESULT_SUCCESS and response_code != 200:
comment_last.text = "Serveur a renvoyé une erreur (code retour HTTP:" + str(response_code) + ")"
comment_last.add_color_override("font_color", "b51111")
get_node("wait_dialog").hide()
get_node("error_dialog/v_box_container/label").text = "Impossible de créer le compte\nCode retour HTTP:" + str(response_code)
get_node("error_dialog").popup_centered()
return
get_node("wait_dialog").hide()
var text = str2var(body.get_string_from_utf8())
regex.compile("^(\\d+)[:]")
var tab = text.split(":", true,2)
if tab.size() > 1 :
if regex.search(tab[0]):
if int(tab[0]) != 1:
comment_last.text = "Serveur a renvoyé une erreur (Code retour:" + str(tab[0]) + ", message:" + tab[1] +")"
comment_last.add_color_override("font_color", "b51111")
get_node("wait_dialog").hide()
get_node("error_dialog/v_box_container/label").text = "Serveur a renvoyé une erreur\nCode retour:" + str(tab[0]) + "\nMessage:" + tab[1]
get_node("error_dialog").popup_centered()
print("[Register] Failed to register (Code retour:" + str(tab[0]) + ", message:" + tab[1] +")")
return
tab = text.rsplit("\n")
regex.compile(">(?<comment>.+)</")
for item in tab:
pos = item.find("comment-Username")
search = regex.search(item)
if pos > 0 and search:
comment_username.text = search.get_string("comment")
print("[Register] Username issue : " + comment_username.text)
pos = item.find("comment-Password")
if pos > 0 and search:
comment_password.text = search.get_string("comment")
print("[Register] Password issue : " + comment_password.text)
pos = item.find("comment-ConfirmPass")
if pos > 0 and search:
comment_confirm_password.text = search.get_string("comment")
print("[Register] ConfirmPass issue : " + comment_confirm_password.text)
pos = item.find("comment-Email")
if pos > 0 and search:
comment_email.text = search.get_string("comment")
print("[Register] Email issue : " + comment_email.text)
pos = item.find("comment-Tac")
if pos > 0 and search:
comment_last.text = search.get_string("comment")
comment_last.add_color_override("font_color", "b51111")
print("[Register] Issue : " + comment_last.text)
func _on_login_edit_text_changed(new_text):
do_enable_register_button();
func _on_password_edit_text_changed(new_text):
do_enable_register_button();
func _on_email_edit_text_changed(new_text):
do_enable_register_button();
func _on_button_pressed():
$HTTPRequest.cancel_request()
get_node("wait_dialog").hide()
func _on_info_dialog_button_pressed():
get_node("info_dialog").hide()
hide()
# _on_register_menu_register_button_pressed
emit_signal( "register_account_created" )
func _on_error_dialog_button_pressed():
get_node("error_dialog").hide()