示例#1
0
        public void ChangePassword(User user, string oldPassword, string newPassword)
        {
            var entity = user as User;
            if (entity == null) return;

            if(!_passwordHelper.ComparePasswordToHash(oldPassword, entity.Password))
                throw new InvalidOperationException("The old password provided does not match the current password.");

            switch (_settings.Password.PasswordFormat)
            {
                case PasswordFormat.Hashed:
                    entity.ChangePassword(_passwordHelper, newPassword);
                    break;
                case PasswordFormat.Clear:
                    entity.ChangePassword(new ClearPasswordHelper(), newPassword);
                    break;
                case PasswordFormat.Encrypted:
                    throw new NotImplementedException();
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            ValidateAndSave(entity);
        }
示例#2
0
 public IEnumerable<TimeRecord> FindAll(User user, int limit)
 {
     return _timeRecordRepository.Query()
         .Where(x => x.User == user)
         .OrderByDescending(x => x.StartTime)
         .Take(limit)
         .ToList();
 }
示例#3
0
 private void SendConfirmationEmail(User user)
 {
     var email = new HtmlTag("body")
         .Child(new HtmlTag("h3").Text("Thank you for registering"))
         .Child(new HtmlTag("div").Id("wrapper")
                    .Child(new LinkTag("Click here to activate your account",
                                       UrlContext.ToFull(_urlRegistry.UrlFor(new ActivateAccountModel() {Id = user.Id})))));
     _emailService.SendEmail(user.Email, _emailSettings.DefaultFromEmailAddress, "Activate your account", email.ToString());
 }
示例#4
0
        public INotification RegisterUser(User user)
        {
            var notification = _userService.Create(user);

            if (notification.IsValid())
                SendConfirmationEmail(user);

            return notification;
        }
示例#5
0
        public Card CreateCard(Card card, Project project, User user)
        {
            var newcard = new Card
            {
                Title = card.Title,
                Size = card.Size,
                Priority = card.Priority,
                Deadline = card.Deadline,
                Details = card.Details,
                Project = project,
                Color = "grey",
                Status = CardStatus.New,
                AssignedTo = user

            };

            var lastCard = project.GetCards().OrderByDescending(x => x.CardNumber).Take(1).FirstOrDefault();

            newcard.CardNumber = lastCard == null ? 1 : lastCard.CardNumber + 1;

            return newcard;
        }
示例#6
0
 public void ChangePasswordQuestionAndAnswer(User user, string password, string question, string answer)
 {
     throw new NotImplementedException();
 }
示例#7
0
 private void ValidateAndSave(User entity)
 {
     var results = _validator.Validate(entity);
     if (results.IsValid())
         _userRepository.Save(entity);
 }
示例#8
0
 private void addDefaultAdmin()
 {
     _user = new SuperUser("KokugenAdmin", "*****@*****.**", "K0kugen@dmin");
     _userService.Create(_user);
 }
示例#9
0
        private void emailUserNewPassword(string newPassword, User user)
        {
            var email = new HtmlTag("div")
                .Child(new HtmlTag("h3", tag => tag.Text("Your password has been reset")))
                .Child(new HtmlTag("span", tag => tag.Text("Your new password is: ")))
                .Child(new HtmlTag("span", tag => tag.Text(newPassword)));

            _emailService.SendEmail(user.Email, _emailSettings.DefaultFromEmailAddress,"Your Password Has Been Reset", email.ToString());
        }
示例#10
0
        private string resetPassword(User entity)
        {
            var newPassword = _passwordHelper.RandomPasswordNoHash(_settings.Password.MinRequiredPasswordLength,
                                                                   _settings.Password.
                                                                       MinRequiredNonAlphanumericCharacters);

            switch (_settings.Password.PasswordFormat)
            {
                case PasswordFormat.Hashed:
                    entity.ChangePassword(_passwordHelper, newPassword);
                    break;
                case PasswordFormat.Clear:
                    entity.ChangePassword(new ClearPasswordHelper(), newPassword);
                    break;
                case PasswordFormat.Encrypted:
                    throw new NotImplementedException();
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            ValidateAndSave(entity);

            return newPassword;
        }
示例#11
0
        public void ResetPassword(User user)
        {
            if (!_settings.PasswordResetRetrievalSettings.EnablePasswordReset)
                throw new InvalidOperationException("Password reset is not enabled");

            var newPassword = resetPassword(user);

            emailUserNewPassword(newPassword, user);
        }
示例#12
0
        public void Unlock(User entity)
        {
            entity.Unlock();

            ValidateAndSave(entity);
        }
示例#13
0
 public virtual void RemoveUser(User user)
 {
     if (_users.Contains(user))
         _users.Remove(user);
 }
示例#14
0
        public void ResetPassword(User user, string passwordAnswer)
        {
            if (!_settings.PasswordResetRetrievalSettings.EnablePasswordReset)
                throw new InvalidOperationException("Password reset is not enabled");

            if(_settings.PasswordResetRetrievalSettings.RequiresQuestionAndAnswer)
            {
               if(user.Answer != passwordAnswer)
                   throw new InvalidOperationException("Password answer does not match");
            }

            var newPassword = resetPassword(user);

            emailUserNewPassword(newPassword, user);
        }
示例#15
0
 public string GetPassword(User user, string passwordAnswer)
 {
     throw new NotImplementedException();
 }
示例#16
0
 public INotification Update(User user)
 {
     return ValidateAndUpdate(user);
 }
示例#17
0
        private INotification ValidateAndUpdate(User entity)
        {
            var notification = _validator.Validate(entity);
            if (notification.IsValid())
            {
                //make sure email is unique
                var user = _userRepository.FindBy(x => x.Email, entity.Email);
                if (user != null)
                {
                    if (user.Id != entity.Id)
                    {
                        notification.RegisterMessage("Email", "Email already exists!", Severity.Error);
                        _userRepository.Evict(entity);
                        return notification;
                    }
                }

                _userRepository.Save(entity);
            }
            else
            {
                _userRepository.Evict(entity);
            }
            return notification;
        }
示例#18
0
 public void Delete(User user)
 {
     var entity = user as Domain.User;
     if (entity != null) _userRepository.Delete(entity);
 }
示例#19
0
        public INotification Create(User user)
        {
            user.GravatarHash = user.Email.ToGravatarHash();

            return ValidateAndCreate(user);
        }
示例#20
0
        public string GetPassword(User user)
        {
            if(_settings.PasswordResetRetrievalSettings.RequiresQuestionAndAnswer)
                throw new InvalidOperationException("Password requires question and answer to retrieve");

            var entity = user as User;

            switch (_settings.Password.PasswordFormat)
            {
                case PasswordFormat.Hashed:
                    throw new InvalidOperationException("Hashed passwords cannot be retieved");
                    break;
                case PasswordFormat.Clear:
                    return entity.Password;
                    break;
                case PasswordFormat.Encrypted:
                    throw new NotImplementedException();
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
示例#21
0
 public virtual void AddUser(User user)
 {
     _users.Add(user);
 }