feat: added user authorization on user registrated
parent
95fcf8ef1a
commit
a1c5dad58c
|
@ -1 +1 @@
|
|||
{"email":"test_user@gmail.com","name":"test_user","password":"9a3d1f5ce0bbbdf38ca26740bdc5aa55","token":"cf49b818d38904019638d6b73be8ec40","userType":"User"}
|
||||
{"email":"test_user@gmail.com","name":"test_user","password":"9a3d1f5ce0bbbdf38ca26740bdc5aa55","token":"c623864771319a70581900cb7a4cd60d","userType":"User"}
|
|
@ -146,20 +146,24 @@ func authorization(_login, _password):
|
|||
|
||||
|
||||
@rpc("any_peer", "reliable", "call_local", 1)
|
||||
func registration(_login, _password):
|
||||
func registration(_login, _password, _name):
|
||||
var db = ORM.new()
|
||||
var client_id : int = multiplayer.get_remote_sender_id()
|
||||
var player : Node2D = _get_player(client_id)
|
||||
var token : String = str(client_id).md5_text()
|
||||
var user = db.findOne("User", _login)
|
||||
if user:
|
||||
var reason = "User already exist"
|
||||
var rpc_response = rpc_id(client_id, 'is_registrated', false, reason)
|
||||
var rpc_response = rpc_id(client_id, 'is_registrated', false, reason, _name, token)
|
||||
if rpc_response != Error.OK:
|
||||
FileManager.add_to_log("ERROR | Status: %s | Message: CLIENT NOT REGISTRATED id: %s - Error: %s" % [STATUS.ERROR, client_id, error_string(rpc_response)])
|
||||
else:
|
||||
FileManager.add_to_log("WARNING | Status: %s | Message: CLIENT NOT REGISTRATED id: %s - Error: %s" % [STATUS.WARNING, client_id, reason])
|
||||
else:
|
||||
# Add user to DB
|
||||
var rpc_response = rpc_id(client_id, 'is_registrated', true, "")
|
||||
var rpc_response = rpc_id(client_id, 'is_registrated', true, "", _name, token)
|
||||
player.token = token
|
||||
player.playerName = _name
|
||||
if rpc_response != Error.OK:
|
||||
FileManager.add_to_log("ERROR | Status: %s | Message: CLIENT NOT REGISTRATED id: %s - Error: %s" % [STATUS.ERROR, client_id, error_string(rpc_response)])
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue