Пример #1
0
        public bool ChangePassword(RecoveryCode model)
        {
            _changePasswordValidators.Validate(model);

            var user = _accessTokenRepository.GetUserByEmail(model.Email);

            if (user == null)
            {
                throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Användare finns inte.");
            }

            model.UserId = user.Id;
            var recoverCode = _accessTokenRepository.CheckValidRecoverCode(model);

            if (recoverCode == null)
            {
                throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Ogiltig kod.");
            }

            if (recoverCode.ExpiredOn < DateTime.Now)
            {
                throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Koden har gått ut.");
            }

            var changePassword = ChangePasswordMapper(model);

            return(_accessTokenRepository.ChangePassword(changePassword, recoverCode.Id));
        }