public ActionResult Signin(FormCollection collection) { var result = ""; var now = DateTime.Now; var validCode = collection["validCode"] ?? ""; var entity = new Zero.DB.Entity.Base.AccountPO { Valid = true, CreateTime = DateTime.Now }; if (validCode == (Session[Zero.Utility.Config.SessionName + "register"] + "")) { var trans = new Transaction(); try { trans.Begin(); var dbHelper = new Zero.DB.Agent.MssqlHelper <AccountPO>(); var existsCount = dbHelper.ExecuteScalar( "Select Count(1) AS RecordCount From Account Where Mobile=@Mobile ", CommandType.Text, new IDbDataParameter[] { new SqlParameter("@Mobile", collection["Mobile"]) }, trans.DbConnection, trans.DbTrans); if (existsCount.ToInt() > 0) { result = "该号码已经注册!"; } else { entity.FillFromCollection(collection); entity.Valid = true; entity.LastSignin = now; entity.UpdateTime = now; entity.CreateTime = now; var salt = Guid.NewGuid().ToString().Replace("-", "").ToLower().Substring(10, 10); entity.Salt = salt; entity.LoginPassword = (collection["Password"] + salt).Md5(); entity = dbHelper.Insert(entity, trans.DbConnection, trans.DbTrans); if (entity != null) { SetAuthorizedAccountTiket(entity, true); //TraineeHelper.Refresh(entity); } } trans.Commit(); } catch (Exception ex) { trans.RollBack(); Logger.Error(ex); } finally { trans.Dispose(); } } return(Content(result)); }
public ActionResult Login(FormCollection collection) { var result = ""; var mobile = collection["Mobile"].SQLParse(); var loginPassword = collection["Password"]; var validCode = collection["validCode"] ?? ""; var url = Request["ReturnUrl"] ?? ""; try { if (validCode == (Session[Zero.Utility.Config.SessionName + "login"] + "")) { if ((mobile != "") && (loginPassword != "")) { var condition = string.Format(" Mobile='{0}' ", mobile); var trans = new Transaction(); try { trans.Begin(); var dbHelper = new Zero.DB.Agent.MssqlHelper <AccountPO>(); var trainee = dbHelper.FindSingle(condition, trans.DbConnection, trans.DbTrans); if (trainee != null) { var now = DateTime.Now; if (trainee.LoginPassword == (loginPassword + trainee.Salt).Md5()) { var traineeNew = new Zero.DB.Entity.Base.AccountPO(); traineeNew.FillFrom(trainee); traineeNew.LastSignin = now; dbHelper.Update(trainee, traineeNew, trans.DbConnection, trans.DbTrans); Logger.Info("LOGIN"); SetAuthorizedAccountTiket(trainee, true); //Data.Domain.TraineeHelper.Refresh(trainee); } else { result = "密码错误"; Logger.Error(result); } } else { result = "账号不存在"; Logger.Error(result); } trans.Commit(); } catch (Exception ex) { Logger.Error(ex); trans.RollBack(); } finally { trans.Dispose(); } } } else { result = "验证码错误"; Logger.Error(result); } } catch (Exception ex) { Logger.Error(ex); } //return View(); return(Content(result)); //RedirectToAction("Login", new { @ReturnUrl = url }); }