public ActionResult Index(string url) { try { var isTesting = bool.Parse(MyUtils.GetAppSetting("isTesting")); ViewBag.userName = currentUser.userName; ViewBag.realName = currentUser.realName; ViewBag.account = currentAccount; ViewBag.accountName = currentCompany.accountName; ViewBag.url = url; var acs = new ItemSv().GetAllCompanies(); if (!isTesting) { acs = acs.Where(a => a.is_testing == false).ToList(); } ViewBag.accountList = acs; //验证密码是否已修改,邮箱是否有登记 var user = new UserSv().GetUserByUserId(currentUser.userId); if (user.password == MyUtils.getMD5(user.user_name)) { ViewBag.needToChangePassword = 1; } else if (string.IsNullOrEmpty(user.email)) { ViewBag.needToRegisterEmail = 1; } } catch { return(RedirectToAction("LogOut", "Account")); } return(View()); }
public JsonResult ActiveStoreKepper(string keeperName) { if (!keeperName.StartsWith("11.") && !keeperName.StartsWith("15.")) { return(Json(new SRM(false, "只有供应商才可以开通仓管员用户"))); } var keeper = new UserSv().GetUserByUserName(keeperName); if (keeper != null) { return(Json(new SRM(false, "仓管员用户之前已开通"))); } keeper = new Users(); keeper.user_name = keeperName; keeper.real_name = currentUser.realName; keeper.user_role = "供应商仓管"; try { new UserSv().SaveUser(keeper); } catch (Exception ex) { return(Json(new SRM(ex))); } return(Json(new SRM())); }
public JsonResult GetUsers(int page, int rows, string searchValue = "") { var users = new UserSv().GetUsers(searchValue); int total = users.Count(); users = users.Skip((page - 1) * rows).Take(rows).ToList(); return(Json(new { rows = users, total = total })); }
/// <summary> /// 订料员邮箱 /// </summary> /// <param name="bill"></param> /// <returns></returns> private string getSupplierEmail(DRBills bill) { var user = new UserSv().GetUserByUserName(bill.supplier_number); if (user == null) { return(""); } return(user.email ?? ""); }
public ActionResult StoreKeeperSetting() { var keeperName = currentUser.userName + "A"; var keeper = new UserSv().GetUserByUserName(keeperName); ViewData["keeperName"] = keeperName; ViewData["keeperStatus"] = keeper == null ? "未启用" : "已启用"; return(View()); }
public JsonResult GetBase64Avatar(string source) { KeyValuePair <bool, string> kv; if (string.IsNullOrEmpty(source) || !source.StartsWith("data:image/png;base64")) { kv = new KeyValuePair <bool, string>(false, "parameter error"); return(Json(new { kv }, JsonRequestBehavior.AllowGet)); } int i = source.Length; if (i <= 10) //source :'data:,' { kv = new KeyValuePair <bool, string>(false, "parameter not integrity"); return(Json(new { kv }, JsonRequestBehavior.AllowGet)); } string base64 = source.Substring(source.IndexOf(",") + 1); base64 = base64.Trim('\0'); byte[] chartData = Convert.FromBase64String(base64); MemoryStream ms = new MemoryStream(chartData, 0, chartData.Length); ms.Write(chartData, 0, chartData.Length); string folderName = GetFilePath(false); string fileName = DateTime.Now.ToFileTime().ToString() + ".png"; string path = Path.Combine(folderName, fileName); Image im = Image.FromStream(ms, true); try { im.Save(Server.MapPath(path), ImageFormat.Png); var r = UserSv.UpdateUserAvatar(path, MyUserId); kv = new KeyValuePair <bool, string>(r, path); im.Dispose(); } catch (Exception ex) { ms.Close(); im.Dispose(); kv = new KeyValuePair <bool, string>(false, ex.ToString()); return(Json(new { kv }, JsonRequestBehavior.AllowGet)); } ms.Close(); im.Dispose(); return(Json(new { kv }, JsonRequestBehavior.AllowGet)); }
public JsonResult IsUserAndEmailExisted(string userName) { var user = new UserSv().GetUserByUserName(userName); if (user == null) { return(Json(new SRM(false, "用户名不存在"))); } if (string.IsNullOrEmpty(user.email)) { return(Json(new SRM(false, "贵司未在此平台登记过邮箱,不能处理;请联系管理员处理"))); } return(Json(new SRM())); }
public JsonResult GetComboUsers(string searchValue = "", int maxCount = 30) { var users = new UserSv().GetUsers(searchValue); var result = users.Select(u => new { u.real_name, u.user_id, u.user_name }) .Take(maxCount) .ToList(); return(Json(result)); }
public JsonResult ResetPassword(int userId) { string result = new UserSv().ResetPassword(userId, SomeUtils.getMD5("000000")); if (!string.IsNullOrEmpty(result)) { return(Json(new ResultModel() { suc = false, msg = result })); } return(Json(new ResultModel() { suc = true })); }
public JsonResult ToggleUser(int userId) { string result = new UserSv().ToggleUser(userId); if (!string.IsNullOrEmpty(result)) { return(Json(new ResultModel() { suc = false, msg = result })); } return(Json(new ResultModel() { suc = true })); }
public JsonResult StartLogin(FormCollection fc) { string account = fc.Get("account"); string userName = fc.Get("user_name"); string password = fc.Get("password"); string validateCode = fc.Get("validate_code"); if (!validateCode.ToLower().Equals((string)Session["code"])) { return(Json(new SRM(false, "验证码不正确"))); } Users user; try { user = new UserSv().StartLogin(userName, password); } catch (Exception ex) { return(Json(new SRM(ex))); } //写入cookie,保留24小时登录状态 var cookie = new HttpCookie(MyUtils.GetCookieName()); cookie.Values.Add("user_id", user.user_id.ToString()); cookie.Values.Add("user_name", MyUtils.EncodeToUTF8(user.user_name)); cookie.Values.Add("real_name", MyUtils.EncodeToUTF8(user.real_name)); cookie.Values.Add("account", account); cookie.Values.Add("code", MyUtils.getMD5(user.user_id.ToString()));//用于filter验证 cookie.Expires = DateTime.Now.AddDays(1); Response.AppendCookie(cookie); //再写入登录用的cookie,用于记住公司名和登录名 cookie = new HttpCookie(MyUtils.GetCookieName() + "_login"); cookie.Values.Add("user_name", MyUtils.EncodeToUTF8(user.user_name)); cookie.Values.Add("account", account); cookie.Expires = DateTime.Now.AddYears(1); Response.AppendCookie(cookie); Session.Clear(); WLog(TAG, "登录成功:" + userName + "," + account); return(Json(new SRM())); }
/// <summary> /// create user of schoolmaster by phone number. /// </summary> /// <param name="schoolmasterphone"></param> /// <returns></returns> private ApplicationUser addSchoolMster(string schoolmasterphone) { var user = new UserSv().GetUserByPhone(schoolmasterphone); if (user == null) { user = new ApplicationUser { Email = schoolmasterphone + "@netedu.com", PhoneNumber = schoolmasterphone, UserName = schoolmasterphone }; var rs = UserManager.Create(user, "123456"); if (rs.Succeeded) { UserManager.AddToRole(user.Id, "schoolmaster"); } } return(user); }
public JsonResult UpdateUser(int id, FormCollection col) { UsersInfo uInfo = new UsersInfo(); SomeUtils.SetFieldValueToModel(col, uInfo); uInfo.id = id; string result = new UserSv().UpdateUser(uInfo); if (!string.IsNullOrEmpty(result)) { return(Json(new ResultModel() { suc = false, msg = result }, "text/html")); } return(Json(new ResultModel() { suc = true }, "text/html")); }
/// <summary> /// 订料员邮箱 /// </summary> /// <param name="bill"></param> /// <returns></returns> private string GetMatOrderEmail(DRBills bill) { var mat = new UserSv().GetUserByUserName(bill.mat_order_number); if (mat == null) { return(""); } List <string> emails = new List <string>(); if (mat.email != null) { emails.Add(mat.email); } var matGroupUser = new UASv().GetAuditGroupUsers(mat.user_id); emails.AddRange(matGroupUser.Select(m => m.email).ToList()); return(string.Join(",", emails.Distinct().ToArray())); }
public JsonResult SaveUser(FormCollection col) { UsersInfo uInfo = new UsersInfo(); SomeUtils.SetFieldValueToModel(col, uInfo); uInfo.password = SomeUtils.getMD5("000000"); string result = new UserSv().SaveUser(uInfo); if (!string.IsNullOrEmpty(result)) { return(Json(new ResultModel() { suc = false, msg = result }, "text/html")); } return(Json(new ResultModel() { suc = true }, "text/html")); }
public JsonResult ValidateEmail4Password(string userName, string code, string opType) { if (Session["emailCode"] == null) { return(Json(new SRM(false, "请先发送邮箱验证码后再操作"))); } if (!code.Trim().ToUpper().Equals(Session["emailCode"])) { return(Json(new SRM(false, "验证码不正确,请重新输入"))); } string result = ""; try { var uv = new UserSv(); var user = uv.GetUserByUserName(userName); if (opType.Contains("R")) { uv.ResetPassword(user.user_id); result += "登录密码已成功重置为和用户名一致;"; } if (opType.Contains("T")) { if (user.is_forbit) { uv.ToggleUser(user.user_id); } result += "用户已解禁"; } WLog(TAG, userName + ":" + result); } catch (Exception ex) { return(Json(new SRM(ex))); } Session.Remove("emailCode"); return(Json(new SRM(true, result))); }
public JsonResult SendValidateCodeForReset(string userName, string emailAddr) { bool isEmailValid; try { isEmailValid = new UserSv().HasEmailRegister(userName, emailAddr); } catch (Exception ex) { return(Json(new SRM(ex))); } if (!isEmailValid) { return(Json(new SRM(false, "此邮箱地址与贵司在本平台登记的不匹配,请确认后重新输入再发送验证码"))); } //验证通过,可以发送验证码 var code = MyUtils.CreateValidateNumber(6); MyEmail.SendValidateCode(code, emailAddr, userName); Session["emailCode"] = code.ToUpper(); return(Json(new SRM(true, "验证码已发送,请到邮箱收取后复制到验证文本框"))); }
public JsonResult GetUsers(int page, int rows, string searchValue = "") { var users = new UserSv().GetUsers(searchValue); var total = users.Count(); var result = users.Skip((page - 1) * rows).Take(rows) .Select(u => new { u.comment, u.continual_error_times, u.email, u.forbit_date, u.forbit_reason, u.in_date, u.is_forbit, u.last_login_date, u.real_name, u.user_id, u.user_name, u.user_role }) .ToList(); return(Json(new { rows = result, total = total })); }
public ActionResult EmailSetting() { ViewData["email"] = new UserSv().GetUserByUserId(currentUser.userId).email ?? ""; return(View()); }