public ActionResult GetTown(string cityid) { var rst = new RestfulData <tb_county>(); var town = DbContext.Instance.List <tb_county>("where cityid='" + cityid + "' and state=1"); rst.code = 100; rst.result = town; return(Json(rst, JsonRequestBehavior.AllowGet)); }
public ActionResult GetCity(string provid) { var rst = new RestfulData <tb_city>(); var city = DbContext.Instance.List <tb_city>("where provid='" + provid + "' and state=1"); rst.code = 100; rst.result = city; return(Json(rst, JsonRequestBehavior.AllowGet)); }
public ActionResult GetProv() { var rst = new RestfulData <tb_province>(); var prov = DbContext.Instance.List <tb_province>("where state=1"); rst.code = 100; rst.result = prov; return(Json(rst, JsonRequestBehavior.AllowGet)); }
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string msg) { var result = new RestfulData { code = statusCode, message = msg }; context.Response.ContentType = "application/json;charset=utf-8"; return(context.Response.WriteAsync(JsonConvert.SerializeObject(result))); }
public RestfulData <UserInfo> GetUserInfo() { var res = new RestfulData <UserInfo>(); var info = new UserInfo(); var cUser = Helper.GetCurrentUser(HttpContext); string[] Roles = new string[] { cUser.Role }; //Roles[1] = cUser.Role; res.data = new UserInfo() { Name = cUser.Nickname, Roles = Roles, }; return(res); }
public async Task <ActionResult> Sigin([FromBody, BindRequired] SigninForm signinForm) { var result = new RestfulData <TokenObj>(); //验证用户名和密码 var userInfo = new UserDao().GetUser(signinForm.username, signinForm.password); if (userInfo != null) { var claims = new Claim[] { new Claim(ClaimTypes.Sid, userInfo.Id.ToString()), new Claim(ClaimTypes.Name, userInfo.Nickname ?? ""), new Claim(ClaimTypes.Role, userInfo.Role), new Claim(ClaimTypes.NameIdentifier, userInfo.Username), }; var key = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes(ConfigHelper.GetValueByKey("SecurityKey"))); var expires = DateTime.Now.AddDays(30);// var token = new JwtSecurityToken( issuer: ConfigHelper.GetValueByKey("issuer"), audience: ConfigHelper.GetValueByKey("audience"), claims: claims, notBefore: DateTime.Now, expires: expires, signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256)); //生成Token string jwtToken = new JwtSecurityTokenHandler().WriteToken(token); result.data = new TokenObj() { token = jwtToken, expires = expires.ToFileTimeUtc() }; result.message = "授权成功!"; return(Ok(result)); } else { result.message = "账号或密码错误"; result.code = 400; return(BadRequest(result)); } }