public BatchExecutionResults2 GenerateSendPasswords(int[] personKeys) { BatchExecutionResults2 batchExecutionResults = new BatchExecutionResults2(); int[] filteredPersonKeys = getPersonKeysWhere(personKeys, p => p.NeedsPasswordSending); foreach (int personKey in filteredPersonKeys) generateSendPassword(personKey, batchExecutionResults); return batchExecutionResults; }
public BatchExecutionResults2 GenerateSendLogins(int[] personKeys) { BatchExecutionResults2 batchExecutionResults = new BatchExecutionResults2(); LetterPrintCommand letterPrintCommand = null; using (IDalSession session = NHSessionFactory.CreateSession()) { letterPrintCommand = new LetterPrintCommand(session, "LetterLoginName", "Letters"); } int[] filteredPersonKeys = getPersonKeysWhere(personKeys, p => p.NeedsLoginSending); foreach (int personKey in filteredPersonKeys) generateSendLogin(personKey, false, letterPrintCommand, batchExecutionResults); return batchExecutionResults; }
private void generateSendPassword(int personKey, BatchExecutionResults2 batchExecutionResults) { using (IDalSession session = NHSessionFactory.CreateSession()) { string personErrorString = personKey.ToString(); try { AssertUserHasPermissions(session); LoginPerson loginPerson = GetOwnedLoginPerson(session, personKey); personErrorString = string.Format("{0} ('{1}')", loginPerson.PersonKey, loginPerson.FullName); SetPassword(session, loginPerson, PasswordEmailType.FirstTime); batchExecutionResults.MarkSuccess(); } catch (Exception ex) { batchExecutionResults.MarkError( new ApplicationException(string.Format("Error sending password to {0} {1}.", PersonType, personErrorString), ex)); } } }
private void generateSendLogin(int personKey, bool isActive, LetterPrintCommand letterPrintCommand, BatchExecutionResults2 batchExecutionResults) { using (IDalSession session = NHSessionFactory.CreateSession()) { string personErrorString = personKey.ToString(); try { AssertUserHasPermissions(session); LoginPerson loginPerson = GetOwnedLoginPerson(session, personKey); personErrorString = string.Format("{0} ('{1}')", loginPerson.PersonKey, loginPerson.FullName); string userName = generateUniqueUserName(session, loginPerson.ShortNameAlphaCharsOnly, 3, 5); string password = SecurityManager.GeneratePassword(passwordLength); string[] initialClientUserRoleList = loginPerson.InitialClientUserRoleList; loginPerson.AssertAddressIsComplete(); loginPerson.AssertHasEmail(); SecurityManager.CreateUser(userName, password, loginPerson.Email, isActive); IExternalLogin blankLogin = CreateBlankLogin(); blankLogin.UserName = userName; blankLogin.IsActive = isActive; loginPerson.Login = blankLogin; LoginMapper.Insert(session, blankLogin); try { foreach (string roleName in initialClientUserRoleList) SecurityManager.AddUserToRole(userName, roleName); letterPrintCommand.PrintLetter(userName, loginPerson); } catch { deleteLogin(session, loginPerson); throw; } batchExecutionResults.MarkSuccess(); } catch (Exception ex) { batchExecutionResults.MarkError( new ApplicationException(string.Format("Error sending login name to {0} {1}.", PersonType, personErrorString), ex)); } } }