コード例 #1
0
        public ActionResult Edit(Guid id, string firstName, string lastName, string emailAddress, string phoneNumber, string organisationName, string loginId)
        {
            Employer         employer    = null;
            LoginCredentials credentials = null;

            try
            {
                employer = _employersQuery.GetEmployer(id);
                if (employer == null)
                {
                    return(NotFound("employer", "id", id));
                }

                credentials = _loginCredentialsQuery.GetCredentials(employer.Id);
                if (credentials == null)
                {
                    return(NotFound("employer", "id", id));
                }

                // Update the employer.

                employer.FirstName    = firstName;
                employer.LastName     = lastName;
                employer.EmailAddress = string.IsNullOrEmpty(emailAddress) ? null : new EmailAddress {
                    Address = emailAddress
                };
                employer.PhoneNumber = _phoneNumbersQuery.GetPhoneNumber(phoneNumber, ActivityContext.Location.Country);

                // Update the organisation but only for verified organisations.

                if (employer.Organisation.IsVerified && organisationName != employer.Organisation.FullName)
                {
                    employer.Organisation = _organisationsQuery.GetVerifiedOrganisation(organisationName);
                }

                _employerAccountsCommand.UpdateEmployer(employer);

                // Update the credentials.

                credentials.LoginId = loginId;
                _loginCredentialsCommand.UpdateCredentials(employer.Id, credentials, User.Id().Value);
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View(new UserModel <IEmployer, EmployerLoginModel>
            {
                User = employer,
                UserLogin = new EmployerLoginModel {
                    LoginId = credentials == null ? null : credentials.LoginId
                },
            }));
        }
コード例 #2
0
        public void TestUpdateDuplicateAccounts()
        {
            _custodianAccountsCommand.CreateTestCustodian(LoginId1, Guid.NewGuid());
            var custodian        = _custodianAccountsCommand.CreateTestCustodian(LoginId2, Guid.NewGuid());
            var loginCredentials = _loginCredentialsQuery.GetCredentials(custodian.Id);

            loginCredentials.LoginId = LoginId1;
            _loginCredentialsCommand.UpdateCredentials(custodian.Id, loginCredentials, custodian.Id);
        }
コード例 #3
0
        public void TestUpdateDuplicateAccounts()
        {
            _employerAccountsCommand.CreateTestEmployer(LoginId1, _organisationsCommand.CreateTestOrganisation(0));
            var employer         = _employerAccountsCommand.CreateTestEmployer(LoginId2, _organisationsCommand.CreateTestOrganisation(1));
            var loginCredentials = _loginCredentialsQuery.GetCredentials(employer.Id);

            loginCredentials.LoginId = LoginId1;
            _loginCredentialsCommand.UpdateCredentials(employer.Id, loginCredentials, employer.Id);
        }
コード例 #4
0
        public void TestUpdateDuplicateAccounts()
        {
            _administratorAccountsCommand.CreateTestAdministrator(LoginId1);
            var administrator    = _administratorAccountsCommand.CreateTestAdministrator(LoginId2);
            var loginCredentials = _loginCredentialsQuery.GetCredentials(administrator.Id);

            loginCredentials.LoginId = LoginId1;
            _loginCredentialsCommand.UpdateCredentials(administrator.Id, loginCredentials, administrator.Id);
        }
コード例 #5
0
        private void UpdateCredentials(Guid memberId, LoginCredentials credentials, string emailAddress)
        {
            // Check that they have login credentials first because they may only have other types of credentials.

            if (credentials != null)
            {
                credentials.LoginId = emailAddress;
                _loginCredentialsCommand.UpdateCredentials(memberId, credentials, memberId);
            }
        }
