Пример #1
0
        public void ChangePassword(Guid userId, String password)
        {
            String secpw = Md5Helper.GetMD5String(password);
            String sql   = String.Format("update bpsys_user set password='******' where id='{1}'", secpw, userId);

            using (DataBaseProcess process = new DataBaseProcess())
            {
                process.Exec(sql);
            }
        }
Пример #2
0
        public static string AddUser(string Userstr)
        {
            string str = string.Empty;

            try
            {
                tbUser tb       = JsonConvert.DeserializeObject <tbUser>(Userstr);
                string passWord = Base64Helper.DecodeBase64(tb.Password);
                string password = Md5Helper.GetMD5String(passWord);
                tbUser newtb    = new tbUser()
                {
                    AccountName = tb.AccountName,
                    CreateBy    = tb.CreateBy,
                    CreateTime  = DateTime.Now,
                    Description = tb.Description,
                    Email       = tb.Email,
                    IfChangePwd = tb.IfChangePwd,
                    IsAble      = tb.IsAble,
                    MobilePhone = tb.MobilePhone,
                    Password    = password,
                    RealName    = tb.RealName,
                    UpdateTime  = DateTime.Now,
                    UpdateBy    = tb.CreateBy
                };
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbUser.Where(p => p.AccountName == newtb.AccountName).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("帐号名:{0}重复,请重新输入", newtb.AccountName));
                }
                DataCount = myDbContext.tbUser.Where(p => p.Email == newtb.Email).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("邮箱:{0}重复,请重新输入", newtb.Email));
                }
                DataCount = myDbContext.tbUser.Where(p => p.MobilePhone == newtb.MobilePhone).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("手机号:{0}重复,请重新输入", newtb.MobilePhone));
                }
                myDbContext.tbUser.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
Пример #3
0
        public static string UpdateUserAllinfo(string Userstr)
        {
            string str = string.Empty;

            try
            {
                tbUser            tb          = JsonConvert.DeserializeObject <tbUser>(Userstr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbUser            data        = myDbContext.tbUser.Where(p => p.ID == tb.ID).FirstOrDefault();
                string            passWord    = Base64Helper.DecodeBase64(tb.Password);
                string            password    = Md5Helper.GetMD5String(passWord);
                data.AccountName = tb.AccountName;
                data.Description = tb.Description;
                data.Email       = tb.Email;
                data.IfChangePwd = tb.IfChangePwd;
                data.IsAble      = tb.IsAble;
                data.MobilePhone = tb.MobilePhone;
                data.Password    = password;
                data.RealName    = tb.RealName;
                data.UpdateBy    = tb.UpdateBy;
                data.UpdateTime  = DateTime.Now;


                int DataCount = myDbContext.tbUser.Where(p => p.AccountName == data.AccountName && p.ID != data.ID).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("帐号名:{0}重复,请重新输入", data.AccountName));
                }
                DataCount = myDbContext.tbUser.Where(p => p.Email == data.Email && p.ID != data.ID).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("邮箱:{0}重复,请重新输入", data.Email));
                }
                DataCount = myDbContext.tbUser.Where(p => p.MobilePhone == data.MobilePhone && p.ID != data.ID).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("手机号:{0}重复,请重新输入", data.MobilePhone));
                }

                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
Пример #4
0
        private HandlingResult ValidateBeforeSave()
        {
            HandlingResult result = new HandlingResult();

            result.Successed = true;
            UserModel model = new UserModel();

            model.Name      = textBoxName.Text.TrimStart().TrimEnd();
            model.Phone     = textBoxPhone.Text.TrimStart().TrimEnd();
            model.Password  = textBoxPassword.Text;
            model.LoginName = textBoxLoginName.Text.TrimStart().TrimEnd();
            if (comboBoxStore.SelectedValue != null)
            {
                model.StoreId = Guid.Parse(comboBoxStore.SelectedValue.ToString());
            }
            if (String.IsNullOrEmpty(model.LoginName))
            {
                result.Message  += "\r\n请录入登录名";
                result.Successed = false;
            }
            if (String.IsNullOrEmpty(model.Name))
            {
                result.Message  += "\r\n请录入姓名";
                result.Successed = false;
            }
            if (String.IsNullOrEmpty(model.Password))
            {
                result.Message  += "\r\n请录入登录密码";
                result.Successed = false;
            }
            else
            {
                model.Password = Md5Helper.GetMD5String(model.Password);
            }
            if (model.StoreId == null || model.StoreId == Guid.Empty)
            {
                result.Message  += "\r\n请选择门店";
                result.Successed = false;
            }
            model.Id      = Guid.NewGuid();
            result.Result = model;
            return(result);
        }
