예제 #1
0
        public async Task <IActionResult> InviteUser([FromBody] UserInviteDto inviteDto)
        {
            if (inviteDto.RoleID.HasValue)
            {
                var role = Role.GetByRoleID(_dbContext, inviteDto.RoleID.Value);
                if (role == null)
                {
                    return(NotFound($"Could not find a Role with the ID {inviteDto.RoleID}"));
                }
            }
            else
            {
                return(BadRequest("Role ID is required."));
            }

            var welcomeText =
                $"You are receiving this notification because an administrator of the {_rioConfiguration.PlatformLongName}, an online service of the {_rioConfiguration.LeadOrganizationLongName}, has invited you to create an account.";
            var response = await KeystoneInviteUserApiResponse(inviteDto.FirstName, inviteDto.LastName, inviteDto.Email, welcomeText);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = GetAndUpdateUserFromEmailOrReturnNewUser(response, inviteDto.Email, (int)inviteDto.RoleID);

            return(Ok(user));
        }
        public ActionResult Index(Guid inviteKey)
        {
            UserInviteDto userInvite = this.userService.GetUserInvite(inviteKey);

            if (userInvite == null)
            {
                return(View("InvalidKey"));
            }

            return(View(new UserSetupModel()
            {
                Email = userInvite.Email, Key = inviteKey
            }));
        }
        public ActionResult Create(UserSetupModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            UserInviteDto userInvite = this.userService.GetUserInvite(model.Key);

            if (userInvite == null)
            {
                return(View("InvalidKey"));
            }

            this.createUser(model, userInvite.Email, false);

            return(RedirectToAction("Index", "Dashboard"));
        }
예제 #4
0
        public JsonResult Search(string term)
        {
            term = term.ToLower();

            List <UserSuggestionModel> suggestions = new List <UserSuggestionModel>();

            List <UserDto> users = this.userService.GetUsers();

            UserDto userFound = users.FirstOrDefault(user => user.Email == term);

            if (userFound != null)
            {
                suggestions.Add(Mapper.Map <UserDto, UserSuggestionModel>(userFound));
                return(Json(suggestions, JsonRequestBehavior.AllowGet));
            }

            List <UserInviteDto> userInvites = this.userService.GetUserInvites();

            UserInviteDto userInviteFound = userInvites.FirstOrDefault(userInvite => userInvite.Email == term);

            if (userInviteFound != null)
            {
                suggestions.Add(Mapper.Map <UserInviteDto, UserSuggestionModel>(userInviteFound));
                return(Json(suggestions, JsonRequestBehavior.AllowGet));
            }

            IEnumerable <UserDto>       usersFiltered       = users.Where(user => user.Email.Contains(term));
            IEnumerable <UserInviteDto> userInvitesFiltered = userInvites.Where(invite => invite.Email.Contains(term));

            suggestions.AddRange(Mapper.Map <IEnumerable <UserDto>, List <UserSuggestionModel> >(usersFiltered));
            suggestions.AddRange(Mapper.Map <IEnumerable <UserInviteDto>, List <UserSuggestionModel> >(userInvitesFiltered));

            suggestions.Add(new UserSuggestionModel());

            return(Json(suggestions, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public IActionResult InviteUser([FromBody] UserInviteDto inviteDto)
        {
            if (inviteDto.RoleID.HasValue)
            {
                var role = Role.GetByRoleID(_dbContext, inviteDto.RoleID.Value);
                if (role == null)
                {
                    return(BadRequest($"Could not find a Role with the ID {inviteDto.RoleID}"));
                }
            }
            else
            {
                return(BadRequest("Role ID is required."));
            }

            var applicationName          = $"{_nebulaConfiguration.PlatformLongName}";
            var leadOrganizationLongName = $"{_nebulaConfiguration.LeadOrganizationLongName}";
            var inviteModel = new KeystoneService.KeystoneInviteModel
            {
                FirstName      = inviteDto.FirstName,
                LastName       = inviteDto.LastName,
                Email          = inviteDto.Email,
                Subject        = $"Invitation to the {applicationName}",
                WelcomeText    = $"You are receiving this notification because an administrator of the {applicationName}, an online service of the {leadOrganizationLongName}, has invited you to create an account.",
                SiteName       = applicationName,
                SignatureBlock = $"{leadOrganizationLongName}<br /><a href='mailto:{_nebulaConfiguration.LeadOrganizationEmail}'>{_nebulaConfiguration.LeadOrganizationEmail}</a><a href='{_nebulaConfiguration.LeadOrganizationHomeUrl}'>{_nebulaConfiguration.LeadOrganizationHomeUrl}</a>",
                RedirectURL    = _nebulaConfiguration.KEYSTONE_REDIRECT_URL
            };

            var response = _keystoneService.Invite(inviteModel);

            if (response.StatusCode != HttpStatusCode.OK || response.Error != null)
            {
                ModelState.AddModelError("Email", $"There was a problem inviting the user to Keystone: {response.Error.Message}.");
                if (response.Error.ModelState != null)
                {
                    foreach (var modelStateKey in response.Error.ModelState.Keys)
                    {
                        foreach (var err in response.Error.ModelState[modelStateKey])
                        {
                            ModelState.AddModelError(modelStateKey, err);
                        }
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var keystoneUser = response.Payload.Claims;
            var existingUser = EFModels.Entities.User.GetByEmail(_dbContext, inviteDto.Email);

            if (existingUser != null)
            {
                existingUser = EFModels.Entities.User.UpdateUserGuid(_dbContext, existingUser.UserID, keystoneUser.UserGuid);
                return(Ok(existingUser));
            }

            var newUser = new UserUpsertDto
            {
                FirstName        = keystoneUser.FirstName,
                LastName         = keystoneUser.LastName,
                OrganizationName = keystoneUser.OrganizationName,
                Email            = keystoneUser.Email,
                PhoneNumber      = keystoneUser.PrimaryPhone,
                RoleID           = inviteDto.RoleID.Value
            };

            var user = EFModels.Entities.User.CreateNewUser(_dbContext, newUser, keystoneUser.LoginName,
                                                            keystoneUser.UserGuid);

            return(Ok(user));
        }