コード例 #1
0
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="inpuEntity"></param>
        /// <returns></returns>
        public bool DTOAdd(AdminInfoInputDTO inpuEntity)
        {
            //AutoMapper转换
            AdminInfo dataModel = Mapper.Map <AdminInfoInputDTO, AdminInfo>(inpuEntity);

            dataModel.PassWord = MD5Helper.EncryptString("123");
            dataModel.DelFlag  = 0;
            //打上添加标记
            adminInfoDAL.AddFlag(dataModel);
            //添加默认数据 员工
            R_UserInfo_RoleInfo model = new R_UserInfo_RoleInfo
            {
                AdminID = dataModel.AdminID,
                RoleID  = "3",
            };

            r_UserInfo_RoleInfoDAL.AddFlag(model);
            if (unitOfWork.SaveChanges() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: UserInfoController.cs プロジェクト: Cloudyang/WebOA
        public ActionResult Edit(UserInfo userInfo)
        {
            string result = "no";

            //装配其它值
            userInfo.SubBy    = 1;
            userInfo.SubTime  = DateTime.Now;
            userInfo.IsDelete = false;
            if (userInfo.Remark == null)
            {
                userInfo.Remark = "";
            }
            //判断密码是否修改
            if (userInfo.UserPwd.Trim() != "")
            {
                userInfo.UserPwd = MD5Helper.EncryptString(userInfo.UserPwd);
            }
            else
            {
                userInfo.UserPwd = Request["pwd2"];
            }

            if (UserInfoService.Edit(userInfo))
            {
                result = "ok";
            }

            return(Content(result));
        }
コード例 #3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            int      id  = Convert.ToInt32(txtEId.Text);
            string   pwd = MD5Helper.EncryptString(txtPwd.Text);
            Employee emp = new Employee()
            {
                EmployeeId  = id,
                EmployeePwd = pwd
            };

            EmployeeBLL eiBLL = new EmployeeBLL();

            if (eiBLL.EmployeeLogin(emp))
            {
                MainForm mainfrm = new MainForm();

                //using Tag in MainForm to transit the Position information of the login employee
                //0 for manager, 1 for employee
                if (emp.EmployeePosition == "Manager")
                {
                    mainfrm.Tag = 0;
                }
                else
                {
                    mainfrm.Tag = 1;
                }

                mainfrm.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Login in failed, check your input", "Login Fail");
            }
        }
コード例 #4
0
ファイル: UserInfoService.cs プロジェクト: hanlei520/ZDNL
        /// <summary>
        /// DTO添加数据
        /// </summary>
        /// <param name="inputEntity"></param>
        /// <returns></returns>
        public bool DTOAdd(UserInfoInputDTO inputEntity)
        {
            UserInfo dataModel = Mapper.Map <UserInfoInputDTO, UserInfo>(inputEntity);

            dataModel.PassWord = MD5Helper.EncryptString("123");
            //先查房屋信息把状态修改为已售并把业主加上去
            HouseInfo model = houseInfoDAL.LoadEntities(u => u.HousID == dataModel.HousID).FirstOrDefault();

            model.State  = false;
            model.UserID = dataModel.UserID;


            //房屋打上修改标记
            houseInfoDAL.EditFlag(model);
            //业主打上添加标记
            userInfoDAL.AddFlag(dataModel);

            if (unitOfWork.SaveChanges() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
        private void btnAddorSave_Click(object sender, EventArgs e)
        {
            bool isSuccess = false;

            Employee emp = new Employee()
            {
                EmployeeName     = txtName.Text.Trim(),
                EmployeePosition = rbManager.Checked ? "Manager" : "Employee",
            };

            if (btnAddorSave.Text.Trim().Equals("Add"))
            {
                if (!(txtName.Text == string.Empty || txtPwd.Text == string.Empty))
                {
                    //Add new employee
                    emp.EmployeePwd = MD5Helper.EncryptString(txtPwd.Text.Trim());

                    if (eiBLL.AddNewEmployeeInfo(emp) != 0)
                    {
                        MessageBox.Show($"Changes made to Employee Table\nOperation: Add New Employee\nSuccess!", "Result");
                        isSuccess = true;
                    }
                }
            }
            else
            {
                //Update an existed employee infomation
                emp.EmployeeId = Convert.ToInt32(txtId.Text);

                //Check the comments in dgvEmployeeList_CellDoubleClick() for details
                if (txtPwd.Text.Equals("!L9%o^3*)G#"))
                {
                    //user do not change the password
                    emp.EmployeePwd = string.Empty;
                }
                else
                {
                    //user change the password
                    emp.EmployeePwd = MD5Helper.EncryptString(txtPwd.Text.Trim());
                }

                int id = eiBLL.UpdateEmployeeInfo(emp);//id for the employee whose infomation has successful update
                if (id != 0)
                {
                    MessageBox.Show($"Changes made to EmployeeInfo Table\nOperation: Update Employee Info with ID:{id}\nSuccess!", "Result");
                    isSuccess = true;
                }
            }

            if (isSuccess)
            {
                //if operation success, reset all TextBox and Button
                ResetTxtBtn();
                RefreshDataGrindViewData();
            }
            else
            {
                MessageBox.Show("Failed!! Check your input and try again", "Result");
            }
        }
コード例 #6
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="pwd">密码</param>
        /// <param name="type">用户类型</param>
        /// <returns></returns>
        public LoginState Login(string name, string pwd, out int type)
        {
            type = -1;
            //根据用户名进行对象的查询
            ManagerInfo mi = miDal.GetByName(name);

            if (mi == null)
            {
                return(LoginState.NameError);
            }
            else
            {
                //用户名正确
                if (mi.MPwd.Equals(MD5Helper.EncryptString(pwd)))
                {
                    //密码正确
                    //登录成功
                    type = mi.MType;
                    return(LoginState.Ok);
                }
                else
                {
                    //密码错误
                    return(LoginState.PwdError);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="inputEntity"></param>
        /// <returns></returns>
        public AdminInfo Login(AdminInfo inputEntity)
        {
            //先给密码进行MD5加密
            string pwd = MD5Helper.EncryptString(inputEntity.PassWord);
            //
            AdminInfo model = adminInfoDAL.LoadEntities(u => u.AdminID == inputEntity.AdminID && u.PassWord == pwd && u.DelFlag != 1).FirstOrDefault();

            return(model);
        }
コード例 #8
0
ファイル: UserInfoService.cs プロジェクト: hanlei520/ZDNL
        /// <summary>
        /// 业主登录
        /// </summary>
        /// <param name="inputEntity"></param>
        /// <returns></returns>
        public UserInfo UserLogin(UserInfo inputEntity)
        {
            //先给密码进行MD5加密
            string pwd = MD5Helper.EncryptString(inputEntity.PassWord);
            //
            UserInfo model = userInfoDAL.LoadEntities(u => u.UserID == inputEntity.UserID && u.PassWord == pwd).FirstOrDefault();

            return(model);
        }
コード例 #9
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="pwd">密码</param>
        /// <param name="type">用户类型</param>
        /// <returns></returns>
        public LoginState Login(string name, string pwd, out int type)
        {
            type = -1;
            //type = -1      没有
            //type = 0       员工
            //type = 1       老板
            //type = 2       顾客
            //根据用户名进行对象的查询
            ManagerInfo mi     = miDal.GetByName(name);
            MemberInfo  member = memberDal.GetByName(name);

            if (mi != null)
            {
                //用户名正确
                if (MD5Helper.EncryptString(mi.MPwd).Equals(MD5Helper.EncryptString(pwd)))
                {
                    //密码正确
                    //登录成功
                    type = mi.MType;
                    //保存用户session
                    GlobalVariable.userId   = Convert.ToString(mi.Id);
                    GlobalVariable.userName = mi.MName;
                    GlobalVariable.pwd      = mi.MPwd;
                    return(LoginState.Ok);
                }
                else
                {
                    //密码错误
                    return(LoginState.PwdError);
                }
            }
            else if (member != null)
            {
                //用户名正确
                if (MD5Helper.EncryptString(member.MPwd).Equals(MD5Helper.EncryptString(pwd)))
                {
                    //密码正确
                    //登录成功
                    type = 2;         //顾客
                    //保存用户session
                    GlobalVariable.userId   = Convert.ToString(member.Id);
                    GlobalVariable.userName = member.MName;
                    GlobalVariable.pwd      = member.MPwd;
                    GlobalVariable.phone    = member.MPhone;
                    return(LoginState.Ok);
                }
                else
                {
                    //密码错误
                    return(LoginState.PwdError);
                }
            }
            return(LoginState.NameError);
        }
コード例 #10
0
ファイル: AccountService.cs プロジェクト: 24808/superMiCore
        public UserOutput Login(string userId, string pwd)
        {
            _logger.LogWarning("开始登陆!");
            string MD5Pwd = MD5Helper.EncryptString(pwd);

            return((from a in _dbContext.Set <UserInfo>().Where(u => u.UserID == userId && u.PassWord == MD5Pwd && u.IsDelect == false)
                    select new UserOutput
            {
                UserId = a.UserID,
                UserName = a.UserName,
            }).FirstOrDefault());
        }
コード例 #11
0
        public int Insert(ManagerInfo manager)
        {
            string sql = "insert into ManagerInfo(mname,mpwd,mtype) values(@name,@pwd,@type)";

            SQLiteParameter[] ps =
            {
                new SQLiteParameter("@name", manager.MName),
                new SQLiteParameter("@pwd",  MD5Helper.EncryptString(manager.MPwd)),
                new SQLiteParameter("@type", manager.MType),
            };
            return(SqliteHelper.ExecuteNonQuery(sql, ps));
        }
コード例 #12
0
        /// <summary>
        /// 向数据库中插入管理者数据
        /// </summary>
        /// <param name="mi">管理者数据对象</param>
        /// <returns>受影响行数</returns>
        public int Insert(ManagerInfo mi)
        {
            string sql = "insert into ManagerInfo(mname,mpwd,mtype) values (@mname,@mpwd,@mtype)"; //语句

            SQLiteParameter[] ps =                                                                 //参数
            {
                new SQLiteParameter("@mname", mi.MName),
                new SQLiteParameter("@mpwd",  MD5Helper.EncryptString(mi.MPwd)),
                new SQLiteParameter("@mtype", mi.MType)
            };
            return(SQLiteHelper.ExecuteNonQuery(sql, ps));       //返回操作行数
        }
コード例 #13
0
        public JsonResult Add(T_Sys_Users one)
        {
            one.UserId      = Guid.NewGuid();
            one.PassWord    = MD5Helper.EncryptString(one.PassWord);
            one.CreateDate  = DateTime.Now;
            one.IsStatus    = 0;
            one.Sex         = 1;
            one.ExamineStep = 2;
            bool      add = _bll.Insert(one);
            CRUDModel cm  = CRUDModelHelper.GetRes(CRUD.ADD, add);

            return(Json(cm, JsonRequestBehavior.AllowGet));
        }
コード例 #14
0
        /// <summary>
        /// 重置密码。可批量
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool RecoverPassword(IEnumerable <int> Id, out string message)
        {
            IQueryable <UserInfo> userInfos = _dbContext.Set <UserInfo>();
            UserInfo user;

            foreach (var item in Id)
            {
                user          = userInfos.Where(u => u.Id == item).FirstOrDefault();
                user.Password = MD5Helper.EncryptString("123");
            }
            message = "密码重置成功!初始密码:123";
            return(_dbContext.SaveChanges() > 0);
        }
コード例 #15
0
ファイル: UserInfoService.cs プロジェクト: hanlei520/ZDNL
        /// <summary>
        /// 查询当前密码是否正确
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool CheckPwd(string value)
        {
            string   pwd   = MD5Helper.EncryptString(value);
            UserInfo model = userInfoDAL.LoadEntities(u => u.PassWord == pwd).FirstOrDefault();

            if (model != null)
            {
                return(true);//密码正确
            }
            else
            {
                return(false);
            }
        }
コード例 #16
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string res = "登录失败";

            try
            {
                string vCode = context.Request.Form["vCode"];
                if (context.Session["vCode"] == null || context.Session["vCode"].ToString() != vCode)
                {
                    context.Response.Write("验证码错误");
                    return;
                }
                if (context.Session["vCode"].ToString().Equals(vCode, StringComparison.InvariantCultureIgnoreCase))
                {
                    string userName = context.Request.Form["UserName"];
                    string pwd      = context.Request.Form["UserPwd"];
                    pwd = MD5Helper.EncryptString(pwd).Substring(0, 20);
                    DataTable user = CommonDB.invokeProc_DataTable("select * from t_users where userName='******' and pwd='" + pwd + "'");
                    if (user != null && user.Rows.Count == 1)
                    {
                        res = "OK";
                        UserModel userInfo = new UserModel();
                        userInfo.UserPower = Convert.ToInt32(user.Rows[0]["userpower"]);
                        userInfo.UserName  = user.Rows[0]["username"].ToString();
                        userInfo.UserPwd   = user.Rows[0]["pwd"].ToString();

                        DataTable hOnline = (DataTable)context.Application["Online"];

                        context.Session.Add("userInfo", userInfo);
                        HttpCookie hcUserName  = new HttpCookie("userName", userInfo.UserName);
                        HttpCookie hcUserPower = new HttpCookie("userPower", userInfo.UserPower.ToString());
                        hcUserName.Expires  = DateTime.Now.AddDays(7);
                        hcUserPower.Expires = DateTime.Now.AddDays(7);
                        context.Response.Cookies.Add(hcUserPower);
                        context.Response.Cookies.Add(hcUserName);
                    }
                    else
                    {
                        res = "用户名或密码错误";
                    }
                }
            }
            finally
            {
                context.Response.Write(res);
                context.Response.End();
            }
        }
コード例 #17
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="mi">ManagerInfo类型的对象</param>
        /// <returns></returns>
        public int Insert(ManagerInfo mi)
        {
            //构造insert语句
            string sql = "insert into ManagerInfo(mname,mpwd,mtype) values(@name,@pwd,@type)";

            //构造sql语句的参数
            SqlParameter[] ps = //使用数组初始化器
            {
                new SqlParameter("@name", mi.MName),
                new SqlParameter("@pwd",  MD5Helper.EncryptString(mi.MPwd)),//将密码进行md5加密
                new SqlParameter("@type", mi.MType)
            };
            //执行插入操作
            return(SQLHelper.ExecuteNonQuery(sql, ps));
        }
コード例 #18
0
        /// <summary>
        /// 读取数据库用户表数据,判断用户密码是否匹配
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        internal T_Sys_Users ValidateUserLogin(string name, string password)
        {
            string encpawd = MD5Helper.EncryptString(password);
            IList <T_Sys_Users> sysUsers = SysDataHelper <T_Sys_Users> .GetData(m => m.UserName == name && m.PassWord == encpawd).ToList();

            if (sysUsers.ToList().Count > 0)
            {
                T_Sys_Users sysUser = sysUsers.ToList().FirstOrDefault();
                HttpContext.Current.Session["userinfo"] = JsonConvert.SerializeObject(sysUser);
                return(sysUser);
            }
            else
            {
                return(null);
            }
        }
コード例 #19
0
        /// <summary>
        /// 更新数据库的管理者数据
        /// </summary>
        /// <param name="mi">要修改的管理者对象</param>
        /// <returns>影响的行数</returns>
        public int Update(ManagerInfo mi)
        {
            List <SQLiteParameter> listPs = new List <SQLiteParameter>();                  //可变参数集合

            listPs.Add(new SQLiteParameter("@name", mi.MName));                            //用户名参数
            string sql = "update ManagerInfo set mname=@name";                             //部分语句

            if (!mi.MPwd.Equals("不会是这个密码吧?"))                                              //判断是否修改过密码
            {
                sql += ",mpwd = @pwd";                                                     //拼接密码部分
                listPs.Add(new SQLiteParameter("@pwd", MD5Helper.EncryptString(mi.MPwd))); //密码参数添加
            }
            sql += ",mtype=@type where mid=@id";                                           //添加尾部
            listPs.Add(new SQLiteParameter("@type", mi.MType));
            listPs.Add(new SQLiteParameter("@id", mi.MId));
            return(SQLiteHelper.ExecuteNonQuery(sql, listPs.ToArray())); //执行
        }
コード例 #20
0
        public int Update(ManagerInfo manager)
        {
            List <SQLiteParameter> list = new List <SQLiteParameter>();
            string sql = "update managerInfo set mname=@name";

            list.Add(new SQLiteParameter("@name", manager.MName));
            if (!(manager.MPwd == "thisold"))
            {
                sql += ",mpwd=@pwd";
                list.Add(new SQLiteParameter("@pwd", MD5Helper.EncryptString(manager.MPwd)));
            }
            sql += ",mtype=@type where mid=@id";
            list.Add(new SQLiteParameter("@type", manager.MType));
            list.Add(new SQLiteParameter("@id", manager.MId));

            return(SqliteHelper.ExecuteNonQuery(sql, list.ToArray()));
        }
コード例 #21
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userInput">输入的数据</param>
        /// <param name="message">回抛的信息</param>
        /// <returns></returns>
        public bool AddUser(UserInput userInput, out string message)
        {
            IQueryable <UserInfo> users = _dbContext.Set <UserInfo>();
            UserInfo user = users.Where(u => u.UserId == userInput.UserId).FirstOrDefault();

            if (user == null)
            {
                try
                {
                    UserInfo newUser = new UserInfo
                    {
                        UserId       = userInput.UserId,
                        UserName     = userInput.UserName,
                        DepartmentId = userInput.DepartmentId,
                        Email        = userInput.Email,
                        Gender       = userInput.Gender,
                        DelFlag      = false,
                        Tel          = userInput.Tel,
                        Password     = MD5Helper.EncryptString("123"),
                        UserTypeId   = (int)TypeEnum.UserType.isGeneralUser,
                        AddTime      = DateTime.Now
                    };
                    _dbContext.Set <UserInfo>().Add(newUser);
                    if (_dbContext.SaveChanges() > 0)
                    {
                        message = "添加成功!";
                        return(true);
                    }
                    else
                    {
                        message = "添加失败!内部出现异常!";
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }
            }
            message = "该用户已存在!请检查UserID!";
            return(false);
        }
コード例 #22
0
        /// <summary>
        /// 修改管理员
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        public int Update(ManagerInfo mi)
        {
            List <SqlParameter> listPs = new List <SqlParameter>();
            //构造update的sql语句
            string sql = "update ManagerInfo set mname=@name";

            listPs.Add(new SqlParameter("@name", mi.MName));
            //判断是否修改密码
            if (!mi.MPwd.Equals("这是原来的密码吗"))
            {
                sql += ",mpwd=@pwd";
                listPs.Add(new SqlParameter("@pwd", MD5Helper.EncryptString(mi.MPwd)));
            }
            sql += ",mtype=@type where Id=@id";
            listPs.Add(new SqlParameter("@type", mi.MType));
            listPs.Add(new SqlParameter("@id", mi.Id));

            //执行语句并返回结果
            return(SQLHelper.ExecuteNonQuery(sql, listPs.ToArray()));
        }
コード例 #23
0
        /// <summary>
        /// 登录判断
        /// </summary>
        /// <param name="name">要检验的用户名</param>
        /// <param name="pwd">要检验的密码</param>
        /// <param name="type">登录类型标记</param>
        /// <returns>登录状态</returns>
        public LoginStatus Login(string name, string pwd, out int type)
        {
            ManagerInfo mi = miDal.GetListByName(name); //数据访问层返回的对象

            if (mi == null)                             //返回为空说明没有这个用户
            {
                type = 0;
                return(LoginStatus.UserNameError);
            }
            else
            {
                type = mi.MType;
                if (mi.MPwd.Equals(MD5Helper.EncryptString(pwd)))   //密码吻合
                {
                    return(LoginStatus.OK);
                }
                else
                {
                    return(LoginStatus.PwdError);
                }
            }
        }
コード例 #24
0
ファイル: UserInfoService.cs プロジェクト: hanlei520/ZDNL
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="model"></param>
        /// <param name="UserID"></param>
        /// <param name="NewPwd"></param>
        /// <param name="Pwd"></param>
        /// <returns></returns>
        public bool ResetPwd(string PassWord, string UserID, string NewPwd, string Pwd)
        {
            //先查
            UserInfo entity = userInfoDAL.LoadEntities(u => u.UserID == UserID).FirstOrDefault();

            if (entity != null)
            {
                if (PassWord != null)
                {
                    string strPassWord = MD5Helper.EncryptString(PassWord);
                    if (entity.PassWord != strPassWord)
                    {
                        return(false);
                    }
                    if (NewPwd != Pwd)
                    {
                        return(false);
                    }
                    Pwd             = MD5Helper.EncryptString(Pwd);
                    entity.PassWord = Pwd;
                    if (userInfoDAL.EditAndSaveChange(entity) > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #25
0
ファイル: UserInfoService.cs プロジェクト: hanlei520/ZDNL
        /// <summary>
        /// 根据ID重置密码
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool RePwd(Array id)
        {
            foreach (var item in id)
            {
                int      ID     = Convert.ToInt32(item);
                UserInfo entity = userInfoDAL.LoadEntities(u => u.ID == ID).FirstOrDefault();

                if (entity != null)
                {
                    //修改密码,为默认值,并MD5加密
                    entity.PassWord = MD5Helper.EncryptString("123");
                    userInfoDAL.EditFlag(entity);
                }
            }
            if (unitOfWork.SaveChanges() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #26
0
ファイル: UserInfoController.cs プロジェクト: Cloudyang/WebOA
        public ActionResult Add(UserInfo userInfo)
        {
            string result = "no";

            //完成属性值的初始化
            userInfo.IsDelete = false;
            userInfo.SubBy    = 1;
            userInfo.SubTime  = DateTime.Now;
            if (userInfo.Remark == null)
            {
                userInfo.Remark = "";
            }

            //对密码进行md5加密
            userInfo.UserPwd = MD5Helper.EncryptString(userInfo.UserPwd);

            //调用Service完成添加
            if (UserInfoService.Add(userInfo))
            {
                result = "ok";
            }
            return(Content(result));
        }
コード例 #27
0
        public bool MutipleImport(IEnumerable <UserInput> userInfos, out string msg)
        {
            IQueryable <UserInfo> users = _dbContext.Set <UserInfo>();

            //遍历
            foreach (var item in userInfos)
            {
                UserInfo userInfo = users.Where(u => u.UserId == item.UserId).FirstOrDefault();
                if (userInfo == null)
                {
                    UserInfo user = new UserInfo
                    {
                        UserId     = item.UserId,
                        UserName   = item.UserName,
                        UserTypeId = (int?)TypeEnum.UserType.isGeneralUser,
                        Password   = MD5Helper.EncryptString("123"),
                        Gender     = item.Gender,
                        Email      = item.Email,
                        Tel        = item.Tel,
                        AddTime    = DateTime.Now,
                        DelFlag    = false
                    };
                    _dbContext.Set <UserInfo>().Add(user);
                }
                else
                {
                    continue;
                }
            }
            if (_dbContext.SaveChanges() > 0)
            {
                msg = "导入成功!";
                return(true);
            }
            msg = "失败!内部错误!";
            return(false);
        }
コード例 #28
0
ファイル: ManagerBll.cs プロジェクト: KUN-NT/NetProjectCode
        public ManagerStute Login(string name, string pwd, out int type)
        {
            type = 0;
            ManagerStute stute = new ManagerStute();
            ManagerInfo  mi    = dal.Login(name);

            if (mi != null)
            {
                if (mi.MPwd.Equals(MD5Helper.EncryptString(pwd)))
                {
                    stute = ManagerStute.OK;
                    type  = mi.MType;
                }
                else
                {
                    stute = ManagerStute.PWDERROR;
                }
            }
            else
            {
                stute = ManagerStute.NAMEERROR;
            }
            return(stute);
        }
コード例 #29
0
        public LoginOutput Login(LoginInput loginInput)
        {
            IQueryable <UserInfo>       infos       = _dbContext.Set <UserInfo>();
            IQueryable <UserType>       types       = _dbContext.Set <UserType>();
            IQueryable <DepartmentInfo> departments = _dbContext.Set <DepartmentInfo>();
            IQueryable <RoleInfo>       roleInfos   = _dbContext.Set <RoleInfo>();
            IQueryable <RUserRoleInfo>  userRoles   = _dbContext.Set <RUserRoleInfo>();
            string   password = MD5Helper.EncryptString(loginInput.Password);
            UserInfo user     = infos.Where(u => u.UserId == loginInput.UserId && u.Password == password && u.DelFlag == false).FirstOrDefault();

            if (user != null)
            {
                IEnumerable <string> roleName = (from a in userRoles
                                                 join b in roleInfos on a.RoleId equals b.RoleId into join_a
                                                 from c in join_a.DefaultIfEmpty()
                                                 where a.UserId == user.UserId
                                                 select new
                {
                    c.RoleName
                }).Select(s => s.RoleName).ToList();
                IEnumerable <string> roleId = (from a in userRoles
                                               join b in roleInfos on a.RoleId equals b.RoleId into join_a
                                               from c in join_a.DefaultIfEmpty()
                                               where a.UserId == user.UserId
                                               select new
                {
                    c.RoleId
                }).Select(s => s.RoleId).ToList();
                string userType       = types.Where(t => t.Id == user.UserTypeId).Select(s => s.TypeName).FirstOrDefault();
                string departmentName = departments.Where(d => d.DepartmentId == user.DepartmentId).Select(s => s.DepartmentName).FirstOrDefault();
                //if (string.IsNullOrEmpty(departmentName))
                //{
                //    departmentName = "";
                //}
                LoginOutput outputs = new LoginOutput
                {
                    Id             = user.Id,
                    UserTypeName   = userType,
                    DepartmentId   = user.DepartmentId,
                    DepartmentName = departmentName,
                    Email          = user.Email,
                    Tel            = user.Tel,
                    AddTime        = user.AddTime,
                    DelFlag        = user.DelFlag,
                    EnterpriseName = user.EnterpriseName,
                    Gender         = user.Gender,
                    Token          = user.Token,
                    UserId         = user.UserId,
                    UserName       = user.UserName,
                    RoleName       = roleName,
                    RoleId         = roleId
                };
                LoginLogInfo loginSuccessLog = new LoginLogInfo
                {
                    UserId         = loginInput.UserId,
                    Ip             = loginInput.IP,
                    BrowserInfo    = loginInput.BrowerInfo,
                    SystemInfo     = loginInput.OSVersion,
                    IsLoginSuccess = true,
                    HappenTime     = DateTime.Now
                };
                _dbContext.Set <LoginLogInfo>().Add(loginSuccessLog);
                if (_dbContext.SaveChanges() > 0)
                {
                    return(outputs);
                }
                return(null);
            }
            LoginLogInfo loginFaildLog = new LoginLogInfo
            {
                UserId         = loginInput.UserId,
                Ip             = loginInput.IP,
                BrowserInfo    = loginInput.BrowerInfo,
                SystemInfo     = loginInput.OSVersion,
                IsLoginSuccess = false,
                HappenTime     = DateTime.Now
            };

            _dbContext.Set <LoginLogInfo>().Add(loginFaildLog);
            _dbContext.SaveChanges();
            return(null);
        }