Hello,
I have a problem I want to make a login and register form. I made it but when I login it changes the password and If I register a new account it will remplace the account that have that username.
Is there a way to create an account verifing that account not exists and when I login only login in an accont previously created?.
My code is this:
using Nakama;
using Nakama.TinyJson;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class AccountManager : MonoBehaviour
{
public ServerConnect ServerConnect;
public Animator LoginScreen;
public TMP_InputField LoginEmailField;
public TMP_InputField LoginNameField;
public TMP_InputField LoginPassword;
public TMP_InputField RegisterEmailField;
public TMP_InputField RegisterNameField;
public TMP_InputField RegisterPassword;
public IClient Client;
public ISession Session;
/// <summary>
/// Called by Unity when the GameObject starts.
/// </summary>
private async void Start()
{
// Connect to the Nakama server.
await ServerConnect.Connect();
}
/// <summary>
/// Login account
/// </summary>
public async void LoginAccount()
{
string email = LoginEmailField.text;
string username = LoginNameField.text;
string password = LoginPassword.text;
Session = await ServerConnect.Client.AuthenticateEmailAsync(email, password, username);
var account = await ServerConnect.Client.GetAccountAsync(Session);
Debug.LogFormat("User id '{0}' username '{1}'", account.User.Id, account.User.Username);
Debug.LogFormat("User wallet: '{0}'", account.Wallet);
Debug.LogFormat("New login: {0}, {1}", Session.Created, Session);
if (account.User.Username != null) {
LoginScreen.Play("Login to Loading");
}
}
/// <summary>
/// Create an account
/// </summary>
public async void CreateAccount()
{
string email = RegisterEmailField.text;
string password = RegisterPassword.text;
string username = RegisterNameField.text;
Session = await ServerConnect.Client.AuthenticateEmailAsync(email, password, username);
var account = await ServerConnect.Client.GetAccountAsync(Session);
Debug.LogFormat("User id '{0}' username '{1}'", account.User.Id, account.User.Username);
Debug.LogFormat("User wallet: '{0}'", account.Wallet);
Debug.LogFormat("New register: {0}, {1}", Session.Created, Session);
if (account.User.Username != null) {
LoginScreen.Play("Sign Up to Login");
}
}
public async void GetName()
{
var account = await ServerConnect.Client.GetAccountAsync(Session);
}
}
}