コード例 #1
0
        public User VerifyUserEmail(string token)
        {
            UserEmailVerification userEmailValidation = this.userReadService.GetUserEmailVerificationByToken(token);

            if (userEmailValidation is null)
            {
                return(null);
            }

            if (userEmailValidation.ExpirationDate < DateTime.Now)
            {
                this.DeleteEmailVerificationToken(userEmailValidation.UserId);
                return(null);
            }

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@id", userEmailValidation.UserId);

            string query = @"UPDATE reg_users SET user_active = 1 WHERE user_id = @id";

            this.userRepository.UpdateDelete(query, parameters);
            this.DeleteEmailVerificationToken(userEmailValidation.UserId);

            return(this.mapper.Map <User>(this.userReadService.GetUserById(userEmailValidation.UserId)));
        }
コード例 #2
0
        public string VerifyResetPassword(string token)
        {
            //Verify the email token that was send to the user's email after resetting their password
            UserEmailVerification userEmailValidation = this.userReadService.GetUserEmailVerificationByToken(token);

            //If the token was not correct
            if (userEmailValidation is null)
            {
                return(null);
            }

            //If the token was correct but expired
            if (userEmailValidation.ExpirationDate < DateTime.Now)
            {
                //Delete the token from db
                this.DeleteEmailVerificationToken(userEmailValidation.UserId);
                return(null);
            }

            //If the token was correct
            else
            {
                //Generate new password
                string newPassword = Guid.NewGuid().ToString("d").Substring(1, 12);
                //Upate the password in the database
                this.UpdatePassword(userEmailValidation.UserId, newPassword, null, true);
                return(newPassword);
            }
        }
コード例 #3
0
        /// <summary>
        /// Create token for e-mail verification
        /// </summary>
        /// <returns>string</returns>
        public string CreateEmailVerificationToken(int userId)
        {
            UserEmailVerification validation = this.userReadService.GetUserEmailVerificationByUserId(userId);

            if (validation != null)
            {
                // Destroy existing validation for this user
                this.DeleteEmailVerificationToken(userId);
            }

            string emailValidationToken = "";

            do
            {
                emailValidationToken = Guid.NewGuid().ToString();
                validation           = this.userReadService.GetUserEmailVerificationByToken(emailValidationToken);
            }while (validation != null);

            return(emailValidationToken);
        }