Exemplo n.º 1
0
        public UserHeader CreateActiveUser(string id, string password, string phrase, Role role)
        {
            var email = id + "@arb.org.uk";
            var salt = _passwordManager.GenerateSalt();
            var hashedPassword = _passwordManager.HashPassword(password, salt);
            var enctyptedSecurePhrase = _passwordManager.EncryptSecurePhrase(phrase);

            var existingUser = _database.GetUserByEmail(email);
            if (existingUser == null)
            {
                var user = new UserData
                {
                    Id = Guid.NewGuid(),
                    Email = email,
                    FirstName = "User",
                    LastName = id,
                    Role = role,
                    UserState = UserState.Activated,
                    HashedPassword = hashedPassword,
                    PasswordSalt = salt,
                    EncryptedSecurePhrase = enctyptedSecurePhrase,
                    FirstSecurePhraseQuestionCharacterIndex = 0,
                    SecondSecurePhraseQuestionCharacterIndex = 1
                };
                _database.CreateUser(user);
                return user;
            }
            else
            {
                existingUser.HashedPassword = hashedPassword;
                existingUser.PasswordSalt = salt;
                existingUser.EncryptedSecurePhrase = enctyptedSecurePhrase;
                existingUser.FirstSecurePhraseQuestionCharacterIndex = 0;
                existingUser.SecondSecurePhraseQuestionCharacterIndex = 1;
                existingUser.UserState = UserState.Activated;
                _database.UpdateUser(existingUser);
                return existingUser;
            }
        }
Exemplo n.º 2
0
 private static int GetMaxUsersAssignedToCase(Role role)
 {
     if (role == Role.Admin || role == Role.None || role == Role.System) return 0;
     if (role == Role.CaseWorker) return 1;
     if (role == Role.PanelMember) return 3;
     if (role == Role.Inquirer || role == Role.Solicitor || role == Role.ThirdPartyReviewer) return int.MaxValue;
     throw new ArgumentException("unknown user role");
 }
Exemplo n.º 3
0
 public OverAssignmentException(int caseId, Role role, UserHeader[] alreadyAssigned)
 {
     CaseId = caseId;
     Role = role;
     AlreadyAssigned = alreadyAssigned;
 }
Exemplo n.º 4
0
 private void CheckOverassignment(int caseId, Role role)
 {
     var assignedUsers = _database.GetAssignedUsers(caseId);
     var assignedUsersInRole = assignedUsers.Where(item => item.Role == role).ToArray();
     var count = assignedUsersInRole.Length;
     var maxCount = GetMaxUsersAssignedToCase(role);
     if (count >= maxCount) throw new OverAssignmentException(caseId, role, assignedUsersInRole);
 }