Exemplo n.º 1
0
        /// <summary>
        /// 验证登陆
        /// </summary>
        /// <param name="condtion"></param>
        /// <returns></returns>
        public static SysManagerUser checkLogin(ViewModelLoginReqeust condtion)
        {
            SysValidata.valiData(condtion);
            using (var db = new SysModelContainer()) {
                //如果还没有用户则需要初始化一个第一个管理员
                int c = (from x in db.Db_SysUserSet.OfType <Db_ManagerUser>() select x.loginName).Count();
                if (c == 0)
                {
                    create(new ViewModelUserRegisterRequest()
                    {
                        fullName  = "管理员",
                        loginname = "admin",
                        role      = "admin"
                    });
                }

                var d = db.Db_SysUserSet.OfType <Db_ManagerUser>().SingleOrDefault(p => p.loginName.Equals(condtion.loginName) && p.passWord.ToLower().Equals(condtion.pwd.ToLower()) && !p.isDeleted && !p.isDisabled);
                if (d == null)
                {
                    throw new SysException("用户名或密码不正确", condtion);
                }
                d.lastLoginTime = DateTime.Now;
                db.SaveChanges();
                SysManagerUser user = new SysManagerUser(condtion.loginName);
                SysUserLog.saveLoginLog(user.loginName);
                return(user);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建新的用户
        /// </summary>
        /// <param name="condtion"></param>
        /// <returns></returns>
        public static SysManagerUser create(ViewModelUserRegisterRequest condtion)
        {
            SysValidata.valiData(condtion);
            int c = getLoginNameCount(condtion.loginname);

            if (c > 0)
            {
                throw new SysException("登录名已存在", condtion);
            }
            using (var db = new SysModelContainer()) {
                Db_ManagerUser dbuser = new Db_ManagerUser()
                {
                    createdOn   = DateTime.Now,
                    fullName    = condtion.fullName,
                    isDeleted   = false,
                    isDisabled  = false,
                    jobTitle    = condtion.jobTitle,
                    loginName   = condtion.loginname,
                    mobilePhone = condtion.mobilePhone,
                    passWord    = defaultPwd,
                    role        = condtion.role
                };
                db.Db_SysUserSet.Add(dbuser);
                db.SaveChanges();
            }
            SysManagerUser newuser = new SysManagerUser(condtion.loginname);

            SysUserLog.saveLog(condtion, SysUserLogType.编辑, newuser.loginName);
            return(newuser);
        }