/// <summary> /// 添加医生 /// </summary> /// <param name="user"></param> /// <returns></returns> public JsonResult AjaxSubmitDoctor(User user) { BaseResult res = new BaseResult(); //检查账号是否存在 if (UserLogic.ExistsLoginName(user.LoginName)) { res.State = State.ExistsLoginName; res.Message = "该账号已存在!"; return(Json(res)); } Doctor d = new Doctor { Hospital = user.Hospital, Subject = user.Subject, DoctorInfo = user.DoctorInfo, Position = user.Position }; user.UserTypeId = 3; user.Status = 0; user.Pwd = Encryption.AESEncrypt("123456"); user.RegisterTime = DateTime.Now; user.HeadImgId = 1; //保存医生信息 UserLogic.SaveUser(user); d.UserId = user.Id; DoctorLogic.SaveDoctor(d); res.State = State.Success; res.Message = "保存成功"; SaveUserLog(AuthUser.LoginName + "添加医生(" + user.LoginName + ")成功", LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubmitDoctor", "添加医生"); return(Json(res)); }
// Finalize message strucutre then write. public static void EncryptSendMessage(byte[] message, NetworkStream stream) { // Encrypt Message Data byte[] encrypt = Encryption.AESEncrypt(message, Encryption.AESKey, Encryption.AESIV); // Encrypt Key Data byte[] finalBytes = Encryption.AppendKeyToMessage(encrypt, Encryption.AESKey, Encryption.AESIV, Encryption.clientCopyOfServerPublicKey); StreamHandler.WriteToStream(stream, finalBytes); }
public static byte[] EncryptMessage(byte[] data, byte[] modulus, byte[] exponent) { // Encrypt Message Data byte[] encrypt = Encryption.AESEncrypt(data, Encryption.AESKey, Encryption.AESIV); // Combine key values. RSAParameters publicKeyCombined = Encryption.RSAParamaterCombiner(modulus, exponent); // Encrypt Key Data byte[] finalBytes = Encryption.AppendKeyToMessage(encrypt, Encryption.AESKey, Encryption.AESIV, publicKeyCombined); return(finalBytes); }
/// <summary> /// 重置密码 /// </summary> /// <param name="userId"></param> /// <returns></returns> public JsonResult ResetPwd(int userId) { BaseResult res = new BaseResult(); if (AuthUser.UserTypeId <= 2) { string pwd = Encryption.AESEncrypt("123456"); User user = UserLogic.EditPwd(userId, pwd); res.State = State.Success; SaveUserLog(AuthUser.LoginName + "重置" + user.LoginName + "的密码成功", LogLevel.Sensitive, AuthUser.LoginName, "ResetPwd", "重置密码"); } else { res.State = State.NoPower; res.Message = "你暂无权限重置用户密码!"; SaveUserLog(AuthUser.LoginName + "重置用户id为" + userId + "的密码失败:" + res.Message, LogLevel.Error, AuthUser.LoginName, "ResetPwd", "重置密码"); } return(Json(res)); }
/// <summary> /// 修改当前用户密码 /// </summary> /// <param name="oldPwd"></param> /// <param name="newPwd"></param> /// <returns></returns> public JsonResult EditPwd(string oldPwd, string newPwd) { BaseResult res = new BaseResult(); if (AuthUser.Pwd == Encryption.AESEncrypt(oldPwd)) { UserLogic.EditPwd(AuthUser.Id, Encryption.AESEncrypt(newPwd)); res.State = State.Success; SaveUserLog(AuthUser.LoginName + "修改密码成功", LogLevel.Sensitive, AuthUser.LoginName, "EditPwd", "修改密码"); } else { res.State = State.PwdFaild; res.Message = "原密码不正确!"; SaveUserLog(AuthUser.LoginName + "修改密码失败:" + res.Message, LogLevel.Sensitive, AuthUser.LoginName, "EditPwd", "修改密码"); } return(Json(res)); }
/// <summary> /// 添加管理员 /// </summary> /// <param name="user"></param> /// <returns></returns> public JsonResult AJaxAddAdmin(User user) { BaseResult res = new BaseResult(); //检查账号是否存在 if (UserLogic.ExistsLoginName(user.LoginName)) { res.State = State.ExistsLoginName; res.Message = "该账号已存在!"; return(Json(res)); } user.UserTypeId = 2; user.Status = 0; user.Pwd = Encryption.AESEncrypt(user.Pwd); user.RegisterTime = DateTime.Now; user.HeadImgId = 1; //保存医生信息 UserLogic.SaveUser(user); res.State = State.Success; res.Message = "保存成功"; SaveUserLog(AuthUser.LoginName + "添加管理员(" + user.LoginName + ")成功", LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubmitDoctor", "添加管理员"); return(Json(res)); }
/// <summary> /// ajax登陆提交 /// </summary> /// <param name="loginName">账号</param> /// <param name="pwd">密码</param> /// <param name="curIp">当前ip</param> /// <returns></returns> public JsonResult AjaxLogin(string loginName, string pwd, string curIp) { Session[ConstVal.SessionIpStr] = curIp; string aesPwd = Encryption.AESEncrypt(pwd); BaseResult res = new BaseResult(); bool isLogin = false;//是否登陆成功 User _u = UserLogic.GetUserByLogin(loginName, aesPwd); if (_u == null) { res.State = State.Falid; res.Message = "账号或密码错误!"; return(Json(res)); } isLogin = _u != null; if (_u.UserTypeId > 3) { //登陆设备系统 LoginModel model = UserData.UserLogin(loginName, pwd); //登陆成功 if (model.State == 0) { //授权 ///FormsAuthentication.SetAuthCookie(loginName, false); // AddAuth(_u.LoginName, _u.UserTypeId.ToString()); res.State = (int)State.Success; _u.APIToken = model.AccessToken; _u.APIUserId = model.Item.UserId; Device d = DeviceLogic.GetDeviceByUserId(_u.Id); if (d != null) { _u.DeviceId = d.Id; } isLogin = true; } else { res.State = State.Falid; res.Message = model.Message; WriteLog("用户" + loginName + "登陆设备系统失败,state:" + model.State + "!"); return(Json(res)); } } //医生,管理员,超级管理员不用登陆设备系统 // isLogin = _u != null && _u.UserTypeId < 4; if (!isLogin) { res.State = State.Falid; res.Message = "账号或密码错误!"; } else { //更新用户登录记录 _u.LastLoginTime = DateTime.Now; _u.LastLoginIp = GetIP(); UserLogic.UpdateUser(_u); WriteLog("用户" + loginName + "登陆设备系统成功!"); AuthUser = _u;//存session } SaveUserLog(loginName + "登陆" + (isLogin ? "成功" : "失败"), isLogin ? LogLevel.Info : LogLevel.Sensitive, loginName, "AjaxLogin", res.Message); return(Json(res)); }
/// <summary> /// 注册提交 /// </summary> /// <param name="param"></param> /// <returns></returns> public JsonResult AjaxRegister(RegisterParam param) { BaseResult res = new BaseResult(); bool isRegister = true;//是否注册成功 //检查用户是否存在 if (UserLogic.ExistsLoginName(param.LoginName)) { res.State = State.ExistsLoginName; res.Message = "用户名已存在!"; isRegister = false; } else if (UserLogic.ExistsPhoneNum(param.Phone)) { res.State = State.NumIsRegister; res.Message = "手机号码已被注册!"; isRegister = false; } if (isRegister) { //先去设备平台注册 RegisterModel rm = UserData.Register(param.LoginName, param.Pwd, param.Phone, param.IMEI); if (rm.User == null) {//注册失败直接返回 res.State = State.Falid; res.Message = rm.Message; isRegister = false; return(Json(res)); } User _u = new User(); _u.UserName = param.LoginName; _u.LoginName = param.LoginName; _u.Pwd = Encryption.AESEncrypt(param.Pwd); _u.RegisterTime = DateTime.Now; _u.PhoneNum = param.Phone; _u.Status = (int)Status.Normal; _u.HeadImgId = ConstVal.DefaultHeadImgId; _u.UserTypeId = 4;//居民 _u.APIUserId = rm.User.UserId; _u.UserInfo = ""; _u.Sex = 1; int i = UserLogic.SaveUser(_u); if (i > 0) { res.State = State.Success; res.Message = "注册成功!"; if (!string.IsNullOrWhiteSpace(param.IMEI)) { //检查设备 DeviceCheckModel dcm = DeviceData.CheckDevice(param.IMEI, _u.APIUserId ?? 0); //添加设备表 Device d = new Device { UserId = _u.Id, IconId = 3, Created = DateTime.Now, Imei = param.IMEI, Status = (int)Status.Normal, APIDeviceId = dcm.DeviceId, APIDeviceModel = dcm.Model }; DeviceLogic.SaveDevice(d); } } else { res.State = State.Falid; res.Message = "注册失败!"; isRegister = false; } } //记录操作日志 SaveUserLog("注册账号" + (isRegister ? "成功" : "失败") + ":" + res.Message, LogLevel.Info, param.LoginName, "AjaxRegister", "注册账号"); return(Json(res)); }
/// <summary> /// 客户登录提交页 /// </summary> /// <returns></returns> public ActionResult PostCustomerLogin() { try { string account = Request.Form["account"]; string pwd = Request.Form["pwd"]; string typeUser = Request.Form["cbxUser"]; string userName = ""; if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(pwd)) { return(Json(new { success = false, msg = "账号或密码不能为空。" })); } HttpCookie cookieUserType = new HttpCookie(); HttpCookie cookieOpenID = new HttpCookie(); cookieOpenID.Value = Request.Cookies["wechatOpenid"]; if (cookieUserType.Value == null) { cookieUserType.Value = new string("userType"); } if (cookieOpenID.Value == null) { cookieOpenID.Value = new string("cookieOpenID"); return(Json(new { success = false, code = 0, msg = "/home/error?state=尚未授权,即将跳转到授权界面!" })); } if (typeUser == "Y") { #region Banned //sql = "SELECT * FROM User WHERE workNo=@loginNo AND [Password]=@password AND IsActive='y'"; //SqlParameter[] param = new SqlParameter[] //{ // new SqlParameter("@loginNo",account), // new SqlParameter("@password",pwd), //}; #endregion User user = Context.User.FirstOrDefault(x => x.WorkNo == account && x.Password == pwd && x.IsActive == "Y"); if (user == null) { return(Json(new { success = false, msg = "账号或密码错误。" })); } user.WeChatID = cookieOpenID.Value; Context.User.Update(user); Context.SaveChanges(); cookieUserType.Value = typeUser; userName = Encryption.AESEncrypt(user.UserName); } else { pwd = account.ToLower() == "leeneo" ? pwd : MD5.GetMd5Str32(pwd); #region Banned //sql = "SELECT * from user u left join t_Customer c on u.CustomerId = c.Customerid where u.isactive = 'Y' and c.IsActive = 'Y' and u.Contact_TelNo =@loginNo and u.[password] = @password; "; //SqlParameter[] param = new SqlParameter[] //{ // new SqlParameter("@loginNo",account), // new SqlParameter("@password",pwd), //}; //SQLHelper.SetConnection("tDb"); //user contact = SQLHelper.ExecuteSqlObject<user>(sql, param); #endregion #region 使用 BeginTransaction 和多个 DbContext 的执行策略和显式事务。 //EF Core 具有两个重要功能,使其有别于 Dapper ,并且增加其性能开销。 第一个功能是从 LINQ 表达式转换为 SQL。 将缓存这些转换,但即便如此,首次执行它们时仍会产生开销。 第二个功能是对实体进行更改跟踪(以便生成高效的更新语句)。 通过使用 AsNotTracking 扩展,可对特定查询关闭此行为。 EF Core 还会生成通常非常高效的 SQL 查询,并且从性能角度上看,任何情况下都能完全接受,但如果需要执行对精确查询的精细化控制,也可使用 EF Core 传入自定义 SQL(或执行存储过程)。 在这种情况下,Dapper 的性能仍然优于 EF Core,但只有略微优势。 ////var strategy = Context.Database.CreateExecutionStrategy(); //await strategy.ExecuteAsync(async () => //{ // // Achieving atomicity between original Catalog database operation and the // // IntegrationEventLog thanks to a local transaction // using (var transaction = Context.Database.BeginTransaction()) // { // Context.user.Update(contact); // await Context.SaveChangesAsync(); // // Save to EventLog only if product price changed // //if (raiseProductPriceChangedEvent) // // await _integrationEventLogService.SaveEventAsync(priceChangedEvent); // transaction.Commit(); // } //}); #endregion #region Linq 带条件查询 //var customers = Context.t_Customer.Select(x => x.IsActive == "Y"); //var customers2 = Context.t_Customer.Select(b => new t_Customer //{ // Customerid = b.Customerid, //此处定义的字段名要与t_Customer中定义的名字、个数一致,否则自动填充为null或default value // CustomerName = b.CustomerName, // IsActive = b.IsActive, // //Validdate=b.Validdate, // status = b.status //}); #endregion //var contactLq = from tcn in Context.user // .Where(x => x.isactive == "Y" && x.Contact_TelNo == account && x.password == pwd) // join tcu in Context.t_Customer // .Where(x => x.IsActive == "Y") // on tcn.CustomerID equals tcu.Customerid into temp2 // from tm2 in temp2.DefaultIfEmpty() // select tcn; //user contact = contactLq.FirstOrDefault(); //if (contact == null) // return Json(new { success = false, msg = "账号或密码错误。" }); //contact.WeChatID = cookieOpenID.Value; //Context.user.Update(contact); //Context.SaveChanges(); //cookieAccount.Value = Encryption.AESEncrypt(contact.Contact_TelNo); //cookiePwd.Value = Encryption.AESEncrypt(contact.password); //cookieUserType.Value = ""; //cookieID.Value = contact.ContactID.ToString(); //userName = Encryption.AESEncrypt(contact.Contact_Person); //Response.Cookies.Append("CustomerID", contact.CustomerID.ToString(), new CookieOptions() //{ // Expires = DateTime.Now.AddMonths(3), // IsEssential = true //}); Response.Cookies.Append("UserName", userName, new CookieOptions() { Expires = DateTime.Now.AddMonths(3), IsEssential = true }); } return(Json(new { success = true, msg = "登录成功。" })); } catch (Exception ex) { ex = ex.GetBaseException(); _Logger.Error(ex.Message, "新增问题客户登录"); return(Json(new { success = false, msg = "登录出错:" + ex.Message })); } }