Skip to content

Commit

Permalink
Merge pull request #11 from TaloDev/develop
Browse files Browse the repository at this point in the history
Release 0.3.1
  • Loading branch information
tudddorrr authored Jul 25, 2024
2 parents 203e92b + 321640f commit c35f092
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 53 deletions.
11 changes: 3 additions & 8 deletions addons/talo/apis/player_auth_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ class_name PlayerAuthAPI extends TaloAPI
var session_manager = TaloSessionManager.new()
var last_error: Variant = null

func _handle_session_created(alias: Dictionary, session_token: String) -> void:
Talo.current_alias = TaloPlayerAlias.new(alias)
Talo.players.identified.emit(Talo.current_player)
session_manager.save_session(session_token)

func _handle_error(res: Dictionary, ret: Variant = FAILED) -> Variant:
if res.body.has("errorCode"):
last_error = TaloAuthError.new(res.body.errorCode)
Expand All @@ -30,7 +25,7 @@ func register(identifier: String, password: String, email: String = "", verifica

match (res.status):
200:
_handle_session_created(res.body.alias, res.body.sessionToken)
session_manager.handle_session_created(res.body.alias, res.body.sessionToken)
return OK
_:
return _handle_error(res)
Expand All @@ -46,7 +41,7 @@ func login(identifier: String, password: String) -> Array[Variant]: ## [Error, b
if res.body.has("verificationRequired"):
session_manager.save_verification_alias_id(res.body.aliasId)
else:
_handle_session_created(res.body.alias, res.body.sessionToken)
session_manager.handle_session_created(res.body.alias, res.body.sessionToken)

return [OK, res.body.has("verificationRequired")]
_:
Expand All @@ -60,7 +55,7 @@ func verify(verification_code: String) -> Error:

match (res.status):
200:
_handle_session_created(res.body.alias, res.body.sessionToken)
session_manager.handle_session_created(res.body.alias, res.body.sessionToken)
return OK
_:
return _handle_error(res)
Expand Down
2 changes: 1 addition & 1 deletion addons/talo/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Talo Game Services"
description="Talo (https://trytalo.com) is an open-source game backend with services designed to help you build games faster. You can currently:\n\n- Identify and authenticate players\n- Store persistent data across players\n- Track events (levelling up, finding loot, etc)\n- Display high scores with leaderboards\n- Store and load player saves\n- Load game config options and flags from the cloud\n- Get feedback directly from your players"
author="trytalo"
version="0.3.0"
version="0.3.1"
script="talo_autoload.gd"
2 changes: 1 addition & 1 deletion addons/talo/samples/authentication/scripts/change_email.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func _on_submit_pressed() -> void:
match Talo.player_auth.last_error.get_code():
TaloAuthError.ErrorCode.INVALID_CREDENTIALS:
validation_label.text = "Current password is incorrect"
TaloAuthError.ErrorCode.NEW_EMAIL_MATCHES_OLD_EMAIL:
TaloAuthError.ErrorCode.NEW_EMAIL_MATCHES_CURRENT_EMAIL:
validation_label.text = "New email must be different from the current email"
_:
validation_label.text = Talo.player_auth.last_error.get_string()
Expand Down
8 changes: 4 additions & 4 deletions addons/talo/samples/authentication/scripts/change_password.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ extends Node2D
signal password_change_success
signal go_to_game

@onready var old_password: TextEdit = %OldPassword
@onready var current_password: TextEdit = %CurrentPassword
@onready var new_password: TextEdit = %NewPassword
@onready var validation_label: Label = %ValidationLabel

func _on_submit_pressed() -> void:
validation_label.text = ""

if not old_password.text:
if not current_password.text:
validation_label.text = "Current password is required"
return

if not new_password.text:
validation_label.text = "New password is required"
return

var res = await Talo.player_auth.change_password(old_password.text, new_password.text)
var res = await Talo.player_auth.change_password(current_password.text, new_password.text)
if res != OK:
match Talo.player_auth.last_error.get_code():
TaloAuthError.ErrorCode.INVALID_CREDENTIALS:
validation_label.text = "Current password is incorrect"
TaloAuthError.ErrorCode.NEW_PASSWORD_MATCHES_OLD_PASSWORD:
TaloAuthError.ErrorCode.NEW_PASSWORD_MATCHES_CURRENT_PASSWORD:
validation_label.text = "New password must be different from the current password"
_:
validation_label.text = Talo.player_auth.last_error.get_string()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ theme = ExtResource("2_hwmu0")
text = "Change password"
horizontal_alignment = 1

[node name="OldPassword" type="TextEdit" parent="UI/MarginContainer/VBoxContainer"]
[node name="CurrentPassword" type="TextEdit" parent="UI/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(400, 40)
layout_mode = 2
Expand Down
9 changes: 0 additions & 9 deletions addons/talo/samples/playground/playground.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ columns = 3
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect0"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control"]
custom_minimum_size = Vector2(16, 16)
Expand All @@ -231,7 +230,6 @@ offset_bottom = 16.0
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect1"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control2"]
custom_minimum_size = Vector2(16, 16)
Expand All @@ -243,7 +241,6 @@ offset_bottom = 16.0
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect2"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control3"]
custom_minimum_size = Vector2(16, 16)
Expand All @@ -255,7 +252,6 @@ offset_bottom = 16.0
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect3"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control4"]
custom_minimum_size = Vector2(16, 16)
Expand All @@ -267,7 +263,6 @@ offset_bottom = 16.0
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect4"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control5"]
custom_minimum_size = Vector2(16, 16)
Expand All @@ -279,7 +274,6 @@ offset_bottom = 16.0
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect5"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control6"]
custom_minimum_size = Vector2(16, 16)
Expand All @@ -291,7 +285,6 @@ offset_bottom = 16.0
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect6"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control7"]
custom_minimum_size = Vector2(16, 16)
Expand All @@ -303,7 +296,6 @@ offset_bottom = 16.0
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect7"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control8"]
custom_minimum_size = Vector2(16, 16)
Expand All @@ -315,7 +307,6 @@ offset_bottom = 16.0
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
script = ExtResource("12_72qp7")
id = "color_rect8"

