public object Login([FromBody] UserDto user) { Worker userResult = _userAppService.Login(user.Account, user.Password); var result = new object(); if (userResult != null) { //set序列化,加入值 //HttpContext.Session.SetString("currentUser", JsonConvert.SerializeObject(userResult)); JWTUtil _jwtUtil = new JWTUtil(); var token = _jwtUtil.GetJwt(userResult.Account, _configuration); result = new { isSuccess = true, message = "登录成功!", user = userResult, menu = _userAppService.GetMenu(userResult.PositionId), token }; } else { result = new { isSuccess = true, message = "登录失败!" } }; return(result); }
/// <summary> /// /// </summary> public static T UsuarioLogueado <T>() where T : class, new() { T result = null; if (System.Web.HttpContext.Current.Request.Cookies.ContainsKey("jwt")) { result = JWTUtil.GetPayload <T>(System.Web.HttpContext.Current.Request.Cookies["jwt"], Security.GetSecurityConfigure.SecuritySecretKey); } return(result); }
public OutputData Insert(IInputData input, object instance) { LogOnData data = instance.Convert <LogOnData>(); using (UserResolver resolver = new UserResolver(this)) { IUserInfo userInfo = resolver.CheckUserLogOn(data.LogOnName, data.Password, 0); if (userInfo == null) { } var response = WebGlobalVariable.Response; CookieOptions options = new CookieOptions { Expires = new DateTimeOffset(DateTime.Now.AddDays(30)) }; response.Cookies.Append(COOKIE_NAME, data.LogOnName, options); options = new CookieOptions { Expires = new DateTimeOffset(JWTUtil.CalcValidTime()) }; string token = JWTUtil.CreateEncodingInfo(userInfo); response.Cookies.Append(JWTUtil.COOKIE_NAME, token, options); //CookieUserInfo cookieInfo = new CookieUserInfo(data, userInfo); //cookie = new HttpCookie(RightConst.USER_INFO_COOKIE_NAME, cookieInfo.Encode()) //{ // Expires = GetExpireDate() //}; //response.Cookies.Set(cookie); WebSuccessResult result; string retUrl = input.QueryString["RetURL"]; if (!string.IsNullOrEmpty(retUrl)) { result = new WebSuccessResult(retUrl); } else { WebAppSetting appSetting = WebAppSetting.WebCurrent; if (string.IsNullOrEmpty(appSetting.MainPath)) { result = new WebSuccessResult(appSetting.HomePath); } else { string url = HttpUtility.UrlEncode(appSetting.HomePath); string mainUrl = UriUtil.AppendQueryString(appSetting.MainPath, "StartUrl=" + url); result = new WebSuccessResult(mainUrl); } } return(OutputData.CreateToolkitObject(result)); } }
public IActionResult Index() { var jwt = JWTUtil.GetPayloadSinControl <Gq_usuariosDto>(Request.Cookies["jwt"], Security.SecuritySecretKey); if (jwt != null && jwt.Usuario != null) { ViewData["UsuarioNombre"] = jwt.Usuario; } return(PartialView()); }
public ReturnData Login([FromBody] Gq_usuariosDto data) { var result = new ReturnData(); var user = Services.Get <ServGq_usuarios>().findBy(x => (x.Usuario == data.Usuario || x.Email == data.Usuario) && (x.Clave == Encriptacion.Encriptar(data.Clave, Constantes.CLAVE_ENCRIPTACION) || x.Clave == data.Clave)).FirstOrDefault(); // Services.GetCollection<Iot_usuarios>().Find(x => (x.NombreUsuario == data.NombreUsuario || x.EMail == data.NombreUsuario) && x.Clave == Constantes.Encriptar(data.Clave)).FirstOrDefault(); if (user != null) { Response.Cookies.Append("jwt", JWTUtil.GenerateToken(user, Security.SecuritySecretKey)); } result.data = new Gq_usuariosDto().SetEntity(user); result.isError = result.data == null; return(result); }
public ReturnData Login([FromBody] Gq_usuariosDto data) { var result = new ReturnData(); var Usuario = JWTUtil.GetPayloadSinControl <Gq_usuariosDto>(Request.Cookies["jwt"], Security.SecuritySecretKey).Usuario; var user = Services.Get <ServGq_usuarios>().findBy(x => (x.Usuario == Usuario || x.Email == Usuario) && (x.Clave == Encriptacion.Encriptar(data.Clave, Constantes.CLAVE_ENCRIPTACION) || x.Clave == data.Clave)).FirstOrDefault(); if (user != null) { Response.Cookies.Delete("jwt"); Response.Cookies.Append("jwt", JWTUtil.GenerateToken(user, Security.SecuritySecretKey)); } result.data = new Gq_usuariosDto().SetEntity(user); result.isError = result.data == null; return(result); }
private void ProcessJWT(HttpContext context) { var request = context.Request; string auth = request.Cookies[JWTUtil.COOKIE_NAME]; if (!string.IsNullOrEmpty(auth)) { try { var info = JWTUtil.DecodeFromJwt(auth); if (JWTUtil.IsValidHost(info, request.Host.Host, request.Host.Port)) { context.User = new ToolkitClaimsPrincipal(info); } } catch (Exception ex) { TkTrace.LogError(ex.Message); } } }