コード例 #6
0
        public ActionResult ChangePassword(Guid id, MemberLoginModel memberLogin, [Bind(Include = "SendPasswordEmail")] CheckBoxValue sendPasswordEmail)
        {
            var member = _membersQuery.GetMember(id);

            if (member == null)
            {
                return(NotFound("member", "id", id));
            }

            var credentials = _loginCredentialsQuery.GetCredentials(member.Id);

            if (credentials == null)
            {
                return(NotFound("member", "id", id));
            }

            try
            {
                // Validate.

                memberLogin.SendPasswordEmail = sendPasswordEmail.IsChecked;
                memberLogin.Validate();

                // Update.

                credentials.PasswordHash       = LoginCredentials.HashToString(memberLogin.Password);
                credentials.MustChangePassword = true;
                _loginCredentialsCommand.UpdateCredentials(member.Id, credentials, User.Id().Value);

                string message;
                if (memberLogin.SendPasswordEmail)
                {
                    var reminderEmail = new PasswordReminderEmail(member, credentials.LoginId, memberLogin.Password);
                    _emailsCommand.TrySend(reminderEmail);
                    message = "The password has been reset and an email has been sent.";
                }
                else
                {
                    message = "The password has been reset.";
                }

                return(RedirectToRouteWithConfirmation(MembersRoutes.Edit, new { id }, message));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            memberLogin.LoginId = credentials.LoginId;
            return(View("Edit", new UserModel <IMember, MemberLoginModel>
            {
                User = _membersQuery.GetMember(id),
                UserLogin = memberLogin
            }));
        }
コード例 #7
0
        public void TestUserMustChangePassword()
        {
            var employer = _employerAccountsCommand.CreateTestEmployer(0, _organisationsCommand.CreateTestOrganisation(0));

            var credentials = _loginCredentialsQuery.GetCredentials(employer.Id);

            credentials.MustChangePassword = true;
            _loginCredentialsCommand.UpdateCredentials(employer.Id, credentials, Guid.NewGuid());

            AssertJsonError(LogIn(HttpStatusCode.Forbidden, employer.GetLoginId(), employer.GetPassword()), null, "103", "The user must change their password.");
        }
コード例 #8
0
        private void UpdateCredentials(Guid employerId, LoginCredentials credentials, string loginId, string password, string confirmPassword, bool useLinkedInProfile)
        {
            if (credentials == null)
            {
                if (!string.IsNullOrEmpty(loginId) || !string.IsNullOrEmpty(password) || !string.IsNullOrEmpty(confirmPassword))
                {
                    // No existing credentials but trying to create some.

                    var credentialsModel = new LoginCredentialsModel {
                        LoginId = loginId, Password = password, ConfirmPassword = confirmPassword
                    };
                    credentialsModel.Validate();

                    _loginCredentialsCommand.CreateCredentials(employerId, new LoginCredentials {
                        LoginId = loginId, PasswordHash = LoginCredentials.HashToString(password)
                    });
                }
            }
            else
            {
                if (loginId != credentials.LoginId)
                {
                    // Cannot remove the login id.

                    if (string.IsNullOrEmpty(loginId))
                    {
                        throw new ValidationErrorsException(new RequiredValidationError("LoginId"));
                    }

                    // Check not trying to someone else's login id.

                    if (_loginCredentialsQuery.DoCredentialsExist(new LoginCredentials {
                        LoginId = loginId
                    }))
                    {
                        throw new DuplicateUserException();
                    }

                    // Update the credentials.

                    credentials.LoginId = loginId;
                    _loginCredentialsCommand.UpdateCredentials(employerId, credentials, employerId);
                }

                // If not wanting to use LinkedIn any more then remove the profile.

                if (!useLinkedInProfile)
                {
                    _linkedInCommand.DeleteProfile(employerId);
                }
            }
        }
コード例 #9
0
        public static void UpdateInvalidMember(this IMemberAccountsCommand memberAccountsCommand, Member member)
        {
            // Keep track of changes.

            var originalCredentials = LoginCredentialsQuery.GetCredentials(member.Id);

            // Save.

            MembersRepository.UpdateMember(member);

            originalCredentials.LoginId = member.GetBestEmailAddress().Address;
            LoginCredentialsCommand.UpdateCredentials(member.Id, originalCredentials, member.Id);
        }
コード例 #10
0
        public ActionResult ChangePassword(Guid id, CustodianLoginModel custodianLogin)
        {
            var custodian = _custodiansQuery.GetCustodian(id);

            if (custodian == null)
            {
                return(NotFound("custodian", "id", id));
            }

            var credentials = _loginCredentialsQuery.GetCredentials(custodian.Id);

            if (credentials == null)
            {
                return(NotFound("custodian", "id", id));
            }

            try
            {
                // Validate.

                custodianLogin.Validate();

                // Update.

                credentials.PasswordHash = LoginCredentials.HashToString(custodianLogin.Password);
                _loginCredentialsCommand.UpdateCredentials(custodian.Id, credentials, User.Id().Value);
                const string message = "The password has been reset.";

                return(RedirectToRouteWithConfirmation(CustodiansRoutes.Edit, new { id }, message));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            custodianLogin.LoginId = credentials.LoginId;
            return(View("Edit", new CustodianUserModel
            {
                User = _custodiansQuery.GetCustodian(id),
                UserLogin = custodianLogin,
                Community = _communitiesQuery.GetCommunity(custodian.AffiliateId.Value),
            }));
        }
コード例 #11
0
        public ActionResult ChangePassword(Guid id, AdministratorLoginModel administratorLogin)
        {
            var administrator = _administratorsQuery.GetAdministrator(id);

            if (administrator == null)
            {
                return(NotFound("administrator", "id", id));
            }

            var credentials = _loginCredentialsQuery.GetCredentials(id);

            if (credentials == null)
            {
                return(NotFound("administrator", "id", id));
            }

            try
            {
                // Validate.

                administratorLogin.Validate();

                // Update.

                credentials.PasswordHash = LoginCredentials.HashToString(administratorLogin.Password);
                _loginCredentialsCommand.UpdateCredentials(administrator.Id, credentials, User.Id().Value);
                const string message = "The password has been reset.";

                return(RedirectToRouteWithConfirmation(AdministratorsRoutes.Edit, new { id }, message));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            administratorLogin.LoginId = credentials.LoginId;
            return(View("Edit", new UserModel <Administrator, AdministratorLoginModel>
            {
                User = _administratorsQuery.GetAdministrator(id),
                UserLogin = administratorLogin,
            }));
        }
コード例 #12
0
        public void TestAuthenticateMustChangePassword()
        {
            var member      = _memberAccountsCommand.CreateTestMember(EmailAddress, Password, FirstName, LastName);
            var credentials = _loginCredentialsQuery.GetCredentials(member.Id);

            credentials.MustChangePassword = true;
            _loginCredentialsCommand.UpdateCredentials(member.Id, credentials, Guid.NewGuid());

            // Normal login.

            var loginAuthenticationCommand = CreateLoginAuthenticationCommand(false, null);

            Assert.AreEqual(AuthenticationStatus.AuthenticatedMustChangePassword, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = Password
            }).Status);

            // Bad password.

            Assert.AreEqual(AuthenticationStatus.Failed, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = "******"
            }).Status);

            // Override password not enabled.

            Assert.AreEqual(AuthenticationStatus.Failed, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = OverridePassword
            }).Status);

            // Override enabled.

            loginAuthenticationCommand = CreateLoginAuthenticationCommand(true, EncryptedOverridePassword);
            Assert.AreEqual(AuthenticationStatus.AuthenticatedMustChangePassword, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = Password
            }).Status);
            Assert.AreEqual(AuthenticationStatus.AuthenticatedWithOverridePassword, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = OverridePassword
            }).Status);

            // Disabled.

            member.IsEnabled   = false;
            member.IsActivated = true;
            _memberAccountsCommand.UpdateMember(member);
            Assert.AreEqual(AuthenticationStatus.Disabled, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = Password
            }).Status);
            Assert.AreEqual(AuthenticationStatus.AuthenticatedWithOverridePassword, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = OverridePassword
            }).Status);

            // Deactivated with override.

            member.IsEnabled   = true;
            member.IsActivated = false;
            _memberAccountsCommand.UpdateMember(member);
            Assert.AreEqual(AuthenticationStatus.AuthenticatedMustChangePassword, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = Password
            }).Status);
            Assert.AreEqual(AuthenticationStatus.AuthenticatedWithOverridePassword, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = OverridePassword
            }).Status);

            // Both fail.

            Assert.AreEqual(AuthenticationStatus.Failed, loginAuthenticationCommand.AuthenticateUser(new LoginCredentials {
                LoginId = EmailAddress, Password = "******"
            }).Status);
        }