public ActionResult UpdatePas(FormCollection form)
        {
            string pass  = form["pass"];
            string pass1 = form["pass1"];
            string pass2 = form["pass2"];

            if (!string.IsNullOrEmpty(pass) && !string.IsNullOrEmpty(pass1) && !string.IsNullOrEmpty(pass2))
            {
                pass  = PwdThreeEncrypt.PasswordThreeMd5Encrypt(pass);
                pass1 = PwdThreeEncrypt.PasswordThreeMd5Encrypt(pass1);
                pass2 = PwdThreeEncrypt.PasswordThreeMd5Encrypt(pass2);
            }
            if (pass1 != pass2)
            {
                return(Error("新密码不一致,请重新输入!"));
            }
            UserModel users = new UserModel();

            users = UserModel.FirstOrDefault("  where Password = '******' and Name = '" + MTConfig.CurrentUser.Name + "' ");
            if (users != null && users.Name != "")
            {
                if (UserModel.Update(" set Password = '******' where  name = '" + MTConfig.CurrentUser.Name + "' ") > 0)
                {
                    return(Success(SaveSuccess, "/Admin/User/UpdatePas"));
                }
                else
                {
                    return(Error());
                }
            }
            else
            {
                return(Error("用户密码错误!"));
            }
        }
Example #2
0
        public static UserInfoModel WebLogin(string name, string password)
        {
            password = PwdThreeEncrypt.PasswordThreeMd5Encrypt(password);
            //UserInfoModel user = UserInfoModel.FirstOrDefault("where Email = @0 and Password = @1  ", name, password);
            UserInfoModel user = UserInfoModel.FirstOrDefault("where LoginName = @0 and Password = @1 ", name, password);

            return(user);
        }
Example #3
0
        /// <summary>
        /// 用户添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Add(UserModel model, string[] roleIds)
        {
            UserModel.repo.BeginTransaction();
            StringBuilder sqlLog = new StringBuilder();

            try
            {
                if (string.IsNullOrEmpty(model.CreateMan + ""))
                {
                    model.CreateMan = MTConfig.CurrentUserID.ToInt();
                }
                model.Password = PwdThreeEncrypt.PasswordThreeMd5Encrypt(model.Password);
                string newUserID = UserModel.repo.Insert(model).ToString();
                sqlLog.Append(UserModel.repo.LastCommand + "\n");

                if (roleIds != null)
                {
                    foreach (string roleId in roleIds)
                    {
                        RoleModel roles = new RoleModel();
                        roles = RoleModel.FirstOrDefault("where id = " + roleId);
                        UserProductModel userProduct = new UserProductModel();
                        userProduct.ProductId = roles.ProductId;
                        userProduct.UserId    = newUserID.ToInt();
                        userProduct.Insert();
                        int i = 0;
                        if (int.TryParse(roleId, out i))
                        {
                            UserRoleModel userRole = new UserRoleModel();
                            userRole.UserID    = newUserID.ToInt();
                            userRole.RoleID    = roleId.ToInt();
                            userRole.CreateMan = !string.IsNullOrEmpty(model.CreateMan + "") ? model.CreateMan : MTConfig.CurrentUserID.ToInt();
                            userRole.Insert();
                            sqlLog.Append(UserModel.repo.LastCommand + "\n");
                        }
                    }
                }

                UserModel.repo.CompleteTransaction();
                LogDAL.AppendSQLLog(string.IsNullOrEmpty(model.CreateMan + "") ? MTConfig.CurrentUserID : model.CreateMan + "",
                                    "User", sqlLog.ToString());
            }
            catch (Exception)
            {
                UserModel.repo.AbortTransaction();
                sqlLog = null;
                return(false);
            }

            return(true);
        }
Example #4
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool UpdatePassword(UserViewModel model)
        {
            bool result = false;

            try
            {
                model.ModifyPassword = PwdThreeEncrypt.PasswordThreeMd5Encrypt(model.ModifyPassword);
                int rs = UserModel.Update("set password = @0 where id = @1", model.ModifyPassword, model.Id);
                if (rs == 1)
                {
                    LogDAL.AppendSQLLog(MTConfig.CurrentUserID, "SysUser");
                    result = true;
                }
            }
            catch
            {
                throw;
            }
            return(result);
        }
        public ActionResult UpdatePassword(string oldPwd, string newPwd, string new2Pwd)
        {
            UserInfoModel umInfoModel = UserInfoModel.FirstOrDefault("select * from UserInfo where UserID=@0", MTConfig.CurrentUserInfo.UserID);

            if (newPwd != new2Pwd)
            {
                return(JsonError(Passowrd1));
            }
            if (PwdThreeEncrypt.PasswordThreeMd5Encrypt(oldPwd) != umInfoModel.Password)
            {
                return(JsonError(Passowrd2));
            }
            umInfoModel.Password = PwdThreeEncrypt.PasswordThreeMd5Encrypt(newPwd);
            if (umInfoModel.Update() > 0)
            {
                return(JsonSuccess(SaveSuccess));
            }
            else
            {
                return(JsonError(SaveError));
            }
        }
