public void SignUp() { if (_signupPlayerNameInputField.text.Trim() == "") { _signUpErrorText.text = "Nickname is necessary!"; return; } if (_signUpEmailInputField.text.Trim() == "") { _signUpErrorText.text = "Email is necessary!"; return; } if (_signUpPasswordInputField.text.Trim() == "") { _signUpErrorText.text = "Password is necessary"; return; } if (!Bloodthirst.Utils.IsEmail(_signUpEmailInputField.text)) { _signUpErrorText.text = "Email must be valid!"; return; } _signUpForm.SetActive(false); _authenticationPendingUI.SetActive(true); SavedData savedData = GameManager.Instance.SaveManager.SavedData; savedData.Nickname = _signupPlayerNameInputField.text; savedData.Email = _signUpEmailInputField.text; savedData.Password = _signUpPasswordInputField.text; GameManager.Instance.SaveManager.Save(savedData); UserInLocal userInLocal = new UserInLocal(_signUpEmailInputField.text, _signUpPasswordInputField.text, _signupPlayerNameInputField.text); _networkUtils.SignUp(userInLocal, (e) => { if (e != null) { _signUpErrorText.text = e.Message; _signUpForm.SetActive(true); _authenticationPendingUI.SetActive(false); } else { // After we are done authenticating, we go to the connection panel GameManager.Instance.SaveManager.UpdateConnected(true); InitializeUI(); } }); }
public void SignUp(UserInLocal userInLocal, System.Action <Exception> callback) { VerifyIfNicknameExists(userInLocal.nickname, (e) => { if (e != null) { callback(e); } else { SignUpWithEmailAndPassword(userInLocal, callback); } }); }
public void SignUpWithEmailAndPassword(UserInLocal userInLocal, System.Action <Exception> callback) { RestClient.Request(new RequestHelper { Uri = signUpBaseEndpoint + ApiKey, Method = "Post", Params = new Dictionary <string, string> { { "email", userInLocal.email }, { "password", userInLocal.password } }, IgnoreHttpException = true }).Then(response => { FirebaseSignResponse firebaseSignResponse = JsonUtility.FromJson <FirebaseSignResponse>(response.Text); if (response.StatusCode == 200) { User user = new User(); user.Nickname = userInLocal.nickname; user.Email = userInLocal.email; // Now we create an instance of the user in the database RestClient.Request(new RequestHelper { Method = "PUT", Uri = DatabaseUrl + "UsersByNickname/" + user.Nickname + ".json", Body = user }).Then(responseFromUserCreation => { if (firebaseSignResponse == null) { callback(new Exception("Couldn't create user instance")); } else { // Now we create another instance of the user, but now using his id as the identifier(This is necessary so we are able to retrieve the user nickname when he signs up using only his email) RestClient.Request(new RequestHelper { Method = "PUT", Uri = DatabaseUrl + "UsersById/" + firebaseSignResponse.localId + ".json", Body = user }).Then(responseFromUserByEmailCreation => { callback(null); }).Catch(e => { callback(e); }); } }).Catch(e => { callback(e); }); } else { FirebaseError firebaseError = JsonUtility.FromJson <FirebaseError>(response.Text); if (firebaseError.error.message == "EMAIL_EXISTS") { firebaseError.error.message = "Email already exists"; } callback(new Exception(firebaseError.error.message)); } }).Catch(e => { callback(e); }); }