public ActionResult Userinfo(int?id, string returnurl, string ephone, string eemail) { if (!string.IsNullOrWhiteSpace(ephone)) { ModelState.AddModelError("mobile", "请修改您的手机号码!"); } if (!string.IsNullOrWhiteSpace(eemail)) { ModelState.AddModelError("email", "请修改您的邮箱地址!"); } List <Entity.advt_user_group> ladvt_user_group = BLL.Login.GetAllUserGroup(); ViewBag.ladvt_user_group = ladvt_user_group; Entity.advt_users info = new advt_users(); if (UserContext.roles == (int)Entity.Status.RoleStatus.Admin) { if (id != null) { info = Data.advt_users.Get_advt_users(id ?? 0); } else { info = UserContext; } } else { info = UserContext; } ViewBag.id = info.id; if (info != null) { info.nickname = (info.nickname ?? string.Empty).Trim(); info.phone = (info.phone ?? string.Empty).Trim(); info.qq = (info.qq ?? string.Empty).Trim(); info.msn = (info.msn ?? string.Empty).Trim(); info.email = (info.email ?? string.Empty).Trim(); } return(View(info)); }
public ActionResult ChangePassword(int?id) { Entity.advt_users info = new advt_users(); if (UserContext.roles == (int)Entity.Status.RoleStatus.Admin) { if (id != null) { info = Data.advt_users.Get_advt_users(id ?? 0); } else { info = UserContext; } } else { info = UserContext; } ViewBag.Userinfo = info; ViewBag.id = info.id; return(View()); }
public ActionResult Login(Model.LoginModel model, string returnUrl) { var IsLogin = ""; try { if (ModelState.IsValid) { string[] SplitAccount = new string[] { }; var username = ""; Entity.advt_users users = new advt_users(); Regex RegEmail = new Regex(@"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?");//w 英文字母或数字的字符串,和 [a-zA-Z0-9] 语法一样 Match m = RegEmail.Match(model.UserName); //工号 var wuser = Data.ExamUsersFromehr.Get_ExamUsersFromehr(new { UserCode = model.UserName }); if (wuser != null) { Service.IProvider.IAuthorizationServices services = new Service.Provider.AuthorizationServices(); users = services.EmailAuthenticate(wuser.CommpanyEmail, model.Password); if (users != null) //验证通过 { username = wuser.EamilUsername; } else { IsLogin = "******"; } } var cuser = Data.ExamUsersFromehr.Get_ExamUsersFromehr(new { EamilUsername = model.UserName }); if (cuser != null) { var acc = "acn\\" + cuser.EamilUsername.Trim(); SplitAccount = acc.Split('\\'); username = cuser.EamilUsername; } if (cuser != null) { if (SplitAccount.Length > 1) { String adPath = ""; //Fully-qualified Domain Name switch (SplitAccount[0].ToLower().Trim()) { case "acn": adPath = "LDAP://acn.advantech.corp"; //acn break; case "aeu": adPath = "LDAP://aeu.advantech.corp"; //advantech break; case "aus": adPath = "LDAP://aus.advantech.corp"; //advantech break; case "advantech": adPath = "LDAP://advantech.corp"; //advantech break; default: adPath = "LDAP://acn.advantech.corp"; //acn break; } LdapAuthentication adAuth = new LdapAuthentication(adPath); string password = model.Password.Trim(); if (true == adAuth.IsAuthenticated(SplitAccount[0], SplitAccount[1], model.Password)) { Service.IProvider.IAuthorizationServices service = new Service.Provider.AuthorizationServices(); users = service.Authenticate(username, model.Password); } else { IsLogin = "******"; } } } if (wuser == null && cuser == null) { IsLogin = "******"; } if (string.IsNullOrEmpty(IsLogin) && !string.IsNullOrEmpty(users.username)) { SetUserAuthIn(users.username.ToString(), users.password, string.Empty, false); //写入Cookie,无需登入。 var LF = Guid.NewGuid().ToString(); //写内存 Manager.Login.Lock_Flag = LF; //写本地 Utils.WriteCookie("ALock", LF); users.msn = LF; advt.Data.advt_users.Update_advt_users(users, null, new string[] { "id" }); XUtils.WriteUserCookie(users, model.CookieTime ?? 0, Config.BaseConfigs.Passwordkey, 1); IsLogin = "******"; } } } catch (Exception ex) { return(Json(new { IsLogin = ex.Message }, JsonRequestBehavior.AllowGet)); throw; } //ModelState.AddModelError("", "用户名或者密码错误!"); return(Json(new { IsLogin }, JsonRequestBehavior.AllowGet)); }
public ActionResult ChangePassword(int?id, Model.LocalPasswordModel model) { Entity.advt_users info = new advt_users(); if (UserContext.roles == (int)Entity.Status.RoleStatus.Admin) { if (id != null) { info = Data.advt_users.Get_advt_users(id ?? 0); } else { info = UserContext; } } else { info = UserContext; } if (info == null) { ModelState.AddModelError("", "系统错误!"); } if (ModelState.IsValid) { ViewBag.Userinfo = info; ViewBag.id = info.id; bool changePasswordSucceeded = false; try { if (ModelState.IsValid) { string pwd = Utils.MD5(model.OldPassword); if (UserContext.roles == (int)Entity.Status.RoleStatus.Admin || info.password == pwd) { info.password = Utils.MD5(model.NewPassword); int result_i = Data.advt_users.Update_advt_users(info, null, new string[] { "id" }); changePasswordSucceeded = result_i == 1; } } } catch (Exception) { changePasswordSucceeded = false; } if (changePasswordSucceeded) { XUtils.WriteUserCookie(info, 0, Config.BaseConfigs.Passwordkey, 1); right("修改密码成功!"); } else { ModelState.AddModelError("", "当前的密码是不正确的或新的密码是无效的!"); } } return(View(model)); }
public ActionResult Userinfo(Entity.advt_users info, string returnurl) { List <Entity.advt_user_group> ladvt_user_group = BLL.Login.GetAllUserGroup(); ViewBag.ladvt_user_group = ladvt_user_group; Entity.advt_users tp_info = new advt_users(); if (ModelState.IsValid) { if (UserContext.roles == (int)Entity.Status.RoleStatus.Admin) { } else { if (info.id != UserContext.id) { alert("非法操作!", Url.Action("Userinfo", "Account", new { Area = "" })); ModelState.AddModelError("", "非法操作!"); } } if (ModelState.IsValid && !string.IsNullOrWhiteSpace(info.nickname) && !BLL.Login.CheckUserName(info.nickname)) { ModelState.AddModelError("nickname", "昵称 格式不正确!"); } if (ModelState.IsValid && string.IsNullOrWhiteSpace(info.firstname)) { ModelState.AddModelError("firstname", "姓 不能为空!"); } if (ModelState.IsValid && !BLL.Login.CheckUserName(info.firstname)) { ModelState.AddModelError("firstname", "姓 格式不正确!"); } if (ModelState.IsValid && string.IsNullOrWhiteSpace(info.lastname)) { ModelState.AddModelError("lastname", "名字 不能为空!"); } if (ModelState.IsValid && !BLL.Login.CheckUserName(info.lastname)) { ModelState.AddModelError("lastname", "名字 格式不正确!"); } if (ModelState.IsValid && Utils.IsInt(((Entity.Status.Sex)info.sex).ToString())) { ModelState.AddModelError("sex", "性别填写有误!"); } if (ModelState.IsValid && !string.IsNullOrWhiteSpace(info.phone) && !BLL.Login.CheckPhone(info.phone)) { ModelState.AddModelError("phone", "电话 格式不正确!"); } if (ModelState.IsValid && !string.IsNullOrWhiteSpace(info.email) && !Common.Utils.IsValidEmail(info.email)) { ModelState.AddModelError("email", "e-Mail 格式不正确!"); } tp_info = Data.advt_users.Get_advt_users(info.id); if (ModelState.IsValid && tp_info == null) { ModelState.AddModelError("", "系统错误,请重试!"); } if (ModelState.IsValid) { int rst = 0; try { tp_info.nickname = info.nickname; tp_info.phone = info.phone; tp_info.qq = info.qq; tp_info.msn = info.msn; tp_info.email = info.email; tp_info.description = info.description; tp_info.firstname = info.firstname; tp_info.lastname = info.lastname; tp_info.sex = info.sex; if (UserContext.roles == (int)Entity.Status.RoleStatus.Admin) { tp_info.status = info.status; tp_info.usergroupid = info.usergroupid; } rst = Data.advt_users.Update_advt_users(tp_info, null, new string[] { "id" }); if (rst == 1) { if (info.id == UserContext.id) { Manager.Login.UserContext = null; } right("修改成功!"); if (!string.IsNullOrEmpty(returnurl)) { return(Redirect(returnurl)); } } else { alert("插入失败!"); } } catch { alert("系统错误,请联系管理员!"); } } } return(View(tp_info)); }