public void Update(PostToken item) { item.id = _databaseInstance.Insert(item, TableName); }
public ActionResult Login(LoginRequest request) { try { WxPayAPI.Log.Info("PosApiController", string.Format("请求登录:账号{0},密码:{1}", request.username, request.password)); LoginRespone result = new LoginRespone(); if (string.IsNullOrEmpty(request.username)) { return(Json(new ApiResponse() { Code = "-1", Msg = "请输入账号" })); } var model = posEndPointService.GetByName(request.username); if (model == null) { return(Json(new ApiResponse() { Code = "-1", Msg = "登录账号不存在" })); } if (model.DataKey != request.password) { return(Json(new ApiResponse() { Code = "-1", Msg = "密码错误" })); } if (model.State != States.Normal) { return(Json(new ApiResponse() { Code = "-1", Msg = "账号已被停用" })); } string token = request.username + "_" + DateTime.Now.ToShortTimeString(); token = SaltAndHash(token, Guid.NewGuid().ToString("N").Substring(0, 8)); var posToken = postTokenService.GetByPosName(request.username); if (posToken == null) { posToken = new PostToken(); posToken.createTime = DateTime.Now; posToken.posName = request.username; posToken.token = token; postTokenService.Insert(posToken); } else { posToken.token = token; posToken.createTime = DateTime.Now; postTokenService.Update(posToken); } result.Code = "1"; result.Msg = "SUCCESS"; result.token = token; return(Json(result)); } catch (Exception ex) { WxPayAPI.Log.Info("PosApiController", string.Format("请求登录:账号{0},密码:{1},异常:{2}", request.username, request.password, ex.Message)); return(Json(new ApiResponse() { Code = "-1", Msg = "系统异常,请联系管理员" })); } }