/// <summary> /// /// </summary> /// <param name="onlineUserSvr"></param> /// <param name="ipLocator"></param> /// <param name="context"></param> /// <param name="loginUser"></param> internal static void CreateLoginUser(IOnlineUsers onlineUserSvr, IIPLocatorProvider ipLocator, HttpContext context, LoginUser loginUser) { loginUser.UserAgent = context.Request.Headers["User-Agent"]; var agent = new UserAgent(loginUser.UserAgent); loginUser.Ip = context.Connection.RemoteIpAddress.ToIPv4String(); loginUser.City = ipLocator.Locate(loginUser.Ip); loginUser.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}"; loginUser.OS = $"{agent.OS?.Name} {agent.OS?.Version}"; }
public bool Post([FromServices] IIPLocatorProvider ipLocator, [FromBody] Log value) { value.UserAgent = Request.Headers["User-Agent"]; var agent = new UserAgent(value.UserAgent); value.Ip = HttpContext.Connection.RemoteIpAddress.ToIPv4String(); value.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}"; value.OS = $"{agent.OS?.Name} {agent.OS?.Version}"; value.City = ipLocator.Locate(value.Ip); value.UserName = User.Identity.Name; return(LogHelper.Save(value)); }
public string Post([FromServices] IOnlineUsers onlineUserSvr, [FromServices] IIPLocatorProvider ipLocator, [FromBody] JObject value) { string token = null; dynamic user = value; string userName = user.userName; string password = user.password; if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password, loginUser => AccountController.CreateLoginUser(onlineUserSvr, ipLocator, HttpContext, loginUser))) { token = BootstrapAdminJwtTokenHandler.CreateToken(userName); } return(token); }
public async Task <IActionResult> Login([FromServices] IOnlineUsers onlineUserSvr, [FromServices] IIPLocatorProvider ipLocator, string userName, string password, string remember) { if (UserHelper.Authenticate(userName, password, loginUser => CreateLoginUser(onlineUserSvr, ipLocator, HttpContext, loginUser))) { var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme); identity.AddClaim(new Claim(ClaimTypes.Name, userName)); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties { ExpiresUtc = DateTimeOffset.Now.AddDays(DictHelper.RetrieveCookieExpiresPeriod()), IsPersistent = remember == "true" }); // redirect origin url var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].FirstOrDefault() ?? "~/Home/Index"; return(Redirect(originUrl)); } return(View("Login", new LoginModel() { AuthFailed = true })); }