Forráskód Böngészése

Merge branch 'add-auth' of 21IS12/SAS into master

BIN
src/SASDesktop/Assets/logout.png


+ 6 - 1
src/SASDesktop/AuthState.cs

@@ -11,6 +11,11 @@ namespace SASDesktop
         /// <summary>
         /// Текущий пользователь
         /// </summary>
-        private static object CurrentUser { get; set; } = null;
+        public static Models.Employee CurrentUser { get; set; } = null;
+
+        /// <summary>
+        /// Видима ли кнопка выхода
+        /// </summary>
+        public static bool LogoutButtonVisible = false;
     }
 }

+ 18 - 0
src/SASDesktop/MainWindow.xaml

@@ -4,6 +4,7 @@
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:SASDesktop"
+        xmlns:root="clr-namespace:SASDesktop" 
         mc:Ignorable="d"
         Icon="Assets/logo.png"
         Title="ГАС | ГосАвтоСистема" Height="600" Width="800">
@@ -22,6 +23,7 @@
             <Grid.ColumnDefinitions>
                 <ColumnDefinition Width="64"/>
                 <ColumnDefinition Width="*"/>
+                <ColumnDefinition Width="128"/>
             </Grid.ColumnDefinitions>
             
             <Image 
@@ -34,6 +36,22 @@
                 Grid.Column="1"
                 Style="{StaticResource H1}"
                 Text="ГосАвтоСистема"/>
+
+            <Button 
+                Margin="8,16"
+                x:Name="LogoutButton"
+                Visibility="Hidden"
+                Command="{Binding Source={x:Static root:Navigation.Logout}}"
+                Grid.Column="2">
+                <StackPanel Orientation="Horizontal">
+                    <TextBlock
+                        VerticalAlignment="Center"
+                        Text="Выход"/>
+                    <Image
+                        Source="/Assets/logout.png"/>
+                </StackPanel>
+                
+            </Button>
         </Grid>
 
         <!--Контент-->

+ 33 - 5
src/SASDesktop/Navigation.cs

@@ -14,12 +14,13 @@ namespace SASDesktop
     class Navigation
     {
         #region Команды
-        public static DelegateCommand ToDriverCreate { get; set; }      = new DelegateCommand(ToDriverCreateExecuted);
-        public static DelegateCommand ToDriverList { get; set; }        = new DelegateCommand(ToDriverListExecuted);
+        public static DelegateCommand ToDriverCreate    { get; set; }   = new DelegateCommand(ToDriverCreateExecuted);
+        public static DelegateCommand ToDriverList      { get; set; }   = new DelegateCommand(ToDriverListExecuted);
         public static DelegateCommand ToTransportCreate { get; set; }   = new DelegateCommand(ToTransportCreateExecuted);
-        public static DelegateCommand ToTransportList { get; set; }     = new DelegateCommand(ToTransportListExecuted);
+        public static DelegateCommand ToTransportList   { get; set; }   = new DelegateCommand(ToTransportListExecuted);
+        public static DelegateCommand Logout            { get; set; }   = new DelegateCommand(LogoutExecuted);//shotup
         #endregion
-        
+
         /// <summary>
         /// Возвращает главный фрейм приложения
         /// </summary>
@@ -27,7 +28,23 @@ namespace SASDesktop
         {
             return (App.Current.MainWindow as MainWindow).ContentBody;
         }
-        
+
+        /// <summary>
+        /// Показывает кнопку выхода
+        /// </summary>
+        public static void ShowLogoutButton()
+        {
+            (App.Current.MainWindow as MainWindow).LogoutButton.Visibility = System.Windows.Visibility.Visible;
+        }
+
+        /// <summary>
+        /// Скрывает кнопку выхода
+        /// </summary>
+        public static void HideLogoutButton()
+        {
+            (App.Current.MainWindow as MainWindow).LogoutButton.Visibility = System.Windows.Visibility.Hidden;
+        }
+
         /// <summary>
         /// Переводит на главную страницу приложения
         /// </summary>
@@ -67,5 +84,16 @@ namespace SASDesktop
         {
             throw new NotImplementedException();
         }
+
+        /// <summary>
+        /// Выполняет выход из приложенияя
+        /// </summary>
+        public static void LogoutExecuted()
+        {
+            AuthState.CurrentUser = null;
+            AuthState.LogoutButtonVisible = false;
+            HideLogoutButton();
+            GetMainFrame().Navigate(new Views.Auth());
+        }
     }
 }

+ 1 - 0
src/SASDesktop/SASDesktop.csproj

@@ -268,6 +268,7 @@
   </ItemGroup>
   <ItemGroup>
     <Resource Include="Assets\BlackAvatar.png" />
+    <Resource Include="Assets\logout.png" />
     <Content Include="Models\SAS.Context.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
       <LastGenOutput>SAS.Context.cs</LastGenOutput>

+ 14 - 3
src/SASDesktop/ViewModels/Auth.cs

@@ -50,6 +50,12 @@ namespace SASDesktop.ViewModels
 
         public Auth()
         {
+            var args = Environment.GetCommandLineArgs();
+            if (args[1] == "--debug")
+            {
+                Login = "inspector";
+                Password = "inspector";
+            }
             LoginCmd = new DelegateCommand(LoginExecuted);
         }
 
@@ -58,15 +64,20 @@ namespace SASDesktop.ViewModels
             // Пытаемся войти в приложение
             var db = new Models.SASEntities();
             var result = db.Employees.FirstOrDefault(e => e.Login == _login && e.Password == _password);
-            /* Раскомментировать, когда данные будут импортированы
+
             if (result == null)
             {
-                MessageBox.Show("Логин или пароль не совпадают");
+                List<string> errors = new List<string>
+                {
+                    "Логин или пароль неверны"
+                };
+                Popups.ShowErrors(errors);
                 Login = "";
                 Password = "";
                 return;
             }
-            */
+            AuthState.CurrentUser = result;
+            Navigation.ShowLogoutButton();
             Navigation.ToPortal();
         }
     }