public void SendAccountUnlockCode(string username) { var user = _userReadRepository.Get(username); user.AssertState("Send unlock code", UserStatuses.Locked); var candidate = _candidateReadRepository.Get(user.EntityId); if (user.AccountUnlockCodeExpiry < DateTime.Now) { // Account unlock code has expired, renew it. _lockUserStrategy.LockUser(user); } var unlockCodeExpiryDays = _configurationManager.GetAppSetting <int>("UnlockCodeExpiryDays"); var firstName = candidate.RegistrationDetails.FirstName; var emailAddress = candidate.RegistrationDetails.EmailAddress; var accountUnlockCode = user.AccountUnlockCode; var expiryInDays = string.Format(unlockCodeExpiryDays == 1 ? "{0} day" : "{0} days", unlockCodeExpiryDays); var tokens = new[] { new CommunicationToken(CommunicationTokens.CandidateFirstName, firstName), new CommunicationToken(CommunicationTokens.Username, emailAddress), new CommunicationToken(CommunicationTokens.AccountUnlockCode, accountUnlockCode), new CommunicationToken(CommunicationTokens.AccountUnlockCodeExpiryDays, expiryInDays) }; _communicationService.SendMessageToCandidate( candidate.EntityId, MessageTypes.SendAccountUnlockCode, tokens); }
public void LockAccount(User user) { _lockUserStrategy.LockUser(user); _sendAccountUnlockCodeStrategy.SendAccountUnlockCode(user.Username); }