public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                Member member = await MemberDb.IsLoginValid(model, _context);

                if (member != null)
                {
                    TempData["Message"] = "Logged in successfully";
                    SessionHelper.LogUserIn(_httpContext, member.MemberId, member.UserName);
                }
                else//Credentials invalid
                {
                    //Adding model error with no key, will display error
                    //message in the validation summary
                    ModelState.AddModelError("BadCredentials", "i'm sorry, your credential did not match any record in our database");
                }
            }
            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                Member member = await MemberDb.IsLoginValid(model, _context);

                if (member != null)
                {
                    TempData["Message"] = $"Welcome back {model.UsernameOrEmail}!";
                    // Create session for user
                    SessionHelper.LogUserIn(_httpAccessor, member.MemberId, member.Username);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Sorry, we are unable to find your credentials within our database.");
                }
            }
            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                Member member = await MemberDb.IsLoginValid(model, _context);

                if (member != null)
                {
                    TempData["Message"] = "Logged in successfully";
                    SessionHelper.LogUserIn(_httpAccessor, member.MemberId, member.Username);
                    return(RedirectToAction("Index", "Home"));
                }
                else // Credentials invalid
                {
                    // Adding model error with no key, will display error message in the validation summary
                    ModelState.AddModelError(string.Empty, "Username or Password is incorrect");
                }
            }

            return(View(model));
        }
Beispiel #4
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                Member member = await MemberDb.IsLoginValid(model, _context);

                if (member != null)
                {
                    TempData["Message"] = "Logged in successfully";

                    // use SessionHelper methods
                    SessionHelper.LogUserIn(_httpAccessor, member.MemberId, member.Username);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    // credentials invalid but password and username is supplied
                    // AddModelError without key displays error message in the validation summary that is auto generated and for modelErrors
                    ModelState.AddModelError(string.Empty, "I'm sorry, you're credentials did not match any records in our database");
                }
            }

            return(View(model));
        }