/// <summary> /// App登录,返回用户信息和认证Cookie /// </summary> /// <param name="phone"></param> /// <param name="passWord"></param> /// <returns></returns> public ActionResult App_Login(string phone, string passWord, string machineCode) { JsonMessage returnJson = new JsonMessage(); using (LoveBankDBContext db = new LoveBankDBContext()) { var t_a = db.T_Vol; //string passWordHash = passWord.Hash(); Vol appUser = t_a.Where(x => x.Phone == phone && x.PassWord == passWord).FirstOrDefault(); if (appUser != null) { returnJson.Status = true; appUser.PassWord = string.Empty; appUser.VolHeadImg = null; returnJson.Data = new { Ticket = AutheTicketManager.CreateAppLoginUserTicket(appUser.ID.ToString()), User = appUser }; returnJson.Info = "登录成功"; //登陆log LoginStatistics loginStatistics = new LoginStatistics(); loginStatistics.Type = LoginType.手机; loginStatistics.LoginState = 1; loginStatistics.Phone = phone; loginStatistics.MachineCode = machineCode; loginStatistics.UserId = appUser.ID; Action<LoginStatistics> loginStatisticsTarget = s => LoginLog(s); loginStatisticsTarget(loginStatistics); return Json(returnJson); } else { returnJson.Status = false; returnJson.Info = "登录失败,手机号或者密码错误"; returnJson.Data = HttpContext.Error; return Json(returnJson); } } returnJson.Status = false; returnJson.Info = "登录失败,系统异常"; returnJson.Data = HttpContext.Error; return Json(returnJson); }
//该方法和App_QRCode是一对配合使用 public ActionResult App_LoginQRCode(QRCodeModel qrCodeModel) { JsonMessage retJson = new JsonMessage(); switch (qrCodeModel.Type) { case QRCodeType.登陆: retJson.Status = QRCodeLogin(qrCodeModel.UserId, qrCodeModel.Ticket);///登录时obj参数是App存储在本科的票据Ticket retJson.Data = qrCodeModel.Data; if (retJson.Status == true) { ////登陆log LoginStatistics loginStatistics = new LoginStatistics(); loginStatistics.Type = LoginType.二维码登陆; loginStatistics.LoginState = 1; loginStatistics.MachineCode = qrCodeModel.MachineCode; loginStatistics.UserId = qrCodeModel.UserId; //LoginLog(loginStatistics); Action<LoginStatistics> loginStatisticsTarget = s => LoginLog(s); loginStatisticsTarget(loginStatistics); retJson.Info = "已经授权成功"; qrCodeModel.State = QRCodeState.已授权; qrCodeModel.UserId = qrCodeModel.UserId; qrCodeModel.GrantTime = DateTime.Now; BaseCacheManage.AddObject(qrCodeModel.QRCodeStringKey, qrCodeModel, 60 * 1);//加入缓存 } return Json(retJson); case QRCodeType.兑换: return Json(retJson); default: retJson.Status = false; retJson.Info = "未知类型(Type)"; return Json(retJson); } }
private bool LoginLog(LoginStatistics model) { model.AddTime = DateTime.Now; using (LoveBankDBContext db = new LoveBankDBContext()) { Machine mModel = db.T_Machine.Where(x=>x.MachineCode==model.MachineCode).FirstOrDefault(); if (mModel!=null) { model.Lon = mModel.Lon; model.Lat = mModel.Lat; model.Address = mModel.Address; } db.Add<LoginStatistics>(model); db.SaveChangesAsync(); } return true; }