Esempio n. 1
0
        public async Task <JsonResult> OrgUserDelete(int id, string id2)
        {
            T_PRT_ORG_USERS orgUser = _DbPortal.GetT_PRT_ORG_USERS_ByOrgUserID(id);
            int             succId  = _DbPortal.DeleteT_PRT_ORG_USERS(orgUser);

            if (succId > 0)
            {
                WordPressHelper.SetUserManager(_userManager);
                ApplicationUser appUser = await WordPressHelper.GetApplicationUser(orgUser.Id);

                WordPressHelper wordPressHelper = new WordPressHelper(_userManager, _DbPortal, _log, _emailSender);
                int             orgUserCount    = _DbPortal.GetOrgUsersCount(orgUser.Id);
                if (orgUserCount == 0)
                {
                    //if we have user in wordpress, make it inactive
                    if (appUser.WordPressUserId > 0)
                    {
                        //string wordPressUri = wordPressHelper.SetWordPressUri(orgUser.ORG_ID);
                        // string userName = wordPressHelper.GetUserName();
                        // string password = wordPressHelper.GetPassword();
                        int.TryParse(appUser.WordPressUserId.ToString(), out var wpuid);
                        //WordPressClient wordPressClient = await wordPressHelper.GetAuthenticatedWordPressClient(wordPressUri, userName, password);
                        WordPressClient wordPressClient = await wordPressHelper.GetAuthenticatedWordPressClient(orgUser.ORG_ID);

                        bool isUserUpdated = await wordPressHelper.UpdateWordPressUser(appUser, wordPressClient, wpuid, "inactive");
                    }
                }
                else
                {
                    //revoke access from the site/organization from wordpress
                    int.TryParse(appUser.WordPressUserId.ToString(), out var wpuid);
                    wordPressHelper.AddRemoveUserSite(wpuid, orgUser.ORG_ID, 0);
                }
                return(Json("Success"));
            }
            else
            {
                return(Json("Unable to delete user from organization."));
            }
        }
Esempio n. 2
0
        public JsonResult AccessRightsRequest(int?orgUser, string client)
        {
            string _UserIDX = _userManager.GetUserId(User);

            T_PRT_ORG_USERS _ou = _DbPortal.GetT_PRT_ORG_USERS_ByOrgUserID(orgUser ?? -1);

            if (_ou != null)
            {
                int SuccID = _DbPortal.InsertUpdateT_PRT_ORG_USERS_CLIENT(null, orgUser, client, false, "R", _UserIDX);

                //return response
                if (SuccID > 0)
                {
                    //send email
                    List <string> _emailRecipients = new List <string>();

                    //**************first try to send to org / client admins
                    List <OrgUserClientDisplayType> _orgUserClientAdmins = _DbPortal.GetT_PRT_ORG_USERS_CLIENT_ByOrgIDandClientID(_ou.ORG_ID, client, true);
                    if (_orgUserClientAdmins != null && _orgUserClientAdmins.Count > 0)
                    {
                        foreach (OrgUserClientDisplayType _orgUserClientAdmin in _orgUserClientAdmins)
                        {
                            ApplicationUser _u = _userManager.FindByIdAsync(_orgUserClientAdmin.UserID).Result;
                            if (_u != null)
                            {
                                _emailRecipients.Add(_u.Email);
                            }
                        }
                    }

                    //**************if none found, then send to org admins

                    //**************finally send to portal admins
                    if (_emailRecipients.Count == 0)
                    {
                        IdentityRole _r = _roleManager.FindByNameAsync("PortalAdmin").Result;

                        IEnumerable <ApplicationUser> _us = _DbPortal.GetT_PRT_USERS_BelongingToRole(_r.Id);
                        if (_us != null)
                        {
                            foreach (ApplicationUser _u in _us)
                            {
                                _emailRecipients.Add(_u.Email);
                            }
                        }
                    }

                    string _UserName = _userManager.GetUserName(User);

                    //construct email parameters
                    List <emailParam> emailParams = new List <emailParam>()
                    {
                        new emailParam()
                        {
                            PARAM_NAME = "userName", PARAM_VAL = _UserName
                        },
                        new emailParam()
                        {
                            PARAM_NAME = "client", PARAM_VAL = client
                        },
                        new emailParam()
                        {
                            PARAM_NAME = "orgID", PARAM_VAL = _ou.ORG_ID
                        }
                    };

                    foreach (string _emailRecipient in _emailRecipients)
                    {
                        _emailSender.SendEmail(null, _emailRecipient, null, null, null, null, "ACCESS_REQUEST", emailParams);
                    }


                    return(Json(new
                    {
                        msg = "Success",
                        redirectUrl = Url.Action("AccessRights", "Manage")
                    }));
                }
            }

            //if got this far, it failed
            return(Json(new { msg = "Unable to request access." }));
        }