示例#1
0
        /// <summary>
        /// Maps an EF user record from the db into a UserMicroSummary object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbUser">User record from the database.</param>
        public virtual UserMicroSummary Map(User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            var user = new UserMicroSummary()
            {
                Email     = dbUser.Email,
                FirstName = dbUser.FirstName,
                LastName  = dbUser.LastName,
                UserId    = dbUser.UserId,
                Username  = dbUser.Username
            };

            var userArea = _userAreaRepository.GetByCode(dbUser.UserAreaCode);

            EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode);

            user.UserArea = new UserAreaMicroSummary()
            {
                UserAreaCode = dbUser.UserAreaCode,
                Name         = userArea.Name
            };

            return(user);
        }
示例#2
0
        private void ValidatePermission(GetUserSummaryByIdQuery query, IExecutionContext executionContext, UserMicroSummary user)
        {
            if (user == null)
            {
                return;
            }

            if (user.UserArea.UserAreaCode == CofoundryAdminUserArea.AreaCode)
            {
                _permissionValidationService.EnforceCurrentUserOrHasPermission <CofoundryUserReadPermission>(query.UserId, executionContext.UserContext);
            }
            else
            {
                _permissionValidationService.EnforceCurrentUserOrHasPermission <NonCofoundryUserReadPermission>(query.UserId, executionContext.UserContext);
            }
        }
        /// <summary>
        /// Changes a users password, without sending them an email notification
        /// </summary>
        /// <param name="controller">Controller instance</param>
        /// <param name="vm">The IChangePasswordTemplate containing the data entered by the user.</param>
        private void ChangePassword(Controller controller, IChangePasswordViewModel vm, UserMicroSummary user)
        {
            if (controller.ModelState.IsValid)
            {
                if (user == null)
                {
                    throw new NotPermittedException("User not logged in");
                }

                var command = new UpdateCurrentUserUserPasswordCommand();
                command.NewPassword = vm.NewPassword;
                command.OldPassword = vm.OldPassword;
                _controllerResponseHelper.ExecuteIfValid(controller, command);
            }
        }