launch.gd 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #*****************************************************************************
  2. # @file launch.gd
  3. # @author MakerYang(https://www.makeryang.com)
  4. # @statement 免费课程配套开源项目,任何形式收费均为盗版
  5. #*****************************************************************************
  6. extends Control
  7. @onready var login: Control = $Login
  8. @onready var main: Control = $Login/Main
  9. @onready var main_submit_button: TextureButton = $Login/Main/Background/MainSubmitButton
  10. @onready var main_register_button: TextureButton = $Login/Main/Background/MainRegisterButton
  11. @onready var main_change_password_button: TextureButton = $Login/Main/Background/MainChangePasswordButton
  12. @onready var main_account_input: LineEdit = $Login/Main/Background/MainAccountInput
  13. @onready var main_password_input: LineEdit = $Login/Main/Background/MainPasswordInput
  14. @onready var register: Control = $Login/Register
  15. @onready var register_confirm_button: TextureButton = $Login/Register/Background/RegisterConfirmButton
  16. @onready var register_cancel_button: TextureButton = $Login/Register/Background/RegisterCancelButton
  17. @onready var register_account_input: LineEdit = $Login/Register/Background/RegisterAccountInput
  18. @onready var register_password_input: LineEdit = $Login/Register/Background/RegisterPasswordInput
  19. @onready var register_confirm_password_input: LineEdit = $Login/Register/Background/RegisterConfirmPasswordInput
  20. @onready var register_name_input: LineEdit = $Login/Register/Background/RegisterNameInput
  21. @onready var register_number_input: LineEdit = $Login/Register/Background/RegisterNumberInput
  22. @onready var register_question_a_input: LineEdit = $Login/Register/Background/RegisterQuestionAInput
  23. @onready var register_answer_a_input: LineEdit = $Login/Register/Background/RegisterAnswerAInput
  24. @onready var register_question_b_input: LineEdit = $Login/Register/Background/RegisterQuestionBInput
  25. @onready var register_answer_b_input: LineEdit = $Login/Register/Background/RegisterAnswerBInput
  26. @onready var change_password: Control = $Login/ChangePassword
  27. @onready var change_password_confirm_button: TextureButton = $Login/ChangePassword/Background/ChangePasswordConfirmButton
  28. @onready var change_password_cancel_button: TextureButton = $Login/ChangePassword/Background/ChangePasswordCancelButton
  29. @onready var change_password_account_input: LineEdit = $Login/ChangePassword/Background/ChangePasswordAccountInput
  30. @onready var change_password_old_input: LineEdit = $Login/ChangePassword/Background/ChangePasswordOldInput
  31. @onready var change_password_new_input: LineEdit = $Login/ChangePassword/Background/ChangePasswordNewInput
  32. @onready var change_password_confirm_input: LineEdit = $Login/ChangePassword/Background/ChangePasswordConfirmInput
  33. @onready var server: Control = $Server
  34. @onready var role: Control = $Role
  35. func _ready() -> void:
  36. server.visible = false
  37. role.visible = false
  38. register.visible = false
  39. change_password.visible = false
  40. func _process(delta: float) -> void:
  41. pass
  42. func _on_main_register_button_pressed() -> void:
  43. register.visible = true
  44. func _on_main_change_password_button_pressed() -> void:
  45. change_password.visible = true
  46. func _on_register_cancel_button_pressed() -> void:
  47. register.visible = false
  48. func _on_change_password_cancel_button_pressed() -> void:
  49. change_password.visible = false
  50. func _on_register_confirm_button_pressed() -> void:
  51. if register_account_input.text == "" or register_password_input.text == "" or register_confirm_password_input.text == "":
  52. printerr("注册信息不完整")
  53. return
  54. if register_password_input.text != register_confirm_password_input.text:
  55. printerr("密码输入不一致")
  56. return
  57. if !check_mail_format(register_account_input.text):
  58. printerr("邮箱格式不正确")
  59. return
  60. register_confirm_button.disabled = true
  61. print("开始请求后端接口")
  62. var post_data: Dictionary = {
  63. "account": register_account_input.text,
  64. "password": register_password_input.text,
  65. "name": register_name_input.text,
  66. "number": register_number_input.text,
  67. "question_a": register_question_a_input.text,
  68. "answer_a": register_answer_a_input.text,
  69. "question_b": register_question_b_input.text,
  70. "answer_b": register_answer_b_input.text,
  71. }
  72. print(post_data)
  73. Request.on_server("/account/register", HTTPClient.METHOD_POST, post_data, func(_result, code, _headers, body):
  74. if code == 200:
  75. var response = JSON.parse_string(body.get_string_from_utf8())
  76. print("[接口反馈数据]", response)
  77. if response["code"] == 0:
  78. print("接口请求成功")
  79. Global.update_account_token(response["data"]["token"])
  80. register_confirm_button.disabled = false
  81. register.visible = false
  82. register_account_input.text = ""
  83. register_password_input.text = ""
  84. register_confirm_password_input.text = ""
  85. register_name_input.text = ""
  86. register_number_input.text = ""
  87. register_question_a_input.text = ""
  88. register_answer_a_input.text= ""
  89. register_question_b_input.text = ""
  90. register_answer_b_input.text = ""
  91. else:
  92. register_confirm_button.disabled = false
  93. if response["code"] == 10001:
  94. printerr("邮箱已经被使用,请换一个")
  95. else:
  96. printerr("接口请求出错")
  97. else:
  98. printerr("接口异常")
  99. register_confirm_button.disabled = false
  100. )
  101. func check_mail_format(mail:String) -> bool:
  102. var check:bool = true
  103. var regex = RegEx.new()
  104. regex.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")
  105. if !regex.search(mail):
  106. check = false
  107. return check