Example #6
0
 /// <summary>
 /// 登陆
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool Login(ref UserModel model)
 {
     model = UserModel.FirstOrDefault("where Name=@0 and Password=@1 and DelFlag=0", model.Name, PwdThreeEncrypt.PasswordThreeMd5Encrypt(model.Password));
     LogDAL.AppendSQLLog(MTConfig.CurrentUserID, "User");
     return(model != null);
 }
        public ActionResult Login(UserModel model, string verify, string remember)
        {
            UserAuthModel auth = null;

            if (string.IsNullOrWhiteSpace(model.Name))
            {
                return(Json(new { status = 0, msg = "请输入用户名" }, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrWhiteSpace(model.Password))
            {
                return(Json(new { status = 0, msg = "请输入密码" }, JsonRequestBehavior.AllowGet));
                //return Content("tipreadurl('请输入密码','/Admin/Public/Login');", "application/x-javascript");
            }
            if (verify.ToLower() != Session[MTConfig.VerifCodeKey].ToString().ToLower())
            {
                return(Json(new { status = 2, msg = "验证码错误" }, JsonRequestBehavior.AllowGet));
            }
            model.Name           = model.Name.Replace("@", "@@");
            model.Password       = model.Password.Replace("@", "@@");
            model.Password       = PwdThreeEncrypt.PasswordThreeMd5Encrypt(model.Password);
            MTConfig.CurrentUser = UserDAL.Login(model.Name, model.Password);

            if (MTConfig.CurrentUser != null && !string.IsNullOrEmpty(MTConfig.CurrentUser.ID))
            {
                auth = UserDAL.GetAuth(MTConfig.CurrentUser.ID.ToInt());
                if (auth.RoleList == null || auth.RoleList.Count < 1)
                {
                    return(Json(new { status = 3, msg = "该账号不存在" }, JsonRequestBehavior.AllowGet));
                    //return Content("tipreadurl('该账号不存在','/Admin/Public/Login');", "application/x-javascript");
                }

                #region 获取用户登录信息并保存 IP地址与地理位置

                //IpToAddress ipadd = new IpToAddress();
                //LoginInfoModel logininfo = new LoginInfoModel();
                //string ip = ipadd.GetRealIP();
                //if (ip == "::1")
                //{
                //    logininfo.Address = "开发地址登录";
                //    logininfo.Ip = "127.0.0.1";
                //}
                //else
                //{
                //    logininfo.Ip = ip;
                //    //根据ip地址获取ip归属地
                //    string address = ipadd.GetIpAddress(ip);
                //    logininfo.Address = address;
                //}

                //logininfo.UserId = MTConfig.CurrentUser.Id.ToInt();
                //logininfo.LoginTime = DateTime.Now;
                //logininfo.Insert();

                #endregion

                if (!string.IsNullOrEmpty(remember))
                {
                    HttpCookie cookie = new HttpCookie(MTConfig.LoginRememberCookie);
                    cookie.Values[MTConfig.UserInfoKey] = model.ID;
                    cookie.Expires = DateTime.MaxValue;
                    Response.Cookies.Add(cookie);
                }
                return(Json(new { status = 1, msg = "成功" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = 3, msg = "用户名或密码错误" }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult RegistUser(UserInfoModel model, string cofmemail = "", string cofmpassword = "", int IsEmployee = 0)
        {
            if (string.IsNullOrEmpty(model.Sex.ToString()))
            {
                return(JsonError(SexError));
            }
            if (string.IsNullOrEmpty(model.Zip.ToString()) || string.IsNullOrEmpty(model.Address))
            {
                return(JsonError(ZipAddressError));
            }
            if (string.IsNullOrEmpty(model.UserName))
            {
                return(JsonError(UserNameError));
            }
            if (string.IsNullOrEmpty(model.Email))
            {
                return(JsonError(Email1));
            }
            if (string.IsNullOrEmpty(model.Phone))
            {
                return(JsonError(Phone1));
            }
            if (model.Email != cofmemail)
            {
                return(JsonError(Email5));
            }
            //邮箱作为登录名是否已经使用,(该方法不会用来注册代理,所以直接判断邮箱就行了,不用考虑代理号登录)
            UserInfoModel userInfo = UserInfoModel.FirstOrDefault("select * from UserInfo where LoginName=@0", model.Email);

            if (userInfo != null)
            {
                return(JsonError(Email3));
            }
            //两次密码是否一致
            if (model.Password != cofmpassword)
            {
                return(JsonError(Passowrd1));
            }
            if (Regex.IsMatch(model.Password, "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$") == false)
            {
                return(JsonError(PassowrdRegex));
            }
            model.Password = PwdThreeEncrypt.PasswordThreeMd5Encrypt(model.Password);
            Regex r = new Regex("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$");

            if (!r.IsMatch(model.Email))
            {
                return(JsonError(Email2));
            }
            if (MTConfig.UserLang + "" == "")
            {
                model.Lang = "Cn";
            }
            else
            {
                model.Lang = MTConfig.UserLang;
            }
            //名字插入
            //if (model.Lang == "En")
            //{
            //    //model.UserNameCn = model.UserName;
            //}
            //else
            //{
            //    if (string.IsNullOrEmpty(model.UserName))
            //    {
            //        return JsonError(UserNameError);
            //    }
            //}

            //获取国家电话前缀
            if (model.Country != null)
            {
                CountryModel countrycode = CountryModel.FirstOrDefault(" where ID = @0", model.Country);
                if (countrycode != null)
                {
                    model.CountryCode = countrycode.AreaCode;
                }
            }
            bool result = Regex.IsMatch(model.Phone, @"^1[3|4|5|7|8][0-9]{9}$");

            if (result == false)
            {
                return(JsonError(Phone2));
            }
            model.LastLoginTime = DateTime.Now;
            model.Birthday      = DateTime.Now;
            //给用户更新登录名
            model.LoginName = model.Email;
            //给IB赋值 A代理没有IB
            UserInfoModel IBModel = new UserInfoModel();

            if (model.Insert() != null)
            {
                return(JsonSuccess(SaveSuccess));
            }
            return(JsonError(SaveError));
        }