예제 #1
0
        public bool Login(string appcode, string loginUser, string password, out string errorMsg)
        {
            errorMsg = string.Empty;
            if (loginUser.ToLower().Equals("root") && password.ToLower().Equals("aaaaaa"))
            {
                return(RootLogin(loginUser, password));
            }
            CurrenterUser = client.Login(loginUser);
            if (CurrenterUser == null)
            {
                errorMsg = "系统不存在该账号,请重新输入!";
                return(false);
            }
            else
            if (CurrenterUser.Pwd.Equals(password))
            {
                if (CurrenterUser.Status != "在职")
                {
                    errorMsg = string.Format("该账号状态不正常,为{0} 不能登陆系统!", CurrenterUser.Status);
                    return(false);
                }
                else
                {
                    RoleList = new List <Role>();
                    RoleList = client.GetRoleInfo(CurrenterUser.ID).ToList <Role>();
                    if (RoleList.Count == 0)
                    {
                        errorMsg = "该账号状态还没有设置角色, 不能登陆系统!";
                        return(false);
                    }
                    if (RoleList.Exists(pr => pr.IsDefault))
                    {
                        DefualtRole = CurrentRole = RoleList.Find(pr => pr.IsDefault);
                    }

                    //获取改账户的默认公司、部门、岗位、及默认角色和其他角色
                    List <OrganizationInfo> orgList = new OrganizationInfoClient().GetOrgnizationByUserID(CurrenterUser.ID).ToList <OrganizationInfo>();
                    if (orgList.Count > 0)
                    {
                        if (orgList.Exists(pr => pr.IsDefault))
                        {
                            //有默认部门
                            DepartInfo      = orgList.Find(pr => pr.IsDefault);
                            ComanyInfo      = new OrganizationInfo();
                            ComanyInfo.ID   = DepartInfo.CompID;
                            ComanyInfo.Name = DepartInfo.CompanyName;
                        }
                    }
                    HasLogin      = true;
                    LoginDateTime = ServerDateTime;
                    EntryIP       = Utils.GetMachineIP();
                    EntryStats    = "在线";
                    CreateLoginLog();
                    client.Save(log);
                    client.UpdateLoginStatus(CurrenterUser.ID, true);
                }
            }
            else
            {
                errorMsg = "密码不正确,请重新输入!";
                return(false);
            }

            return(true);
        }