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); }
public IEnumerable<TimeRecord> FindAll(User user, int limit) { return _timeRecordRepository.Query() .Where(x => x.User == user) .OrderByDescending(x => x.StartTime) .Take(limit) .ToList(); }
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()); }
public INotification RegisterUser(User user) { var notification = _userService.Create(user); if (notification.IsValid()) SendConfirmationEmail(user); return notification; }
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; }
public void ChangePasswordQuestionAndAnswer(User user, string password, string question, string answer) { throw new NotImplementedException(); }
private void ValidateAndSave(User entity) { var results = _validator.Validate(entity); if (results.IsValid()) _userRepository.Save(entity); }
private void addDefaultAdmin() { _user = new SuperUser("KokugenAdmin", "*****@*****.**", "K0kugen@dmin"); _userService.Create(_user); }
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()); }
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; }
public void ResetPassword(User user) { if (!_settings.PasswordResetRetrievalSettings.EnablePasswordReset) throw new InvalidOperationException("Password reset is not enabled"); var newPassword = resetPassword(user); emailUserNewPassword(newPassword, user); }
public void Unlock(User entity) { entity.Unlock(); ValidateAndSave(entity); }
public virtual void RemoveUser(User user) { if (_users.Contains(user)) _users.Remove(user); }
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); }
public string GetPassword(User user, string passwordAnswer) { throw new NotImplementedException(); }
public INotification Update(User user) { return ValidateAndUpdate(user); }
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; }
public void Delete(User user) { var entity = user as Domain.User; if (entity != null) _userRepository.Delete(entity); }
public INotification Create(User user) { user.GravatarHash = user.Email.ToGravatarHash(); return ValidateAndCreate(user); }
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(); } }
public virtual void AddUser(User user) { _users.Add(user); }