Esempio n. 1
0
        private void menu_InitPassword_Click(object sender, EventArgs e)
        {
            if (!HasFunction("User/Set/UserInitPwd"))
            {
                MessageDxUtil.ShowError(Const.NoAuthMsg);
                return;
            }

            if (MessageDxUtil.ShowYesNoAndTips(string.Format("您确定重置选定记录的用户密码么? \r\n重置后密码将设置为【{0}】", Const.defaultPwd)) == DialogResult.No)
            {
                return;
            }

            int[] rowSelected = this.winGridViewPager1.GridView1.GetSelectedRows();
            foreach (int iRow in rowSelected)
            {
                string ip           = NetworkUtil.GetLocalIP();
                string macAddr      = HardwareInfoHelper.GetMacAddress();
                Int32  changeUserId = this.winGridViewPager1.GridView1.GetRowCellDisplayText(iRow, "Id").ToInt32();

                bool success = BLLFactory <User> .Instance.ResetPassword(Portal.gc.UserInfo.Id, changeUserId, Portal.gc.SYSTEMTYPEID, ip, macAddr);

                MessageDxUtil.ShowTips(success ? "重置密码操作成功" : "操作失败");
            }
        }
Esempio n. 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            #region 输入验证
            if (this.txtRePassword.Text != this.txtPassword.Text)
            {
                MessageDxUtil.ShowTips("两个新密码的输入不一致");
                this.txtRePassword.Focus();
                return;
            }
            #endregion

            try
            {
                string ip      = NetworkUtil.GetLocalIP();
                string macAddr = HardwareInfoHelper.GetMacAddress();
                bool   result  = BLLFactory <User> .Instance.ModifyPassword(this.LoginUserInfo.Name, this.txtPassword.Text, Portal.gc.SystemType, ip, macAddr);

                if (result)
                {
                    this.DialogResult = DialogResult.OK;
                    MessageDxUtil.ShowTips("密码修改成功");
                }
                else
                {
                    MessageDxUtil.ShowWarning("用户密码资料不正确,请核对");
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmModifyPassword));
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Esempio n. 3
0
        private void btnComputer_Click(object sender, EventArgs e)
        {
            string computerName = HardwareInfoHelper.GetComputerName();
            string userName     = HardwareInfoHelper.GetUserName();
            string systemType   = HardwareInfoHelper.GetSystemType();
            string cpuid        = HardwareInfoHelper.GetCPUId();
            string cpuName      = HardwareInfoHelper.GetCPUName();
            int    cpuUsage     = HardwareInfoHelper.GetCpuUsage();
            string diskId       = HardwareInfoHelper.GetDiskID();
            string ip           = HardwareInfoHelper.GetIPAddress();
            string macAddress   = HardwareInfoHelper.GetMacAddress();
            string memery       = HardwareInfoHelper.GetTotalPhysicalMemory();

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("ComputerName:\t {0} \r\n", computerName);
            sb.AppendFormat("UserName:\t {0} \r\n", userName);
            sb.AppendFormat("SystemType:\t {0} \r\n", systemType);
            sb.AppendFormat("CPU ID:\t {0} \r\n", cpuid);
            sb.AppendFormat("CPU Name:\t {0} \r\n", cpuName);
            sb.AppendFormat("CPU Usage:\t {0} \r\n", cpuUsage);
            sb.AppendFormat("Disk Id:\t {0} \r\n", diskId);
            sb.AppendFormat("IP:\t {0} \r\n", ip);
            sb.AppendFormat("MacAddress:\t {0} \r\n", macAddress);
            sb.AppendFormat("TotalPhysicalMemory:\t {0} \r\n", memery);
            MessageDxUtil.ShowTips(sb.ToString());

            string identity = FingerprintHelper.Value();

            MessageDxUtil.ShowTips(identity);
        }
