示例#1
0
        public static int Login(string account, string password)
        {
            NeuPrincipal _principal = null;
            NeuIdentity  _identity  = null;

            if (Program.isMessageShow == true)
            {
                Program.isMessageShow = false;
                return(-1);
            }
            //认证
            PrivilegeService proxy = new PrivilegeService();

            try
            {
                _identity = proxy.Authenticate(account, password, "");
                ///
                ///查询该用户拥有的角色
                IList <Role> _roles;

                using (proxy as IDisposable)
                {
                    //表更改了,所以修改了SQL语句(张凯钧)Security.Org.GetRoleByUserID
                    _roles = proxy.QueryRole(_identity.User.Id);
                }

                if (_roles == null | _roles.Count == 0)
                {
                    Program.isMessageShow = false;
                    MessageBox.Show("该用户没有进行角色授权!");
                    Program.isMessageShow = true;
                    return(-1);
                }

                _principal = new NeuPrincipal(_identity, _roles);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    Program.isMessageShow = false;
                    MessageBox.Show(ex.Message);
                    Program.isMessageShow = true;
                }
                else
                {
                    SystemErrorForm _error = new SystemErrorForm(ex);
                    _error.ShowDialog();
                }

                return(-1);
            }

            if (_principal.Identity.IsAuthenticated)
            {
                //加载选择角色科室界面
                Role _role = SelectLoginRole((_principal.Identity as NeuIdentity).User, _principal.Roles);

                if (_role == null)
                {
                    Application.Exit();
                    //{AE0687E4-FE13-4b00-8865-738F84B74BB2}
                    return(-1);
                }

                //通过认证以后,给当前角色赋值;
                _principal.CurrentRole = _role;


                //设置登录时间
                _principal.LoginTime = Neusoft.FrameWork.Function.NConvert.ToDateTime(new Neusoft.FrameWork.Management.DataBaseManger().GetSysDateTime());

                //设置当前操作员信息
                SetLoginUser((_principal.Identity as NeuIdentity).User, (Neusoft.FrameWork.Models.NeuObject)_principal.CurrentRole, _principal.CurrentRole.UnitId);
            }
            return(0);
        }