Ejemplo n.º 1
0
        /// <summary>
        /// 权限路径改变回调方法
        /// </summary>
        private static void OnAuthorityPathChanged(BindableObject dependencyObject, object oldValue, object newValue)
        {
            if (GlobalSetting.AuthorizationEnabled)
            {
                VisualElement element       = (VisualElement)dependencyObject;
                string        authorityPath = newValue?.ToString();
                LoginInfo     loginInfo     = MembershipMediator.GetLoginInfo();

                #region # 验证

                if (string.IsNullOrWhiteSpace(authorityPath))
                {
                    throw new NullReferenceException("权限路径不可为空!");
                }
                if (loginInfo == null)
                {
                    throw new NoPermissionException("当前登录信息为空,请重新登录!");
                }

                #endregion

                //从登录信息中取出权限集
                IEnumerable <string> ownedAuthorityPaths = loginInfo.LoginAuthorityInfos.Select(x => x.Path);

                //验证权限
                if (ownedAuthorityPaths.Contains(authorityPath))
                {
                    element.IsVisible = true;
                }
                else
                {
                    element.IsVisible = false;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 转换元素可见性
        /// </summary>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (GlobalSetting.AuthorizationEnabled)
            {
                FrameworkElement element       = (FrameworkElement)value;
                string           authorityPath = element?.Tag?.ToString();
                LoginInfo        loginInfo     = MembershipMediator.GetLoginInfo();

                #region # 验证

                if (string.IsNullOrWhiteSpace(authorityPath))
                {
                    throw new ArgumentNullException(nameof(FrameworkElement.Tag), "权限路径不可为空!");
                }
                if (loginInfo == null)
                {
                    throw new NoPermissionException("当前登录信息为空,请重新登录!");
                }

                #endregion

                //从登录信息中取出权限集
                IEnumerable <string> ownedAuthorityPaths = loginInfo.LoginAuthorityInfos.Select(x => x.Path);

                //验证权限
                if (ownedAuthorityPaths.Contains(authorityPath))
                {
                    return(Visibility.Visible);
                }

                return(Visibility.Collapsed);
            }

            return(Visibility.Visible);
        }
Ejemplo n.º 3
0
        public void TestGetLoginInfo()
        {
            LoginInfo loginInfoInput = new LoginInfo(CommonConstants.AdminLoginId, "超级管理员", Guid.Empty);

            AppDomain.CurrentDomain.SetData(GlobalSetting.ApplicationId, loginInfoInput);

            LoginInfo loginInfoOutput = MembershipMediator.GetLoginInfo();

            Assert.AreEqual(loginInfoInput.LoginId, loginInfoOutput.LoginId);
        }
        /// <summary>
        /// 权限路径改变回调方法
        /// </summary>
        private static void OnAuthorityPathChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            if (GlobalSetting.AuthorizationEnabled)
            {
                string    authorityPath = eventArgs.NewValue?.ToString();
                LoginInfo loginInfo     = MembershipMediator.GetLoginInfo();

                #region # 验证

                if (string.IsNullOrWhiteSpace(authorityPath))
                {
                    throw new ArgumentNullException(nameof(AuthorityPath), "权限路径不可为空!");
                }
                if (loginInfo == null)
                {
                    throw new NoPermissionException("当前登录信息为空,请重新登录!");
                }

                #endregion

                //从登录信息中取出权限列表
                string[] ownedAuthorityPaths = loginInfo.LoginAuthorityInfos.Select(x => x.Path).ToArray();

                //验证权限
                if (dependencyObject is UIElement uiElement)
                {
                    if (ownedAuthorityPaths.Contains(authorityPath))
                    {
                        uiElement.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        uiElement.Visibility = Visibility.Collapsed;
                    }
                }
                if (dependencyObject is DataGridTemplateColumn columnElement)
                {
                    if (ownedAuthorityPaths.Contains(authorityPath))
                    {
                        columnElement.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        columnElement.Visibility = Visibility.Collapsed;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 注销登录
        /// </summary>
        public async void Logout()
        {
            MessageBoxResult result = MessageBox.Show("确定要注销吗?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                //清空Session
                MembershipMediator.SetLoginInfo(null);

                //跳转到登录窗体
                LoginViewModel loginViewModel = ResolveMediator.Resolve <LoginViewModel>();
                await this._windowManager.ShowWindowAsync(loginViewModel);

                //关闭当前窗口
                await base.TryCloseAsync();
            }
        }
        /// <summary>
        /// 拦截方法
        /// </summary>
        /// <param name="context">方法元数据</param>
        public void Advise(MethodAdviceContext context)
        {
            object[] attributes = context.TargetMethod.GetCustomAttributes(typeof(RequireAuthorizationAttribute), false);
            RequireAuthorizationAttribute attribute = attributes.Any() ? (RequireAuthorizationAttribute)attributes[0] : null;

            if (GlobalSetting.AuthorizationEnabled && attribute != null)
            {
                LoginInfo loginInfo = MembershipMediator.GetLoginInfo();
                if (loginInfo == null)
                {
                    throw new NoPermissionException("当前登录信息为空,请重新登录!");
                }

                IEnumerable <string> ownedAuthorityPaths = loginInfo.LoginAuthorityInfos.Select(x => x.Path);
                if (!ownedAuthorityPaths.Contains(attribute.AuthorityPath))
                {
                    throw new NoPermissionException("您没有权限,请联系系统管理员!");
                }
            }

            context.Proceed();
        }
Ejemplo n.º 7
0
        //Actions

        #region 提交 —— async void Submit()
        /// <summary>
        /// 提交
        /// </summary>
        public async void Submit()
        {
            #region # 验证

            if (string.IsNullOrWhiteSpace(this.OldPassword))
            {
                MessageBox.Show("旧密码不可为空!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(this.NewPassword))
            {
                MessageBox.Show("新密码不可为空!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(this.ConfirmedPassword))
            {
                MessageBox.Show("确认密码不可为空!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (this.NewPassword != this.ConfirmedPassword)
            {
                MessageBox.Show("两次密码输入不一致!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            #endregion

            this.Busy();

            LoginInfo loginInfo = MembershipMediator.GetLoginInfo();
            await Task.Run(() => this._userContract.Channel.UpdatePassword(loginInfo.LoginId, this.OldPassword, this.NewPassword));

            this.Idle();
            await base.TryCloseAsync(true);

            this.ToastSuccess("修改成功!");
        }
        //Actions

        #region 登录 —— async void Login()
        /// <summary>
        /// 登录
        /// </summary>
        public async void Login()
        {
            #region # 验证

            if (string.IsNullOrWhiteSpace(this.LoginId))
            {
                await this.Alert("用户名不可为空!");

                return;
            }
            if (string.IsNullOrWhiteSpace(this.Password))
            {
                await this.Alert("密码不可为空!");

                return;
            }

            #endregion

            this.Busy();

            LoginInfo loginInfo = await Task.Run(() => this._authenticationContract.Channel.Login(this.LoginId, this.Password));

            MembershipMediator.SetLoginInfo(loginInfo);

            this.Idle();

            TextToSpeech.SpeakAsync("登录成功");
            this.Toast($"登录成功!{loginInfo.LoginId}");

            IList <LoginMenuInfo> menuItems = new List <LoginMenuInfo>
            {
                new LoginMenuInfo
                {
                    Name         = "在线模式",
                    Icon         = "online",
                    SubMenuInfos = new List <LoginMenuInfo>
                    {
                        new LoginMenuInfo
                        {
                            Name         = "单据管理",
                            SubMenuInfos = new List <LoginMenuInfo>
                            {
                                new LoginMenuInfo
                                {
                                    Name = "收货管理",
                                    Icon = "warehouse_in",
                                },
                                new LoginMenuInfo
                                {
                                    Name = "发货管理",
                                    Icon = "warehouse_out",
                                    Url  = "url2"
                                }
                            }
                        },
                        new LoginMenuInfo
                        {
                            Name         = "托盘管理",
                            Icon         = "pallet_stacking",
                            Url          = "url3",
                            SubMenuInfos = new List <LoginMenuInfo>
                            {
                                new LoginMenuInfo
                                {
                                    Name = "装托",
                                    Icon = "pallet_stacking",
                                },
                                new LoginMenuInfo
                                {
                                    Name = "拼托",
                                    Icon = "pallet_join"
                                },
                                new LoginMenuInfo
                                {
                                    Name = "拆托",
                                    Icon = "pallet_breaking"
                                },
                                new LoginMenuInfo
                                {
                                    Name = "换托/货",
                                    Icon = "pallet_change"
                                }
                            }
                        }
                    }
                },
                new LoginMenuInfo
                {
                    Name         = "离线模式",
                    Icon         = "offline",
                    SubMenuInfos = new List <LoginMenuInfo>
                    {
                        new LoginMenuInfo
                        {
                            Name         = "单据管理",
                            SubMenuInfos = new List <LoginMenuInfo>
                            {
                                new LoginMenuInfo
                                {
                                    Name = "收货管理",
                                    Icon = "warehouse_in",
                                    Url  = "url2"
                                },
                                new LoginMenuInfo
                                {
                                    Name = "发货管理",
                                    Icon = "warehouse_out",
                                    Url  = "url2"
                                }
                            }
                        }
                    }
                },
                new LoginMenuInfo
                {
                    Name         = "个人中心",
                    Icon         = "center",
                    SubMenuInfos = new List <LoginMenuInfo>
                    {
                        new LoginMenuInfo
                        {
                            Name         = "个人中心",
                            SubMenuInfos = new List <LoginMenuInfo>
                            {
                                new LoginMenuInfo
                                {
                                    Name = "设备注册",
                                    Icon = "device_info",
                                },
                                new LoginMenuInfo
                                {
                                    Name = "修改密码",
                                    Icon = "stock_taking_order",
                                }
                            }
                        }
                    }
                }
            };
            this._navigationService
            .For <IndexViewModel>()
            .WithParam(x => x.MenuItems, new ObservableCollection <LoginMenuInfo>(menuItems))
            .Navigate(false);
        }