Exemple #1
0
        public async Task <IActionResult> logout()
        {
            var authenticationId = getLoggedInAuthenticationId();
            await HttpContext.SignOutAsync();

            var sessionDto = new CMS.User.Dto.LoginSessionDto()
            {
                authentication_id = authenticationId,
                type = CMS.User.Enums.SessionType.logout
            };

            _loginSessionService.save(sessionDto);

            return(Redirect("/account/login"));
        }
Exemple #2
0
        public async Task <IActionResult> login(LoginModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var authenticationDetail = _authenticationService.validateUser(model.username, model.password);

                    if (authenticationDetail == null)
                    {
                        throw new Exception("Username and password didnot match.");
                    }

                    var claims = new List <Claim>()
                    {
                        new Claim(ClaimTypes.NameIdentifier, authenticationDetail.authentication_id.ToString())
                    };

                    var userIdentity = new ClaimsIdentity(claims, "local");

                    ClaimsPrincipal          principal = new ClaimsPrincipal(userIdentity);
                    AuthenticationProperties prop      = new AuthenticationProperties();
                    prop.ExpiresUtc   = DateTime.UtcNow.AddDays(30);
                    prop.IsPersistent = model.remember_me;
                    await HttpContext.SignInAsync("userDetails", principal, prop);

                    var sessionDto = new CMS.User.Dto.LoginSessionDto()
                    {
                        authentication_id = authenticationDetail.authentication_id,
                        type = CMS.User.Enums.SessionType.login
                    };
                    _loginSessionService.save(sessionDto);
                    return(Redirect("/admin"));
                }
            }
            catch (Exception ex)
            {
                AlertHelper.setMessage(this, ex.Message, messageType.error);
            }
            return(View(model));
        }