Esempio n. 1
0
        /// <summary>
        /// Verify password recovery token and change user password
        /// </summary>
        /// <param name="userId">user id</param>
        /// <param name="token">user token</param>
        /// <param name="newPassword">new user password</param>
        /// <returns>instance of DefaultServiceResult</returns>
        public virtual async Task <ServiceNoResult> VerifyPasswordRecoveryTokenAsync(string userIdentification, string token, string newPassword)
        {
            if (string.IsNullOrEmpty(userIdentification))
            {
                throw new ArgumentNullException(nameof(userIdentification));
            }

            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException(nameof(token));
            }

            if (string.IsNullOrEmpty(newPassword))
            {
                throw new ArgumentNullException(nameof(newPassword));
            }

            GalleryUser user = await userManager.FindByIdAsync(userIdentification);

            var resultFactory = new RequestNoResult();

            if (user == null)
            {
                return(resultFactory.BadRequest("Used doesnt exist"));
            }

            var resutlToken = await userManager.ResetPasswordAsync(user, token, newPassword);

            if (!resutlToken.Succeeded)
            {
                resultFactory.BadRequest(resutlToken.Errors.Select(item => item.Description).ToList());
            }

            return(resultFactory.GoodRequest());
        }
Esempio n. 2
0
        /// <summary>
        /// Verify confirmation token
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public virtual async Task <ServiceNoResult> VerifyConfirmationTokenAsync(string userId, string token)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException(nameof(token));
            }

            var result = new RequestNoResult();

            var confirmationResult = await manager.VerifyConifrmationTokenAsync(userId, token);

            if (confirmationResult)
            {
                return(result.GoodRequest());
            }
            else
            {
                return(result.BadRequest("Token confirmation failed"));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Verify confirmation token
        /// </summary>
        /// <param name="userId">user id</param>
        /// <param name="token">user token</param>
        /// <returns>instance of DefaultServiceResult</returns>
        public virtual async Task <ServiceNoResult> VerifyConfirmationTokenAsync(string userId, string token)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException(nameof(token));
            }

            GalleryUser user = await userManager.FindByIdAsync(userId);

            var resultFactory = new RequestNoResult();

            if (user == null)
            {
                return(resultFactory.BadRequest("Used doesnt exist"));
            }

            var resutlToken = await userManager.ConfirmEmailAsync(user, token);

            return(resultFactory.GoodRequest());
        }
Esempio n. 4
0
        /// <summary>
        /// Verify password recovery token
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="token"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        public virtual async Task <ServiceNoResult> VerifyPasswordRecoveryTokenAsync(string userId, string token, string newPassword)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException(nameof(token));
            }

            if (string.IsNullOrEmpty(newPassword))
            {
                throw new ArgumentNullException(nameof(newPassword));
            }

            var resultFactory = new RequestNoResult();

            bool success = await manager.VerifyPasswordRecoveryTokenAsync(userId, token, newPassword);

            if (success)
            {
                resultFactory.BadRequest("Password recovery failed");
            }

            return(resultFactory.GoodRequest());
        }