Ejemplo n.º 1
0
        public async Task <IActionResult> Login(LoginViewModel loginVM, string returnUrl)
        {
            GolfioUser   golfioUser = new GolfioUser();
            bool         isValidLogin;
            SignInResult signInResult;

            if (!ModelState.IsValid)
            {
                return(View(loginVM));
            }

            golfioUser = await _golfioUser.GetUserAsync(loginVM.Email);

            if (golfioUser == null)
            {
                TempData["MessageTitle"] = "Login Failed";
                TempData["Message"]      = "Invalid Login Attempt";
                return(View(loginVM));
            }

            isValidLogin = await _golfioUser.IsValidLoginAsync(golfioUser, loginVM.Password);

            if (!isValidLogin)
            {
                TempData["MessageTitle"] = "Login Failed";
                TempData["Message"]      = "Invalid Login Attempt";
                return(View(loginVM));
            }

            signInResult = await _golfioUser.SignInUserAsync(loginVM);

            if (!signInResult.Succeeded)
            {
                TempData["MessageTitle"] = "Login Failed";
                TempData["Message"]      = "Invalid Login Attempt";
                return(View(loginVM));
            }

            HttpContext.Session.SetString("FullName", golfioUser.FullName);

            if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(string userId)
        {
            // Get user information
            GolfioUser golfioUser = await _golfioUser.GetUserAsync(userId);

            AdminEditViewModel adminEditVM = new AdminEditViewModel()
            {
                UserId    = golfioUser.Id,
                FirstName = golfioUser.FirstName,
                LastName  = golfioUser.LastName,
                Email     = golfioUser.Email,
            };

            // Get user claim(s)
            List <Claim> claims = await _golfioUser.GetUserClaimsAsync(golfioUser);

            foreach (var claimType in Enum.GetValues(typeof(ClaimType)).Cast <ClaimType>())
            {
                ClaimInfo claimInfo = new ClaimInfo()
                {
                    ClaimType  = claimType.ToString(),
                    IsSelected = false,
                };

                adminEditVM.ClaimInfos.Add(claimInfo);
            }

            foreach (var claim in claims)
            {
                ClaimInfo claimInfo = adminEditVM.ClaimInfos.FirstOrDefault(ci => ci.ClaimType == claim.Type.ToString());
                claimInfo.IsSelected = Convert.ToBoolean(claim.Value);
            }

            return(View(adminEditVM));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit()
        {
            UserEditViewModel userEditVM = new UserEditViewModel();
            List <string>     claimTypes = new List <string>();

            string userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            userEditVM.GolfioUser = await _golfioUser.GetUserAsync(userId);

            (await _golfioUser.GetUserClaimsAsync(userEditVM.GolfioUser))
            .ForEach(uc => claimTypes.Add(uc.Type.ToString()));

            userEditVM.UserClaims = string.Join(", ", claimTypes);

            return(View(userEditVM));
        }