Esempio n. 4
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (this.cmbzhanhao.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.cmbzhanhao.Focus();
                return;
            }
            #endregion

            try
            {
                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.cmbzhanhao.Text.Trim();
                string identity  = BLLFactory <WHC.Security.BLL.User> .Instance.VerifyUser(loginName, this.tbPass.Text, "WareMis", ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <WHC.Security.BLL.User> .Instance.GetUserByName(loginName);

                    #region 获取用户的功能列表

                    List <FunctionInfo> list = BLLFactory <WHC.Security.BLL.Function> .Instance.GetFunctionsByUser(info.ID, "WareMis");

                    if (list != null && list.Count > 0)
                    {
                        foreach (FunctionInfo functionInfo in list)
                        {
                            if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                            {
                                Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo);
                            }
                        }
                    }

                    #endregion

                    //登录成功
                    bLogin = true;
                    Portal.gc.LoginInfo = info;
                    this.DialogResult   = DialogResult.OK;
                }
                else
                {
                    MessageDxUtil.ShowTips("用户帐号密码不正确");
                    this.tbPass.Text = ""; //设置密码为空
                }
            }
            catch (Exception err)
            {
                MessageDxUtil.ShowError(err.Message);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 重置用户密码为12345678
        /// </summary>
        /// <param name="id">用户ID</param>
        /// <returns></returns>
        public ActionResult ResetPassword(string id)
        {
            CommonResult result = new CommonResult();

            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    result.ErrorMessage = "用户id不能为空";
                }
                else
                {
                    UserInfo info = BLLFactory <User> .Instance.FindByID(id);

                    if (info != null)
                    {
                        string defaultPassword = Const.defaultPwd;
                        string ip       = NetworkUtil.GetLocalIP();
                        string macAddr  = HardwareInfoHelper.GetMacAddress();
                        bool   tempBool = BLLFactory <User> .Instance.ModifyPassword(info.Name, defaultPassword, Const.SystemTypeID, ip, macAddr);

                        if (tempBool)
                        {
                            result.Success = true;
                        }
                        else
                        {
                            result.ErrorMessage = "口令初始化失败";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(UserController));
                result.ErrorMessage = ex.Message;
            }
            return(ToJsonContent(result));
        }
Esempio n. 6
0
        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="name">用户名称</param>
        /// <param name="oldpass">旧密码</param>
        /// <param name="newpass">修改密码</param>
        /// <returns></returns>
        public ActionResult ModifyPass(string name, string oldpass, string newpass)
        {
            CommonResult result = new CommonResult();

            try
            {
                // TODO 这里要修改为Request IP
                string ip       = NetworkUtil.GetLocalIP();
                string macAddr  = HardwareInfoHelper.GetMacAddress();
                string identity = BLLFactory <User> .Instance.VerifyUser(name, oldpass, Const.SystemTypeID, ip, macAddr);

                if (string.IsNullOrEmpty(identity))
                {
                    result.ErrorMessage = "原口令错误";
                }
                else
                {
                    bool tempBool = BLLFactory <User> .Instance.ModifyPassword(name, newpass, Const.SystemTypeID, ip, macAddr);

                    if (tempBool)
                    {
                        result.Success = true;
                    }
                    else
                    {
                        result.ErrorMessage = "口令修改失败";
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(UserController));
                result.ErrorMessage = ex.Message;
            }
            return(ToJsonContent(result));
        }
Esempio n. 7
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (this.txtUserName.Text.Length == 0)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "请输入帐号", typeof(Login));
                MessageDxUtil.ShowError("请输入帐号");
                this.txtUserName.Focus();
                return;
            }

            if (this.txtPassword.Text.Length == 0)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "请输入密码", typeof(Login));
                MessageDxUtil.ShowError("请输入密码");
                this.txtPassword.Focus();
                return;
            }
            #endregion

            try
            {
                string loginName = this.txtUserName.Text.Trim();
                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string identity  = BLLFactory <User> .Instance.VerifyUser(loginName, this.txtPassword.Text, Portal.gc.SYSTEMTYPEID, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <User> .Instance.GetUserByName(loginName);

                    // 20191207 wjm 新增判断超级管理员 系统配置参数为1
                    // 20171109 wjm 不应该直接去判断这个Name的值,不合理 删除其逻辑判断
                    if (info != null && BLLFactory <Sysparameter> .Instance.UserIsSuperAdmin(loginName))
                    {
                        Portal.gc.UserInfo     = info;
                        Portal.gc.IsSuperAdmin = true;
                        bLogin            = true;
                        this.DialogResult = DialogResult.OK;
                    }
                    else if (info != null && BLLFactory <Role> .Instance.UserHasRole(info.Id))
                    {
                        Portal.gc.UserInfo     = info;
                        Portal.gc.IsSuperAdmin = false;
                        bLogin            = true;
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, string.Format("该用户({0})没有管理员权限", loginName), typeof(Login));
                        MessageDxUtil.ShowError(string.Format("该用户({0})没有管理员权限", loginName));
                        txtUserName.Focus();
                        return;
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "用户名或密码错误或被禁止登陆", typeof(Login));
                    MessageDxUtil.ShowError("用户名或密码错误或被禁止登陆");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(Login));
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 处理登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (this.txtUserName.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.txtUserName.Focus();
                return;
            }
            #endregion

            try
            {
                this.Cursor           = Cursors.WaitCursor;
                this.btnLogin.Enabled = false;
                this.btnExit.Enabled  = false;
                //保存用户登录参数
                SaveParameter();

                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.txtUserName.Text.Trim();
                string identity  = await CallerFactory <IUserService> .Instance.VerifyUser2Asyn(loginName, this.txtPassword.Text, Portal.gc.SystemType, ip, macAddr).TimeOut <string>(Portal.gc.AsynTimeOut);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = await CallerFactory <IUserService> .Instance.GetUserByNameAsyn(loginName).TimeOut <UserInfo>(Portal.gc.AsynTimeOut);

                    if (info != null)
                    {
                        #region 获取用户的功能列表
                        Portal.gc.FunctionDict.Clear();

                        List <FunctionInfo> list = await CallerFactory <IFunctionService> .Instance.GetFunctionsByUserAsyn(info.ID, Portal.gc.SystemType).TimeOut <List <FunctionInfo> >(Portal.gc.AsynTimeOut);

                        if (list != null && list.Count > 0)
                        {
                            foreach (FunctionInfo functionInfo in list)
                            {
                                if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                                {
                                    Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo.ControlID);
                                }
                            }
                        }


                        #endregion

                        #region 权限判断

                        //判断是否为超级管理员
                        Portal.gc.IsAdmin = await CallerFactory <IUserService> .Instance.UserIsAdminAsyn(info.Name).TimeOut <bool>(Portal.gc.AsynTimeOut);

                        //判断如果用户管理的公司数据多于一个,那么就显示选择单位列表,并绑定公司数据
                        Portal.gc.CompanyList = await CallerFactory <IRoleDataService> .Instance.GetBelongCompanysByUserAsyn(info.ID).TimeOut <List <string> >(Portal.gc.AsynTimeOut);

                        List <string> deptList = await CallerFactory <IRoleDataService> .Instance.GetBelongDeptsByUserAsyn(info.ID).TimeOut <List <string> >(Portal.gc.AsynTimeOut);

                        Portal.gc.DeptList = deptList;

                        //设置选定的公司ID(默认为用户所在公司的ID)
                        Cache.Instance["SelectedCompanyID"] = info.Company_ID;
                        //设置过滤条件给界面基类使用
                        string filterCondition = string.Format(" Company_ID = '{0}' ", info.Company_ID);
                        if (!Portal.gc.IsAdmin)
                        {
                            if (deptList.Count > 0)
                            {
                                filterCondition += string.Format(" AND Dept_ID IN ('{0}')", deptList.CreateSQLInCondition());
                            }
                            else
                            {
                                filterCondition += string.Format(" AND Creator = '{0}' ", info.ID);
                            }
                        }
                        Cache.Instance["DataFilterCondition"] = filterCondition;

                        #endregion

                        bLogin                        = true;
                        Portal.gc.UserInfo            = info;
                        Portal.gc.LoginUserInfo       = Portal.gc.ConvertToLoginUser(info); //方便后续处理
                        Portal.gc.LoginUserInfo.Data1 = txtPassword.Text;                   //当前用户登录密码,方便其他子系统自动登录
                        Cache.Instance.Add("FunctionDict", Portal.gc.FunctionDict);         //缓存权限信息,方便后续使用
                        Cache.Instance.Add("LoginUserInfo", Portal.gc.LoginUserInfo);

                        this.DialogResult = DialogResult.OK;
                        RegistryHelper.SaveValue(Login_Name_Key, this.txtUserName.Text);
                    }
                }
                else
                {
                    MessageDxUtil.ShowTips("用户帐号密码不正确");
                    this.txtPassword.Text = ""; //设置密码为空
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.Error(ex);
                MessageDxUtil.ShowError(ex.Message);
            }
            finally
            {
                this.btnExit.Enabled  = true;
                this.btnLogin.Enabled = true;
                this.Cursor           = Cursors.Default;
            }
        }
