private bool IsCredentialsValid(string mail, string password)
        {
            var relatedUserWithWebMasterRole = Optional(_intranetUserService.GetByEmail(mail))
                                               .Filter(member => member.Role.Name == IntranetRolesEnum.WebMaster.ToString())
                                               .Bind(member => member.UmbracoId.ToOption())
                                               .Map(id => _memberService.GetById(id));

            Option <IMember> GetUserWithMatchingEmail() => Optional(_memberService.GetByEmail(mail));

            return(EnumerableExtensions
                   .Choose(relatedUserWithWebMasterRole, GetUserWithMatchingEmail)
                   .Map(user => Membership.ValidateUser(user.Username, password))
                   .IfNone(() => false));
        }
Beispiel #2
0
        private void SaveUsers(string domain, bool updateExisting,
                               UserCredential userCredential, out Exception exception)
        {
            exception = null;
            try
            {
                var service = new DirectoryService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = userCredential,
                    ApplicationName       = "Uintra"
                });

                var request = service.Users.List();
                request.Domain  = domain;
                request.OrderBy = UsersResource.ListRequest.OrderByEnum.Email;
                var users = request.Execute().UsersValue.ToList();

                foreach (var user in users)
                {
                    var email        = user.Emails.First().Address;
                    var existingUser = _intranetUserService.GetByEmail(email);

                    if (existingUser != null)
                    {
                        if (updateExisting)
                        {
                            var updateUserDto = user.Map <UpdateUserDto>();
                            updateUserDto.Id       = existingUser.Id;
                            updateUserDto.NewMedia = GetMediaId(user, service);
                            _intranetUserService.Update(updateUserDto);
                        }
                    }
                    else
                    {
                        var createUserDto = user.Map <CreateUserDto>();
                        createUserDto.MediaId = GetMediaId(user, service);
                        _intranetUserService.Create(createUserDto);
                    }
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
        }
Beispiel #3
0
        public virtual IHttpActionResult Create(CreateUserDto createModel)
        {
            if (ModelState.IsValid)
            {
                var user = _intranetUserService.GetByEmail(createModel.Email);
                if (user != null)
                {
                    return(Conflict());
                }

                var id = _intranetUserService.Create(createModel);

                return(Ok(id));
            }
            else
            {
                return(BadRequest(GetModelErrors()));
            }
        }