Beispiel #1
0
        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));
                }
            }
        }
Beispiel #2
0
        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));
                }
            }
        }