Esempio n. 9
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (this.txtUserName.Text.Length == 0)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "请输入帐号", typeof(Login));
                MessageDxUtil.ShowError("请输入帐号");
                this.txtUserName.Focus();
                return;
            }

            if (this.txtPassword.Text.Length == 0)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "请输入密码", typeof(Login));
                MessageDxUtil.ShowError("请输入密码");
                this.txtPassword.Focus();
                return;
            }
            #endregion

            try
            {
                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.txtUserName.Text.Trim();

                string identity = BLLFactory <User> .Instance.VerifyUser(loginName, this.txtPassword.Text, Portal.gc.SystemType, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    // 20171109 wjm 不应该直接去判断这个Name的值,不合理 删除其逻辑判断
                    //if (BLLFactory<User>.Instance.UserIsAdmin(loginName))
                    //{
                    UserInfo info = BLLFactory <User> .Instance.GetUserByName(loginName);

                    Portal.gc.UserInfo = info;                                      //赋值给全局变量“管理用户”
                    bLogin             = true;
                    this.DialogResult  = DialogResult.OK;
                    //}
                    //else
                    //{
                    //    LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "该用户没有管理员权限", typeof(Login));
                    //    MessageDxUtil.ShowError("该用户没有管理员权限");
                    //    txtUserName.Focus();
                    //    return;
                    //}
                }
                else
                {
                    LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "用户名或密码错误或被禁止登陆", typeof(Login));
                    MessageDxUtil.ShowError("用户名或密码错误或被禁止登陆");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(Login));
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Esempio n. 10
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (Portal.gc.EnableRegister && !Portal.gc.Registed)
            {
                MessageUtil.ShowError("软件未进行授权注册,不能使用。\r\n请单击左边【软件注册】按钮进行注册。");
                return;
            }

            if (this.cmbzhanhao.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.cmbzhanhao.Focus();
                return;
            }
            #endregion

            try
            {
                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.cmbzhanhao.Text.Trim();
                string identity  = BLLFactory <WHC.Security.BLL.User> .Instance.VerifyUser(loginName, this.tbPass.Text, Portal.gc.SystemType, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <WHC.Security.BLL.User> .Instance.GetUserByName(loginName);

                    if (info != null)
                    {
                        #region 获取用户的功能列表

                        List <FunctionInfo> list = BLLFactory <WHC.Security.BLL.Function> .Instance.GetFunctionsByUser(info.ID, Portal.gc.SystemType);

                        if (list != null && list.Count > 0)
                        {
                            foreach (FunctionInfo functionInfo in list)
                            {
                                if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                                {
                                    Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo.ControlID);
                                }
                            }
                        }

                        #endregion

                        bLogin                  = true;
                        Portal.gc.UserInfo      = info;
                        Portal.gc.LoginUserInfo = Portal.gc.ConvertToLoginUser(info);
                        Cache.Instance.Add("LoginUserInfo", Portal.gc.LoginUserInfo); //缓存用户信息,方便后续处理
                        Cache.Instance.Add("FunctionDict", Portal.gc.FunctionDict);   //缓存权限信息,方便后续使用
                        Cache.Instance.Add("WeightModel", "自动");
                        this.DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    MessageDxUtil.ShowTips("用户帐号密码不正确");
                    this.tbPass.Text = ""; //设置密码为空
                }
            }
            catch (Exception err)
            {
                MessageDxUtil.ShowError(err.Message);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 使用参数化登录
        /// </summary>
        /// <param name="args"></param>
        private static void LoginByArgs(string[] args)
        {
            CommandArgs commandArgs = CommandLine.Parse(args);
            // 获取用户参数
            string loginName = commandArgs.ArgPairs["U"];
            string password  = commandArgs.ArgPairs.ContainsKey("P") ? commandArgs.ArgPairs["P"] : "";

            if (!string.IsNullOrEmpty(loginName))
            {
                string ip       = NetworkUtil.GetLocalIP();
                string macAddr  = HardwareInfoHelper.GetMacAddress();
                string identity = BLLFactory <WHC.Security.BLL.User> .Instance.VerifyUser(loginName, password, "WareMis", ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <WHC.Security.BLL.User> .Instance.GetUserByName(loginName);

                    #region 获取用户的功能列表

                    List <FunctionInfo> list = BLLFactory <WHC.Security.BLL.Function> .Instance.GetFunctionsByUser(info.ID, "WareMis");

                    if (list != null && list.Count > 0)
                    {
                        foreach (FunctionInfo functionInfo in list)
                        {
                            if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                            {
                                Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo.ControlID);
                            }
                        }
                    }

                    #endregion

                    Portal.gc.UserInfo      = info;
                    Portal.gc.LoginUserInfo = Portal.gc.ConvertToLoginUser(info);
                    Cache.Instance.Add("LoginUserInfo", Portal.gc.LoginUserInfo); //缓存用户信息,方便后续处理
                    Cache.Instance.Add("FunctionDict", Portal.gc.FunctionDict);   //缓存权限信息,方便后续使用

                    #region 获取用户管理的库房
                    Portal.gc.ManagedWareHouse = Portal.gc.GetWareHouse(info);
                    if (Portal.gc.ManagedWareHouse != null && Portal.gc.ManagedWareHouse.Count > 0)
                    {
                        SplashScreen.Splasher.Show(typeof(SplashScreen.frmSplash));

                        gc.MainDialog = new MainForm();
                        gc.MainDialog.StartPosition = FormStartPosition.CenterScreen;
                        Application.Run(gc.MainDialog);
                    }
                    else
                    {
                        MessageUtil.ShowTips("用户登录信息正确,但未授权管理库房信息,请联系组长授权管理");
                        LoginNormal(args);
                    }

                    #endregion
                }
                else
                {
                    MessageUtil.ShowTips("用户帐号密码不正确");
                    LoginNormal(args);
                }
            }
            else
            {
                MessageUtil.ShowTips("命令格式有误");
                LoginNormal(args);
            }
        }
