Esempio n. 1
0
        /// <summary>
        /// 更新用户数据
        /// </summary>
        /// <param name="svrUserInfo"></param>
        /// <returns></returns>
        public int UpdateUser(SvrUserInfo svrUserInfo)
        {
            if (svrUserInfo.OrgId == 0)
            {
                throw new QWF.Framework.GlobalException.UIValidateException("机构ID为NULL");
            }

            //开始
            using (var db = DbAccess.DbFrameworkContext.Create())
            {
                var userHelper = new BLL.UserHelper(db, this.svrUser);

                BLL.User user = userHelper.GetUserInfoById(svrUserInfo.UserId);
                if (user == null)
                {
                    throw new QWF.Framework.GlobalException.UIValidateException(string.Format("用户ID=【{0}】不存在!", svrUserInfo.UserId));
                }


                //密码不为空则修改密码
                if (!svrUserInfo.PassWord.StrValidatorHelper().StrIsNullOrEmpty())
                {
                    user.DbModel.PassWord = svrUserInfo.PassWord;
                }

                if (!svrUserInfo.UserCode.StrValidatorHelper().StrIsNullOrEmpty())
                {
                    user.DbModel.UserCode = svrUserInfo.UserCode;
                }

                //必要字段

                user.DbModel.OrgId       = svrUserInfo.OrgId;
                user.DbModel.Leader      = svrUserInfo.Leader ? 1 : 0;
                user.DbModel.QQ          = svrUserInfo.Realname;
                user.DbModel.Realname    = svrUserInfo.Realname;
                user.DbModel.Tel         = svrUserInfo.Tel;
                user.DbModel.Phone       = svrUserInfo.Phone;
                user.DbModel.Email       = svrUserInfo.Email;
                user.DbModel.Position    = svrUserInfo.Position;
                user.DbModel.Weixin      = svrUserInfo.Weixin;
                user.DbModel.Fax         = svrUserInfo.Fax;
                user.DbModel.UserRemarks = svrUserInfo.UserRemarks;

                if (svrUserInfo.UserStatus == SvrUserInfo.UserStatusEnum.正常 || svrUserInfo.UserStatus == SvrUserInfo.UserStatusEnum.禁用)
                {
                    user.DbModel.UserStatus = (int)svrUserInfo.UserStatus;
                }

                //修改者
                user.DbModel.UpdateUserId = this.svrUser.UserId;
                user.DbModel.UpdateTime   = DateTime.Now;
                //保存修改
                db.SaveChanges();

                return(user.GetNewUserId());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// /
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="userName"></param>
        /// <param name="passWord">由客户端决定加密的方式</param>
        /// <returns></returns>
        public bool CheckUserLogin(string appId, string userName, string passWord)
        {
            if (userName.StrValidatorHelper().StrIsNullOrEmpty())
            {
                throw new Framework.GlobalException.UIValidateException("用户名不能为空");
            }
            if (passWord.StrValidatorHelper().StrIsNullOrEmpty())
            {
                throw new Framework.GlobalException.UIValidateException("密码不能为空");
            }

            using (var qwfContext = DbAccess.DbFrameworkContext.Create())
            {
                var                 ip          = QWF.Framework.Web.QWFRequest.GetIP();
                BLL.UserHelper      users       = new BLL.UserHelper(qwfContext, svrUserIdentifier);
                BLL.UserLoginHelper loginHelper = new BLL.UserLoginHelper(qwfContext, svrUserIdentifier);

                var log = new SvrModels.SvrLoginLog();
                log.AppId    = appId;
                log.Ip       = ip;
                log.UserName = userName;
                try
                {
                    BLL.User user = users.GetUserInfo(userName);

                    if (user.GetPassword() != passWord)
                    {
                        log.Remarks = userName + "的密码错误!";
                        throw new UserValidateException(log.Remarks);
                    }

                    user.UpdateLoginLog(ip);
                    user.SetUserTokenCookie(appId);

                    //保存所有修改
                    log.LoginStatus = SvrModels.SvrLoginLoginStauts.Success;
                    loginHelper.Add(log);

                    qwfContext.SaveChanges();
                }
                catch (UserValidateException uex)
                {
                    //写入登录日志
                    log.LoginStatus = SvrModels.SvrLoginLoginStauts.Error;
                    log.Remarks     = uex.Message;

                    loginHelper.Add(log);
                    qwfContext.SaveChanges();

                    throw uex;
                }
                return(true);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 创建用户接口
        /// </summary>
        /// <param name="svrUserInfo"></param>
        /// <returns></returns>
        public int CreateUser(SvrUserInfo svrUserInfo)
        {
            //开始
            using (var db = DbAccess.DbFrameworkContext.Create())
            {
                var      userHelper = new BLL.UserHelper(db, this.svrUser);
                BLL.User user       = userHelper.CreateUserInfo(svrUserInfo);
                //保存修改
                db.SaveChanges();

                return(user.GetNewUserId());
            }
        }
Esempio n. 4
0
        public bool ResetPassword(int userId, string oldPassword, string newPassword)
        {
            using (var db = DbAccess.DbFrameworkContext.Create())
            {
                var helper = new BLL.UserHelper(db, svrUser);
                var user   = helper.GetUserInfoById(userId);
                if (user != null)
                {
                    if (user.GetPassword() != oldPassword.StringHelper().EncodeMD5())
                    {
                        throw new QWF.Framework.GlobalException.UIValidateException("旧密码不正确");
                    }

                    user.ResetPassword(newPassword.StringHelper().EncodeMD5());
                }
                db.SaveChanges();
            }

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type">DelUser,StopUser,StartUser</param>
        /// <param name="userIds"></param>
        /// <returns></returns>
        public bool OrderUser(string type, List <string> userIds)
        {
            if (userIds.Count == 0)
            {
                return(true);
            }

            using (var db = DbAccess.DbFrameworkContext.Create())
            {
                foreach (var userid in userIds)
                {
                    var userHelper = new BLL.UserHelper(db, this.svrUser);
                    //获取用户对象
                    var user = userHelper.GetUserInfoById(userid.SafeConvert().ToInt32(0));

                    if (user != null)
                    {
                        switch (type)
                        {
                        case "DelUser":
                            user.DelUser();
                            break;

                        case "StopUser":
                            user.StopUser();
                            break;

                        case "StartUser":
                            user.StartUser();
                            break;
                        }
                    }
                }
                //一次提交
                db.SaveChanges();
            }

            return(true);
        }
Esempio n. 6
0
 public User(DbAccess.T_QWF_User dbModel, DbAccess.DbFrameworkContext db, UserHelper helper)
 {
     //初始化数据
     this.helper  = helper;
     this.dbModel = dbModel;
 }