public async Task<IActionResult> Index(SearchViewModel model)
 {
     // Get the user and the UserType claim
     var user = await _userManager.FindByEmailAsync(model.Email);
     var claims = await _userManager.GetClaimsAsync(user);
     if (claims.Count <= 0)
     {
         model.TenantAdmin = false;
         return View("MakeUserTenantAdmin", model);
     }
     var claimValue = claims.FirstOrDefault(c => c.Type.Equals("UserType")).Value;
     if (!claimValue.Equals("TenantAdmin"))
     {
         model.TenantAdmin = false;
     }
     return View("MakeUserTenantAdmin", model);
 }
        public async Task<IActionResult> MakeUserTenantAdmin(SearchViewModel model, bool diff)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);
            if (model.TenantAdmin)
            {
                var result = await _userManager.AddClaimAsync(user, new Claim("UserType", "TenantAdmin"));
                if(result.Succeeded)
                {
                    ViewData["result"] = "Successfully approved user";
                    return View();
                }
                else
                {
                    ViewData["result"] = "Successfully approved user";
                    return Redirect("Error");
                }

            }
            return RedirectToAction("Index");
        }
Example #3
0
        public async Task<IActionResult> MakeUserTenantAdmin(SearchViewModel model, bool diff)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);
            if (model.TenantAdmin)
            {
                var result = await _userManager.AddClaimAsync(user, new Claim("UserType", "TenantAdmin"));
                if (result.Succeeded)
                {
                    ViewData["result"] = "Successfully made user a tenant admin";
                    var callbackUrl = Url.Action("Login", "Admin", new { Email = model.Email }, protocol: Context.Request.Scheme);
                    await _emailSender.SendEmailAsync(model.Email, "Account Approval", "Your account has been approved by an administrator. Please <a href=" + callbackUrl + ">Click here to Log in</a>");
                    return View();
                }
                else
                {
                    return Redirect("Error");
                }

            }
            return RedirectToAction("Index");
        }
Example #4
0
        public async Task<IActionResult> Index(SearchViewModel model)
        {
            // Get the user and the UserType claim
            var user = await _userManager.FindByEmailAsync(model.Email);
            if(user == null)
            {
                ViewBag.UserSearchError = string.Format("Sorry, no accounts were found with the address {0}", model.Email);
                return View(model);
            }

            var claims = await _userManager.GetClaimsAsync(user);
            if (claims.Count <= 0)
            {
                model.TenantAdmin = false;
                return View("MakeUserTenantAdmin", model);
            }
            var claimValue = claims.FirstOrDefault(c => c.Type.Equals("UserType")).Value;
            if (!claimValue.Equals("TenantAdmin"))
            {
                model.TenantAdmin = false;
            }
            return View("MakeUserTenantAdmin", model);
        }
Example #5
0
 public IActionResult MakeUserTenantAdmin(SearchViewModel model)
 {
     return View(model);
 }