예제 #1
0
        public bool ChangeWebPassword(RecoveryCode model)
        {
            var webUser = _accessTokenRepository.GetWebUserByEmail(model.Email);

            if (webUser == null)
            {
                throw new Exception("Emailadressen finns inte.");
            }

            model.UserId = webUser.Id;
            var checkValidRecoveryCode = _accessTokenRepository.CheckValidWebRecoveryCode(model);

            if (checkValidRecoveryCode == null)
            {
                throw new Exception("Ogiltig kod.");
            }

            if (checkValidRecoveryCode.ExpiredOn < DateTime.Now)
            {
                throw new Exception("Koden har gått ut.");
            }

            webUser.Password     = _cryptoGraphy.EncryptString(model.NewPassword);
            webUser.ModifiedDate = DateTime.Now;
            return(_accessTokenRepository.ChangeWebPassword(webUser, checkValidRecoveryCode.Id));
        }