Пример #1
0
        public async Task <List <string> > ConfirmEmail(string email, string code)
        {
            List <string> response = new List <string>();

            var user = await _userManager.FindByEmail(email);

            if (user == null)
            {
                response.Add("No User");
                return(response);
            }

            if (user.EmailConfirmed)
            {
                response.Add("AlreadyConfirmed");
                return(response);
            }

            var result = await _userManager.ConfirmEmailAsync(user, code);

            if (result.Succeeded)
            {
                response.Add("EmailConfirmed");
                response.Add(code);
                return(response);
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    response.Add(error.ToString());
                }
                return(response);
            }
        }
Пример #2
0
        // Method to Create New JWT and Refresh Token
        private async Task <TokenResponseModel> GenerateNewToken(TokenRequestModel model)
        {
            // check if there's an user with the given username
            var user = await _userManager.FindByEmail(model.UserName);

            // Validate credentials
            if (user != null && await _userManager.CheckPassword(user, model.Password))
            {
                //If the user has confirmed his email
                if (!await _userManager.IsEmailConfirmedAsync(user))
                {
                    return(null);
                }

                // username & password matches: create the refresh token
                var newRtoken = CreateRefreshToken(_appSettings.ClientId, user.Id);

                // first we delete any existing old refreshtokens
                await RemoveTokensById(user.Id);

                // Add new refresh token to Database
                await _dalLayer.AddToken(newRtoken);

                // Create & Return the access token which contains JWT and Refresh Token
                TokenResponseModel accessToken = await CreateAccessToken(user, newRtoken.Value);

                return(accessToken);
            }
            return(null);
        }