Esempio n. 12
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (Portal.gc.EnableRegister && !Portal.gc.Registed)
            {
                MessageUtil.ShowError("软件未进行授权注册,不能用于商业用途。\r\n如需注册,请单击左边【软件注册】按钮进行注册。");
            }

            if (this.cmbzhanhao.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.cmbzhanhao.Focus();
                return;
            }
            #endregion

            try
            {
                //保存用户登录参数
                SaveParameter();

                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.cmbzhanhao.Text.Trim();
                string identity  = CallerFactory <IUserService> .Instance.VerifyUser2(loginName, this.tbPass.Text, Portal.gc.SystemType, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = CallerFactory <IUserService> .Instance.GetUserByName(loginName);

                    if (info != null)
                    {
                        #region 获取用户的功能列表

                        List <FunctionInfo> list = CallerFactory <IFunctionService> .Instance.GetFunctionsByUser(info.ID, Portal.gc.SystemType);

                        if (list != null && list.Count > 0)
                        {
                            foreach (FunctionInfo functionInfo in list)
                            {
                                if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                                {
                                    Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo.ControlID);
                                }
                            }
                        }

                        #endregion

                        #region 权限判断

                        //判断是否为超级管理员
                        Portal.gc.IsAdmin = CallerFactory <IUserService> .Instance.UserIsAdmin(info.Name);

                        //判断如果用户管理的公司数据多于一个,那么就显示选择单位列表,并绑定公司数据
                        Portal.gc.CompanyList = CallerFactory <IRoleDataService> .Instance.GetBelongCompanysByUser(info.ID);

                        List <int> deptList = CallerFactory <IRoleDataService> .Instance.GetBelongDeptsByUser(info.ID);

                        Portal.gc.DeptList = deptList;

                        //设置选定的公司ID(默认为用户所在公司的ID)
                        Cache.Instance["SelectedCompanyID"] = info.Company_ID;
                        //设置过滤条件给界面基类使用
                        string filterCondition = string.Format(" Company_ID = '{0}' ", info.Company_ID);
                        if (!Portal.gc.IsAdmin)
                        {
                            if (deptList.Count > 0)
                            {
                                filterCondition += string.Format(" AND Dept_ID IN ({0})", string.Join(",", deptList));
                            }
                            else
                            {
                                filterCondition += string.Format(" AND Creator = '{0}' ", info.ID);
                            }
                        }
                        Cache.Instance["DataFilterCondition"] = filterCondition;

                        #endregion

                        bLogin                  = true;
                        Portal.gc.UserInfo      = info;
                        Portal.gc.LoginUserInfo = Portal.gc.ConvertToLoginUser(info);
                        Cache.Instance.Add("LoginUserInfo", Portal.gc.LoginUserInfo); //缓存用户信息,方便后续处理
                        Cache.Instance.Add("FunctionDict", Portal.gc.FunctionDict);   //缓存权限信息,方便后续使用

                        this.DialogResult = DialogResult.OK;
                        RegistryHelper.SaveValue(Login_Name_Key, this.cmbzhanhao.Text);
                    }
                }
                else
                {
                    MessageDxUtil.ShowTips("用户帐号密码不正确");
                    this.tbPass.Text = ""; //设置密码为空
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.Error(ex);
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Esempio n. 13
0
        private void btnTestLogin_Click(object sender, EventArgs e)
        {
            if (this.txtLogin.Text.Trim() == "")
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.txtLogin.Focus();
                return;
            }

            try
            {
                //判断用户是否登录成功
                string loginName  = this.txtLogin.Text.Trim();
                string ip         = NetworkUtil.GetLocalIP();
                string macAddr    = HardwareInfoHelper.GetMacAddress();
                string systemType = "WareMis";
                string identity   = BLLFactory <User> .Instance.VerifyUser(loginName, this.txtPassword.Text, systemType, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <User> .Instance.GetUserByName(loginName);

                    if (info != null)
                    {
                        //获取该登陆用户的权限集合
                        List <FunctionInfo> list = BLLFactory <Functions> .Instance.GetFunctionsByUser(info.ID, systemType);

                        if (list != null && list.Count > 0)
                        {
                            foreach (FunctionInfo functionInfo in list)
                            {
                                if (!functionDict.ContainsKey(functionInfo.FunctionId))
                                {
                                    functionDict.Add(functionInfo.FunctionId, functionInfo);
                                }
                            }
                        }

                        //进一步判断用户角色
                        //if (BLLFactory<User>.Instance.UserIsAdmin(loginName))
                        //{
                        MessageDxUtil.ShowTips(string.Format("用户【{0}】身份验证正确", loginName));
                        //}
                        //else
                        //{
                        //    MessageDxUtil.ShowWarning("该用户没有管理员权限");
                        //    return;
                        //}
                    }
                }
                else
                {
                    MessageDxUtil.ShowWarning("用户名或密码错误");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(Form1));
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 对用户登录的操作进行验证
        /// </summary>
        /// <param name="username">用户账号</param>
        /// <param name="password">用户密码</param>
        /// <param name="code">验证码</param>
        /// <returns></returns>
        public ActionResult CheckUser(string username, string password, string code)
        {
            CommonResult result = new CommonResult();

            bool codeValidated = true;

            if (this.TempData["ValidateCode"] != null)
            {
                codeValidated = (this.TempData["ValidateCode"].ToString() == code);
            }

            if (string.IsNullOrEmpty(username))
            {
                result.ErrorMessage = "用户名不能为空";
            }
            else if (!codeValidated)
            {
                result.ErrorMessage = "验证码输入有误";
            }
            else
            {
                string ip       = NetworkUtil.GetLocalIP(); // TODO 这里要改成requestIP
                string macAddr  = HardwareInfoHelper.GetMacAddress();
                string identity = BLLFactory <User> .Instance.VerifyUser(username, password, Const.SystemTypeID, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <User> .Instance.GetUserByName(username);

                    if (info != null)
                    {
                        result.Success = true;

                        //方便方法使用
                        Session["UserInfo"] = info;

                        Session["FullName"]   = info.FullName;
                        Session["UserID"]     = info.ID;
                        Session["Company_ID"] = info.Company_ID;
                        Session["Dept_ID"]    = info.Dept_ID;
                        bool isSuperAdmin = BLLFactory <User> .Instance.UserInRole(info.Name, RoleInfo.SuperAdminName);//判断是否超级管理员

                        Session["IsSuperAdmin"] = isSuperAdmin;

                        Session["Identity"] = info.Name.Trim();

                        #region 取得用户的授权信息,并存储在Session中

                        List <FunctionInfo> functionList = BLLFactory <Functions> .Instance.GetFunctionsByUser(info.ID, Const.SystemTypeID);

                        Dictionary <string, string> functionDict = new Dictionary <string, string>();
                        foreach (FunctionInfo functionInfo in functionList)
                        {
                            if (!string.IsNullOrEmpty(functionInfo.FunctionId) &&
                                !functionDict.ContainsKey(functionInfo.FunctionId))
                            {
                                functionDict.Add(functionInfo.FunctionId, functionInfo.Name);
                            }
                        }
                        Session["Functions"] = functionDict;

                        #endregion
                    }
                }
                else
                {
                    result.ErrorMessage = "用户名输入错误或者您已经被禁用";
                }
            }

            return(ToJsonContent(result));
        }