Beispiel #1
0
        protected override async Task <OperationResult> DoExecute(RemindLoginDto request)
        {
            User user;

            if (string.IsNullOrEmpty(request.Pesel))
            {
                user = await _dbContext.Users.FirstOrDefaultAsync(u => u.Email == request.Email &&
                                                                  u.EmailVerified == true &&
                                                                  u.Pesel == null &&
                                                                  u.Name == request.Name &&
                                                                  u.Surname == request.Surname);
            }
            else
            {
                user = await _dbContext.Users.FirstOrDefaultAsync(u => u.Email == request.Email &&
                                                                  u.EmailVerified == true &&
                                                                  u.Pesel == request.Pesel);
            }

            if (user == null)
            {
                //Security issue: always return 200 even if user was no found
                return(new OperationSucceded());
            }

            _sendEmailCommand.Execute(new EmailDto()
            {
                To    = user.Email,
                Title = EmailContentConfiguration.LoginRemindedTitle,
                Body  = EmailContentConfiguration.LoginRemindedBody(user.CandidateId)
            });
            return(new OperationSucceded());
        }
        public override async Task <string> Execute(Guid request)
        {
            var email = _dbContext.ConfirmationEmails
                        .Include(ce => ce.User)
                        .FirstOrDefault(ce => ce.Id == request);

            if (email == null)
            {
                throw new EmailVerificationTokenNotFoundException();
            }

            if (email.Used)
            {
                return(email.User.CandidateId);
            }

            email.Used = true;

            var user = email.User;

            user.EmailVerified = true;
            await AssignCandidateId(user);

            await _dbContext.SaveChangesAsync();

            _sendEmailCommand.Execute(new EmailDto()
            {
                To    = user.Email,
                Title = EmailContentConfiguration.EmailVerifiedTitle,
                Body  = EmailContentConfiguration.EmailVerifiedBody(user.CandidateId)
            });

            return(user.CandidateId);
        }
Beispiel #3
0
        public override async Task <OperationResult> Execute(ResetPasswordDto request)
        {
            if (string.IsNullOrWhiteSpace(request.Login))
            {
                return(new OperationSucceded());
            }

            User user = await _dbContext.Users.SingleAsync(u => u.EmailVerified && u.CandidateId == request.Login);

            var passwordReset = new PasswordReset()
            {
                UserId         = user.Id,
                Id             = Guid.NewGuid(),
                InsertDateTime = DateTime.UtcNow
            };

            _dbContext.PasswordResets.Add(passwordReset);
            await _dbContext.SaveChangesAsync();

            _sendEmailCommand.Execute(new EmailDto()
            {
                To    = user.Email,
                Title = EmailContentConfiguration.ResetPasswordTitle,
                Body  = EmailContentConfiguration.ResetPasswordBody(_endpointConfig.SetNewPassword(passwordReset.Id.ToString()))
            });

            return(new OperationSucceded());
        }
        protected override async Task RegistrationCompleted(Guid id)
        {
            // becouse of user manager async disposing
            //var userManager = _scope.Get<UserManager<SimpleCustomerAccount, Guid>>();

            var token = await _userManager.GenerateEmailConfirmationTokenAsync(id);

            var user = await _userManager.FindByIdAsync(id);

            string host = ConfigurationManager.AppSettings["frontendUri"];

            await _sendEmailCommand.Execute(new EmailPublish
            {
                Email = user.Email,
                Body  =
                    $"Регистрация на сайте <a href=\"{host}\"> Наша няня </a>. Для подтверждения пароля перейдите по <a href=\"{host}#/confirm_email?userId={id}&token={token}\"> ссылке </a>",
                Subject = "Регистрация на сайте Наша няня"
            });
        }
        public void Execute_SendEmailCommand_ReturnsOptionObject2015()
        {
            // Arrange
            OptionObject2015 expected = new OptionObject2015();

            OptionObject2015       optionObject2015      = new OptionObject2015();
            IOptionObjectDecorator optionObjectDecorator = new OptionObjectDecorator(optionObject2015);
            var messageService = new Mock <ISmtpService>();
            var command        = new SendEmailCommand(optionObjectDecorator, messageService.Object);

            // Act
            var actual = command.Execute();

            // Assert
            Assert.AreEqual(expected.GetType(), actual.GetType());
        }
        protected async override Task <int> DoExecute(RegisterDto request)
        {
            int alreaddyRegisteredUsers = _dbContext.Users.Count(u => u.Email == request.Email);

            if (alreaddyRegisteredUsers >= _businessConfiguration.AllowedAccountsWithSameEmail)
            {
                throw new ValidationFailedException()
                      {
                          ValidationResult = new ValidationResult("Na ten email zarejestrowanych jest już za dużo użytkowników")
                      };
            }

            var user = new User
            {
                Email         = request.Email,
                Name          = request.Name,
                Surname       = request.Surname,
                Pesel         = request.Pesel,
                CandidateId   = null,
                PasswordHash  = _passwordHasher.HashPassword(request.Password),
                EmailVerified = false,
                BirthDate     = request.BirthDate.Value
            };

            EntityEntry <User> result = _dbContext.Users.Add(user);
            await _dbContext.SaveChangesAsync();


            if (!result.IsKeySet)
            {
                throw new Exception("Registration Failed");
            }

            Guid token = await GenerateEmailConfirmationToken(result.Entity.Id);

            _sendEmailCommand.Execute(new EmailDto()
            {
                Body  = EmailContentConfiguration.RegisteredBody(_endpointConfig.ConfirmEmail(token.ToString())),
                Title = EmailContentConfiguration.RegisteredTitle,
                To    = user.Email
            });
            return(result.Entity.Id);
        }
 public void LeavesEmailInDropFolder()
 {
     var vModel = new SendEmailModel {Body = "", ToAddress = "*****@*****.**", Subject = "test"};
     var vCommand = new SendEmailCommand(vModel);
     vCommand.Execute();
 }