Example #1
0
        public async Task <IActionResult> OrgUserEdit(int?edit_oRG_USER_IDX, string uidx, string org_id, string AccessLevel, string StatusInd)
        {
            if (ModelState.IsValid)
            {
                int newID = _DbPortal.InsertUpdateT_PRT_ORG_USERS(edit_oRG_USER_IDX, org_id, uidx, AccessLevel, StatusInd, User.Identity.Name);

                if (newID == 0)
                {
                    TempData["Error"] = "Unable to add user to organization.";
                }
                else
                {
                    WordPressHelper wordPressHelper = new WordPressHelper(_userManager, _DbPortal, _log, _emailSender);
                    int             isWPUserAdded   = await wordPressHelper.SetupWordPressAccess(uidx, org_id, AccessLevel, StatusInd);

                    TempData["Success"] = "Record successfully added.";
                }
            }
            else
            {
                TempData["Error"] = "Unable to add user to organization.";
            }

            return(RedirectToAction("UserEdit", "Admin", new { id = uidx }));
        }
        public async Task <IActionResult> PortalRegister(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName   = model.Email,
                    Email      = model.Email,
                    FIRST_NAME = model.FirstName,
                    LAST_NAME  = model.LastName
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    //Encrypt and store password to database
                    //used for WordPress user management
                    var _user = await _userManager.FindByEmailAsync(model.Email);

                    if (_user != null)
                    {
                        _DbPortal.UpdateT_PRT_USERS_PasswordEncrypt(_user, model.Password);
                    }

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var  callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    bool emailSucc   = _emailSender.SendEmail(null, model.Email, null, null, null, null, "EMAIL_CONFIRM", "callbackUrl", callbackUrl);
                    //_log.InsertT_PRT_SYS_LOG("info-cburl", callbackUrl);

                    //if users email is associated with an organization, then associate user with org
                    List <T_PRT_ORGANIZATIONS> orgs = _DbPortal.GetT_PRT_ORGANIZATIONS_ByEmail(model.Email);
                    if (orgs != null && orgs.Count == 1)
                    {
                        _DbPortal.InsertUpdateT_PRT_ORG_USERS(null, orgs[0].ORG_ID, user.Id, "U", "A", user.Id);
                    }

                    TempData["Success"]       = "Account has been created. Please check your email to verify your account.";
                    TempData["toastrTimeout"] = "true";
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }