Ejemplo n.º 1
0
        public async Task <Result> AccountConfirmedOTP(int randomNumber)
        {
            try
            {
                var email = await _currentUser.GetEmail();

                OTPConfirmationModel otpModel = new()
                {
                    RandomNumber = randomNumber,
                    Email        = email
                };

                var loginAsJson = JsonConvert.SerializeObject(otpModel);

                var response = await httpClient.PostAsync("api/v1/OAuth/AccountOTPConfirmation",
                                                          new StringContent(loginAsJson, Encoding.UTF8, "application/json"));

                var loginResult = JsonConvert.DeserializeObject <AuthenticationResult>(await response.Content.ReadAsStringAsync());

                if (!response.IsSuccessStatusCode)
                {
                    return(Result.Failure(loginResult.EnError, loginResult.FaError));
                }

                await SetAuthentication(loginResult.Token, loginResult.RefreshToken);

                return(Result.Success());
            }
            catch (Exception)
            {
                return(CommonResults.InternalServerError("Internal Server Error", "سرور در حال بارگذاری می باشد"));
            }
        }
Ejemplo n.º 2
0
        private async Task <Player> GetPlayerAsync(CancellationToken token)
        {
            var authId = GetAuthId();

            if (!await _context.Player.AnyAsync <Player>(x => x.AuthString == authId, cancellationToken: token))
            {
                var entity = new Player()
                {
                    DisplayName = _currentUser.GetName(),
                    AuthString  = authId,
                    Email       = _currentUser.GetEmail()
                };

                if (!await _context.Player.AnyAsync <Player>(cancellationToken: token))
                {
                    foreach (var role in _context.PlayerRole)
                    {
                        entity.Roles.Add(new PlayerRolePlayer()
                        {
                            PlayerRoleId = role.Id
                        });
                    }
                }
                await _context.Player.AddAsync(entity, token);

                await _context.SaveChangesAsync(token);
            }

            var player = _context.Player.Include(p => p.Roles).ThenInclude(role => role.PlayerRole).First <Player>(x => x.AuthString == authId);

            //TODO: Remove this fix
            if (string.IsNullOrEmpty(player.Email))
            {
                player.Email = _currentUser.GetEmail();
                await _context.SaveChangesAsync(token);
            }

            return(player);
        }