makeyangcom 8 月之前
父节点
当前提交
1b1f3fac22

二进制
game/assets/launch/message_background.png


+ 34 - 0
game/assets/launch/message_background.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://llh2in832a08"
+path="res://.godot/imported/message_background.png-921fc0d794af457637631219ca27a628.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/launch/message_background.png"
+dest_files=["res://.godot/imported/message_background.png-921fc0d794af457637631219ca27a628.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1

+ 5 - 0
game/scripts/base/global.gd

@@ -60,3 +60,8 @@ func get_server_address() -> String:
 # 获取用户Token
 func get_account_token() -> String:
 	return data["account"]["token"]
+	
+# 更新并返回用户Token
+func update_account_token(token: String) -> String:
+	data["account"]["token"] = token
+	return data["account"]["token"]

+ 32 - 3
game/scripts/launch/launch.gd

@@ -65,9 +65,13 @@ func _on_register_confirm_button_pressed() -> void:
 	if register_password_input.text != register_confirm_password_input.text:
 		printerr("密码输入不一致")
 		return
+	if !check_mail_format(register_account_input.text):
+		printerr("邮箱格式不正确")
+		return
+	register_confirm_button.disabled = true
 	print("开始请求后端接口")
 	var post_data: Dictionary = {
-		"account": register_password_input.text,
+		"account": register_account_input.text,
 		"password": register_password_input.text,
 		"name": register_name_input.text,
 		"number": register_number_input.text,
@@ -83,8 +87,33 @@ func _on_register_confirm_button_pressed() -> void:
 			print("[接口反馈数据]", response)
 			if response["code"] == 0:
 				print("接口请求成功")
+				Global.update_account_token(response["data"]["token"])
+				register_confirm_button.disabled = false
+				register.visible = false
+				register_account_input.text = ""
+				register_password_input.text = ""
+				register_confirm_password_input.text = ""
+				register_name_input.text = ""
+				register_number_input.text = ""
+				register_question_a_input.text = ""
+				register_answer_a_input.text= ""
+				register_question_b_input.text = ""
+				register_answer_b_input.text = ""
 			else:
-				printerr("接口请求出错")
+				register_confirm_button.disabled = false
+				if response["code"] == 10001:
+					printerr("邮箱已经被使用,请换一个")
+				else:
+					printerr("接口请求出错")
 		else:
-			printerr("接口异常")	
+			printerr("接口异常")
+			register_confirm_button.disabled = false
 	)
+
+func check_mail_format(mail:String) -> bool:
+	var check:bool = true
+	var regex = RegEx.new()
+	regex.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")
+	if !regex.search(mail):
+		check = false
+	return check

+ 14 - 0
wiki/course/3.0.0.md

@@ -542,4 +542,18 @@ account := router.Group("account")
 {
     account.POST("/register", AccountInterface.Register)
 }
+```
+
+### 邮箱格式验证函数
+
+> 用于游戏引擎中验证邮箱格式的合法性
+
+``` go
+func check_mail_format(mail:String) -> bool:
+	var check:bool = true
+	var regex = RegEx.new()
+	regex.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")
+	if !regex.search(mail):
+		check = false
+	return check
 ```