public ActionResult LogIn() { string username = Request.Form["username"]; //获取用户名 string password = Request.Form["password"]; //获取密码 try { //表单验证 if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(Content("<script> alert('用户名密码不得为空'); location.href = '" + Url.Action("Index", "Account") + "'</script>")); } else { if (username != "admin") { return(Content("<script> alert('该用户没有权限登录'); location.href = '" + Url.Action("Index", "Account") + "'</script>")); } List <Wheres> whs = new List <Wheres>() { new Wheres("username", "=", username) }; var dir = bll.QuerySingleByWheres(whs); if (dir != null) { string obj = (string)(dir.objectId); string pas = (string)(dir.password); //string li = "raw:" + password + " sql:" + pas + " jiami:" + (password + obj).Md5(); //string ss = (password + obj).Md5(); if ((password.Md5() + obj).Md5().Equals(pas)) { string sessionToken = Guid.NewGuid().ToString(); bll.UpdateById(obj, new Dictionary <string, object> { { "sessionToken", sessionToken } }); _User model = bll.QuerySingleById(obj); Session["CurrentUser"] = username; return(RedirectToAction("GetItems", "Items")); //return ok(model); } else { return(Content("<script> alert('密码错误'); location.href = '" + Url.Action("Index", "Account") + "'</script>")); // return notFound("密码错误" + li); } } else { return(Content("<script> alert('用户不存在'); location.href = '" + Url.Action("Index", "Account") + "'</script>")); //return notFound("用户不存在"); } } } catch (Exception e) { return(Content("<script> alert('" + e.Message + "'); location.href = '" + Url.Action("Index", "Account") + "'</script>")); //return execept(e.Message); } }
public IHttpActionResult PostWithdrawalsDetail(string v1, string password, [FromBody] WithdrawalsDetails withdrawalsHistory) { try { if (withdrawalsHistory.change <= 0) { return(notFound("必须为非空整数")); } string objectId = HttpContext.Current.Request.Headers["objectId"]; _UserBLL userModel = new _UserBLL(); var usermodel = userModel.QuerySingleById(objectId); if (!usermodel.transaction_password.Equals((password + objectId).Md5())) { return(notFound("密码错误")); } if (usermodel.overage < withdrawalsHistory.change) { return(notFound("余额不足")); } withdrawalsHistory.createdAt = DateTime.Now; withdrawalsHistory.updatedAt = DateTime.Now; withdrawalsHistory.before = usermodel.overage; withdrawalsHistory.after = usermodel.overage - withdrawalsHistory.change; withdrawalsHistory.objectId = Guid.NewGuid().ToString(); withdrawalsHistory.state = "未完成"; if (bll.saveDetail(withdrawalsHistory, objectId)) { return(ok(withdrawalsHistory.objectId)); } return(notFound("失败")); } catch (Exception e) { return(execept(e.Message)); } }
//public async Task<HttpResponseMessage> Get() //{ // return await Task<HttpResponseMessage>.Factory.StartNew(() => // { // return Request.CreateResponse(HttpStatusCode.OK, "aa"); // }); ////} //public IHttpActionResult GetUsers(string v1, string include = "") //{ // try // { // if (string.IsNullOrEmpty(include)) // { // IEnumerable<_User> list = bll.QueryList(0); // //return result<IEnumerable<_User>>(list); // return ok(list); // } // else // { // //非空时,解析所有列 // Dictionary<string, string[]> columns = new Dictionary<string, string[]>(); // string includeInit = include.Substring(0, include.Count() - 1); // string[] cols = includeInit.Split(new string[] { "]," }, StringSplitOptions.None); // foreach (var col in cols) // { // string[] cols1 = col.Split('['); // columns.Add(cols1[0], cols1[1].Split('|')); // } // IEnumerable<Dictionary<string, object>> list = bll.QueryListX(0, 10, columns); // //return result<IEnumerable<Dictionary<string, object>>>(list); // return ok(list); // } // } // catch (Exception e) // { // return execept(e.Message); // } //} // GET api/values/5 获取指定id信息 public IHttpActionResult GetUser(string v1, string objectId, string include = "") { try { if (string.IsNullOrEmpty(objectId)) { return(invildRequest("用户ID不能为空")); } if (string.IsNullOrEmpty(include)) { _User model = bll.QuerySingleById(objectId); return(ok(model)); } else { Dictionary <string, string[]> columns = new Dictionary <string, string[]>(); string includeInit = include.Substring(0, include.Count() - 1); string[] cols = includeInit.Split(new string[] { "]," }, StringSplitOptions.None); foreach (var col in cols) { string[] cols1 = col.Split('['); columns.Add(cols1[0], cols1[1].Split(',')); } Dictionary <string, object> model = bll.QuerySingleByIdX(objectId, columns); //IEnumerable<Dictionary<string, object>> model = bll.QueryListX(0, 1, columns, new List<Wheres> { new Wheres("objectId", "=", objectId) }); //if (model == null||model.Count()<1) { // return notFound("查询失败"); //} //return ok(model.First()); if (model == null) { return(notFound("查询失败")); } return(ok(model)); } } catch (Exception e) { return(execept(e.Message)); } }
public IHttpActionResult autoLogin(string uid, long credits) { _User user = userBll.QuerySingleById(uid); if (user == null) { return(creditError("no such user", 0)); } if (user.credit != (int)credits) { return(creditError("user credits not correct", 0)); } Hashtable hshTable = new Hashtable(); hshTable.Add("uid", uid); hshTable.Add("credits", credits); string url = duiba.BuildUrlWithSign(loginUrl, hshTable, APP_KEY, APP_SECRET); return(ok(url)); }
public _User GetUser(string objectId) { try { _User model = bll.QuerySingleById(objectId); return(model); } catch (Exception e) { return(null); } }
public IHttpActionResult Get(string v1, string objectId) { try { if (string.IsNullOrEmpty(objectId)) { return(invildRequest("用户ID不能为空")); } _User user = bll.QuerySingleById(objectId); if (user.shake_times < 1) { return(ok(-1)); } Random ran = new Random(); int number = ran.Next(-3, 6); if (number < 1) { return(ok(number)); } CreditsHistory history = new CreditsHistory(); history.change = number; history.type = -1; Guid guid = Guid.NewGuid(); history.objectId = guid.ToString(); history.updatedAt = DateTime.Now; history.createdAt = DateTime.Now; history.userId = objectId; history.credit = user.credit + history.change; if (historyBLL.shake(history, objectId)) { return(ok(number)); } else { return(notFound("发生错误")); } } catch (Exception e) { return(execept(e.Message)); } }
public IHttpActionResult Post(string v1, [FromBody] order myOrder) { try { //string objectId = myOrder.trade_no; //RechargeHistory model = bll.QuerySingleById(objectId); //HttpClint query = new HttpClint(); //RechargeHistory mm = new RechargeHistory(); //mm.createdAt = DateTime.Now; //mm.updatedAt = DateTime.Now; //mm.objectId = "11111111"; //bll.Update(mm); string out_trade_no = myOrder.out_trade_no; string response = HttpHelper.Get(@"https://api.bmob.cn/1/pay/" + out_trade_no, new { }); RechargeHistory model = JsonHelper.Deserialize <RechargeHistory>(response); RechargeHistory modelX = bll.QuerySingleById(model.body); model.updatedAt = DateTime.Now; model.createdAt = modelX.createdAt; model.objectId = model.body; model.userId = modelX.userId; model.trade_state = myOrder.trade_status; model.out_trade_no = myOrder.out_trade_no; bool result = bll.Update(model); _UserBLL userbll = new _UserBLL(); _User userModel = userbll.QuerySingleById(model.userId); userbll.UpdateById(model.userId, new Dictionary <string, object> { { "overage", userModel.overage + model.total_fee * 100 } }); if (result) { return(ok("success")); } return(ok("failure")); } catch (Exception e) { return(ok(e.Message)); } }
public IHttpActionResult Get(string v1, string objectId, int type) { try { if (string.IsNullOrEmpty(objectId)) { return(invildRequest("用户ID不能为空")); } _User user = userbll.QuerySingleById(objectId); if (user == null) { return(notFound("用户不纯在")); } if (!user.sign_in) { return(notFound("已签到")); } CreditsHistory history = new CreditsHistory(); if (type == 0) { history.type = 0; history.change = 2; } else if (type == 1) { Random ran = new Random(); history.change = ran.Next(0, 6); history.type = 1; } else { Random ran = new Random(); history.change = ran.Next(-2, 9); history.type = 2; } Guid guid = Guid.NewGuid(); history.objectId = guid.ToString(); history.updatedAt = DateTime.Now; history.createdAt = DateTime.Now; history.userId = objectId; history.credit = user.credit + history.change; if (historyBLL.SignIn(history, objectId)) { return(ok(history)); } else { return(notFound("发生错误")); } } catch (Exception e) { return(execept(e.Message)); } }