[node name="ColorRect" type="ColorRect" parent="UI/MarginContainer/APIs/Saves/VBoxContainer/GridContainer/Control9"]
custom_minimum_size = Vector2(16, 16)
Expand Down
24 changes: 10 additions & 14 deletions addons/talo/utils/session_manager.gd
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
class_name TaloSessionManager extends Node

var _config_file_path = "user://talo_session.cfg"

func _init() -> void:
Talo.players.identified.connect(_check_session)
var _verification_alias_id = ""

func _load_config() -> ConfigFile:
var config = ConfigFile.new()
config.load(_config_file_path)
return config

func save_session(session_token: String) -> void:
func _save_session(session_token: String) -> void:
var config = ConfigFile.new()
config.set_value("session", "token", session_token)
config.set_value("session", "identifier", Talo.current_alias.identifier)
config.save(_config_file_path)

func _check_session(_player: TaloPlayer) -> void:
if Talo.current_alias.service != "talo":
clear_session()

func clear_session() -> void:
var config = _load_config()
config.erase_section("session")
Expand All @@ -34,10 +28,12 @@ func get_identifier() -> String:
return config.get_value("session", "identifier", "")

func save_verification_alias_id(alias_id: int) -> void:
var config = _load_config()
config.set_value("verification", "alias_id", str(alias_id))
config.save(_config_file_path)
_verification_alias_id = alias_id

func get_verification_alias_id() -> String:
var config = _load_config()
return config.get_value("verification", "alias_id", "")
func get_verification_alias_id() -> int:
return _verification_alias_id

func handle_session_created(alias: Dictionary, session_token: String) -> void:
Talo.current_alias = TaloPlayerAlias.new(alias)
Talo.players.identified.emit(Talo.current_player)
_save_session(session_token)
17 changes: 2 additions & 15 deletions addons/talo/utils/talo_auth_error.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,11 @@ enum ErrorCode {
IDENTIFIER_TAKEN,
MISSING_SESSION,
INVALID_SESSION,
NEW_PASSWORD_MATCHES_OLD_PASSWORD,
NEW_EMAIL_MATCHES_OLD_EMAIL,
NEW_PASSWORD_MATCHES_CURRENT_PASSWORD,
NEW_EMAIL_MATCHES_CURRENT_EMAIL,
PASSWORD_RESET_CODE_INVALID
}

# var error_map: Dictionary = {
# "API_ERROR": ErrorCode.API_ERROR,
# "INVALID_CREDENTIALS": ErrorCode.INVALID_CREDENTIALS,
# "VERIFICATION_ALIAS_NOT_FOUND": ErrorCode.VERIFICATION_ALIAS_NOT_FOUND,
# "VERIFICATION_CODE_INVALID": ErrorCode.VERIFICATION_CODE_INVALID,
# "IDENTIFIER_TAKEN": ErrorCode.IDENTIFIER_TAKEN,
# "MISSING_SESSION": ErrorCode.MISSING_SESSION,
# "INVALID_SESSION": ErrorCode.INVALID_SESSION,
# "NEW_PASSWORD_MATCHES_OLD_PASSWORD": ErrorCode.NEW_PASSWORD_MATCHES_OLD_PASSWORD,
# "NEW_EMAIL_MATCHES_OLD_EMAIL": ErrorCode.NEW_EMAIL_MATCHES_OLD_EMAIL,
# "PASSWORD_RESET_CODE_INVALID": ErrorCode.PASSWORD_RESET_CODE_INVALID
# }

var _error_string = ""

func _init(error_string: String) -> void:
Expand Down

0 comments on commit c35f092

Please sign in to comment.