Пример #5
0
        public HandlingResult ValidateLogin(UserValidationModel model)
        {
            HandlingResult result = new HandlingResult();

            result.Successed = false;
            DataTable dt  = null;
            String    sql = String.Format("SELECT * FROM BPSYS_USER WHERE LOGINNAME='{0}'", model.LoginName);

            using (DataBaseProcess process = new DataBaseProcess())
            {
                dt = process.Query(sql);
            }
            if (dt != null && dt.Rows.Count > 0)
            {
                UserInformationModel usermodel = new UserInformationModel()
                {
                    Id        = Guid.Parse(dt.Rows[0]["ID"].ToString()),
                    LoginName = dt.Rows[0]["LOGINNAME"].ToString(),
                    Name      = dt.Rows[0]["NAME"].ToString(),
                    StoreId   = dt.Rows[0]["STOREID"].ToString(),
                };
                String pw = Md5Helper.GetMD5String(model.Password);
                if (pw.Equals(dt.Rows[0]["PASSWORD"].ToString()))
                {
                    result.Result    = usermodel;
                    result.Successed = true;
                }
                else
                {
                    result.Message = "用户名或密码错误!";
                }
            }
            else
            {
                result.Message = "用户名或密码错误";
            }
            return(result);
        }
Пример #6
0
        public static string GetUserByAccountName(string accountName, string passWord, string address, string port)
        {
            string str = string.Empty;

            try
            {
                passWord = Base64Helper.DecodeBase64(passWord);
                string md5passWord = Md5Helper.GetMD5String(passWord);
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                UserInfoModel     temp        = new UserInfoModel();
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                List <tbUser>     templist    = myDbContext.tbUser.Where(p => p.AccountName == accountName).ToList();
                if (templist != null && templist.Count > 0)
                {
                    tbUser tempUser = templist[0];
                    if (tempUser.Password == md5passWord)
                    {
                        if (tempUser.IsAble != 1)
                        {
                            throw new Exception("帐号未启用!");
                        }

                        string   Token       = Guid.NewGuid().ToString();
                        DateTime newDataTime = DateTime.Now;

                        List <tbUserToken> tempOldTokenlist = myDbContext.tbUserToken.Where(p => p.UserId == tempUser.ID && p.IsLoginOut != 1).ToList();
                        foreach (var st in tempOldTokenlist)
                        {
                            st.IsLoginOut = 1;
                        }

                        tbUserToken newtb = new tbUserToken();
                        newtb.UserId     = tempUser.ID;
                        newtb.Token      = Token;
                        newtb.CreateTime = newDataTime;
                        newtb.UpdateTime = newDataTime;
                        newtb.Address    = address;
                        newtb.Port       = port;
                        newtb.IsLoginOut = 0;
                        myDbContext.tbUserToken.Add(newtb);
                        myDbContext.SaveChanges();

                        temp.ID          = tempUser.ID;
                        temp.AccountName = tempUser.AccountName;
                        temp.CreateTime  = DateTime.Now;
                        temp.RealName    = tempUser.RealName;

                        temp.Token      = Token;
                        temp.CreateTime = newDataTime;
                        str             = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                        str             = ResponseHelper.ResponseMsg("1", "取数成功", str);
                    }
                    else
                    {
                        str = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                        str = ResponseHelper.ResponseMsg("-1", "密码错误", str);
                    }
                }
                else
                {
                    str = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("-1", "用户不存在", str);
                }
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }