public void Find_By_Guid()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name",  Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            User accountUserLoaded = userRepository.Find(accountUser.Guid);
            Assert.IsTrue(accountUserLoaded.Id == accountUserLoaded.Id);
        }
        public void Find_By_Email_And_Password()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            User accountUserFound = userRepository.Find(accountUser.Email, accountUser.Password);
            Assert.IsNotNull(accountUserFound);
        }
        public void Find_By_ForgotPassword()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            accountUser.ForgotPasswordGuid = Guid.NewGuid();
            userRepository.Update(accountUser);

            User userFound = userRepository.FindByForgotPassword(accountUser.ForgotPasswordGuid);
            Assert.IsNotNull(userFound);
        }
        public void SendUserForgotPassword(User accountUser, Guid guidForgotPassword)
        {
            try
            {
                using (SmtpClient smtpClient = new SmtpClient())
                {
                    string message = this.getTemplate("AppActs.Client.Service.Templates.Email.UserForgotPassword.htm");

                    message = String.Format
                        (
                            message,
                            accountUser.Name,
                            new StringBuilder()
                                .Append(this.settings.Url)
                                .Append("Password-Change/")
                                .Append("?token=")
                                .Append(guidForgotPassword),
                            this.getTemplate("AppActs.Client.Service.Templates.Part.Signature.htm"),
                            settings.Url
                        );

                    using (MailMessage mailMessage = new MailMessage
                        (
                            new MailAddress(this.settings.EmailFrom, this.settings.EmailFromDisplayName),
                            new MailAddress(accountUser.Email)
                        ))
                    {
                        mailMessage.Subject = String.Format("{0}, did you forget your password?", accountUser.Name);
                        mailMessage.Body = message;
                        mailMessage.IsBodyHtml = true;
                        smtpClient.Send(mailMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ServiceLayerException(ex);
            }
        }
Exemplo n.º 5
0
 public void Consume(User accountUser)
 {
     this.Id = accountUser.Id;
     this.Guid = accountUser.Guid;
     this.Name = accountUser.Name;
     this.Email = accountUser.Email;
     this.Active = accountUser.Active;
     this.DateCreated = accountUser.DateCreated;
     this.DateModified = accountUser.DateModified;
 }
        public void Update(User accountUser)
        {
            try
            {
                accountUser.Name = accountUser.Name.Substring(0, 1).ToUpper() +
                                    accountUser.Name.Substring(1, accountUser.Name.Length - 1);

                this.accountUserRepository.Update(accountUser);
            }
            catch (DataAccessLayerException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ServiceLayerException(ex);
            }
        }
        public void Save(User accountUser)
        {
            try
            {
                accountUser.Password = DES.Encrypt
                    (
                        this.settings.SecurityKey,
                        SHA2.GetSHA256Hash(accountUser.Password)
                    );

                accountUser.Name = accountUser.Name.Substring(0, 1).ToUpper() +
                                    accountUser.Name.Substring(1, accountUser.Name.Length - 1);

                this.accountUserRepository.Save(accountUser);
            }
            catch (DataAccessLayerException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ServiceLayerException(ex);
            }
        }
        public void Update()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            User accountUserLoaded = userRepository.Find(accountUser.Id);

            accountUserLoaded.Active = false;
            accountUserLoaded.Password = "******";
            accountUserLoaded.DateModified = DateTime.Now;

            userRepository.Update(accountUserLoaded);

            User accountUserUpdate = userRepository.Find(accountUser.Id);

            Assert.IsTrue(accountUserUpdate.Active == accountUserLoaded.Active);
        }
        public void Save()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            Assert.IsTrue(accountUser.Id != ObjectId.Empty);
        }