Beispiel #1
0
        public JsonResult AddOrUpdateUser(User user)
        {
            var bl = false;

            if (user.UserId > 0)
            {
                var model = UserBll.GetUserByID(user.UserId);
                model.UserName = user.UserName;
                model.RealName = user.RealName;
                model.Mobile   = user.Mobile;
                if (!string.IsNullOrEmpty(user.PassWord))
                {
                    model.RealName = DESEncrypt.GetMD5String(user.PassWord);
                }
                bl = UserBll.Update(model);
            }
            else
            {
                //新建
                user.PassWord   = DESEncrypt.GetMD5String(user.PassWord);
                user.CreateTime = DateTime.Now;
                user.Status     = 0;
                bl = UserBll.Add(user) > 0;
            }

            if (bl)
            {
                return(Json(JsonHandler.CreateMessage(1, "操作成功")));
            }
            else
            {
                return(Json(JsonHandler.CreateMessage(-1, "操作失败")));
            }
        }
Beispiel #2
0
        public string RegistIn(FormCollection collection)
        {
            var userName = collection.Get("username");
            var password = collection.Get("password");
            var email    = collection.Get("email");
            var phone    = collection.Get("phone");

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                return(HttpRequestResult.StateNotNull);
            }
            var user = new User
            {
                UserName   = userName,
                PassWord   = password,
                Email      = email,
                PhoneNum   = phone,
                IsEnable   = true,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };

            if (_userBll.Exists(user.UserName))
            {
                return(HttpRequestResult.StateExisted);
            }
            var flag = _userBll.Add(user);

            if (flag > 0)
            {
                return(HttpRequestResult.StateOk);
            }
            return(HttpRequestResult.StateError);
        }
Beispiel #3
0
        public IActionResult Add(User model)
        {
            var rst = new ApiResult <bool>();

            var bll = new UserBll();

            if (model.id == 0)
            {
                model.user_id = EncryptHelper.CreateGuid();
                if (string.IsNullOrEmpty(model.password))
                {
                    model.password = "******";
                }
                model.password = EncryptHelper.MD5Encrypt(model.password);
                rst            = bll.Add(model);
            }
            else
            {
                if (!string.IsNullOrEmpty(model.password))
                {
                    model.password = EncryptHelper.MD5Encrypt(model.password);
                }
                rst = bll.UpdateUser(model);
            }

            return(Json(rst));
        }
Beispiel #4
0
        public string Regist(string userName, string passWord)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord))
            {
                return("用户名不能为空");
            }
            var exist = _userBll.Exists(userName);

            if (exist)
            {
                return("用户名已存在");
            }
            var model = new User
            {
                UserName   = userName,
                PassWord   = passWord,
                IsEnable   = true,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };
            var result = _userBll.Add(model);

            if (result > 0)
            {
                Session.Add("user", model);
                return(HttpRequestResult.StateOk);
            }
            return(HttpRequestResult.StateError);
        }
Beispiel #5
0
        public TEntity Post(TEntity item)
        {
            if (item == null)
            {
                return(null);
            }
            var dbItem = item.ToDbModel();
            var result = dbSet.Add(dbItem);

            return(result ? item : null);
        }
Beispiel #6
0
        public IActionResult Register(User model)
        {
            var rst = new ReturnResult <bool>();

            using var bll = new UserBll();
            model.user_id = EncryptHelper.CreateGuid();
            model.role_id = GlobalConfig.RegRoleId;
            if (string.IsNullOrEmpty(model.password))
            {
                model.password = "******";
            }
            model.password = EncryptHelper.MD5Encrypt(model.password);
            rst            = bll.Add(model);

            return(Json(rst));
        }
Beispiel #7
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            UserInfo user = new UserInfo();

            user.UserName = context.Request["UserName"];
            string passwrod = context.Request["Password"];

            if (passwrod != context.Request["Password1"])
            {
                context.Response.Write("密码不一致!");
                return;
            }
            else if (user.UserName.Length < 6 || user.UserName.Length > 16 || passwrod.Length < 6 || passwrod.Length > 16)
            {
                context.Response.Write("用户名或密码的长度过短或过长!!!");
                return;
            }
            UserBll bll = new UserBll();

            if (bll.ExistByUserName(user.UserName))//检验用户是否存在
            {
                context.Response.Write("用户名已存在!!");
                return;
            }
            user.Password = passwrod;
            user.Mail     = context.Request["Email"];
            if (!user.Mail.Contains("@"))//校验邮箱
            {
                context.Response.Write("邮箱格式不正确!!");
                return;
            }
            user.Name   = context.Request["Name"];
            user.Sex    = context.Request["Sex"] == "男";
            user.Region = context.Request["Region"];

            //调用 业务逻辑层 添加数据方法 保存到数据库
            if (bll.Add(user))
            {
                context.Response.Write("Ok");
            }
            else
            {
                context.Response.Write("No!");
            }
        }
Beispiel #8
0
        public string Add(User model)
        {
            var rst = new ReturnResult <bool>();
            var bll = new UserBll();

            if (model.Id == 0)
            {
                model.CreateTime = DateTime.Now;
                rst = bll.Add(model);
            }
            else
            {
                rst = bll.Update(model);
            }

            return(JsonHelper.Instance.Serialize(rst));
        }
Beispiel #9
0
        /// <summary>
        /// 登录成功保存数据
        /// </summary>
        private void LoginSuccess()
        {
            if (m_loginUser != null)
            {
                if (cbUserName.Text != m_loginUser.UserName || m_nSelectedPlatformId != m_loginUser.PlatformId)
                {
                    //登录用户名不同或者平台不同,则原登录用户最近一次登录置为false并更新
                    m_loginUser.RecentLogin = false;
                    m_bllUser.Update(m_loginUser);
                }
            }

            User user  = m_bllUser.GetUserForName(cbUserName.Text, m_nSelectedPlatformId);
            bool IsNew = false;      //是否是新建用户

            if (user == null)
            {
                //没有该用户,则新建
                IsNew = true;
                user  = new User();
            }

            user.UserName    = cbUserName.Text;
            user.PlatformId  = m_nSelectedPlatformId;
            user.RememberPwd = cbkRememberPwd.Checked;
            if (cbkRememberPwd.Checked)
            {
                user.UserPwd = Encrypt.DES3Encrypt(tbUserPwd.Text, Encrypt.MD5Encrypt(cbUserName.Text));
            }
            else
            {
                user.UserPwd = string.Empty;
            }
            user.AutoLogin   = cbkAutoLogin.Checked;
            user.RecentLogin = true;

            if (IsNew)
            {
                m_bllUser.Add(user);
            }
            else
            {
                m_bllUser.Update(user);
            }
        }