瀏覽代碼

Добавьте файлы проекта.

AnnaBezaeva 6 小時之前
父節點
當前提交
fc1cacac04

+ 25 - 0
RegAuth.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.11.35219.272
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegAuth", "RegAuth\RegAuth.csproj", "{B1E499BB-DDA0-4BD1-A59D-76AA406FEB7C}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{B1E499BB-DDA0-4BD1-A59D-76AA406FEB7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{B1E499BB-DDA0-4BD1-A59D-76AA406FEB7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B1E499BB-DDA0-4BD1-A59D-76AA406FEB7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{B1E499BB-DDA0-4BD1-A59D-76AA406FEB7C}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {5436BC11-2F02-4B3E-9B4F-C993020448E5}
+	EndGlobalSection
+EndGlobal

+ 15 - 0
RegAuth/App.axaml

@@ -0,0 +1,15 @@
+<Application xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             x:Class="RegAuth.App"
+             xmlns:local="using:RegAuth"
+             RequestedThemeVariant="Default">
+             <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
+
+    <Application.DataTemplates>
+        <local:ViewLocator/>
+    </Application.DataTemplates>
+  
+    <Application.Styles>
+        <FluentTheme />
+    </Application.Styles>
+</Application>

+ 29 - 0
RegAuth/App.axaml.cs

@@ -0,0 +1,29 @@
+using Avalonia;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Markup.Xaml;
+using RegAuth.ViewModels;
+using RegAuth.Views;
+
+namespace RegAuth
+{
+    public partial class App : Application
+    {
+        public override void Initialize()
+        {
+            AvaloniaXamlLoader.Load(this);
+        }
+
+        public override void OnFrameworkInitializationCompleted()
+        {
+            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+            {
+                desktop.MainWindow = new MainWindow
+                {
+                    DataContext = new MainWindowViewModel(),
+                };
+            }
+
+            base.OnFrameworkInitializationCompleted();
+        }
+    }
+}

二進制
RegAuth/Assets/avalonia-logo.ico


+ 13 - 0
RegAuth/Models/Role.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+
+namespace RegAuth.Models;
+
+public partial class Role
+{
+    public long Id { get; set; }
+
+    public string? Role1 { get; set; }
+
+    public virtual ICollection<User> Users { get; set; } = new List<User>();
+}

+ 21 - 0
RegAuth/Models/User.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+
+namespace RegAuth.Models;
+
+public partial class User
+{
+    public long Id { get; set; }
+
+    public string Fio { get; set; } = null!;
+
+    public string Login { get; set; } = null!;
+
+    public long Roleid { get; set; }
+
+    public List<byte[]>? Img { get; set; }
+
+    public byte[]? Password { get; set; }
+
+    public virtual Role Role { get; set; } = null!;
+}

+ 69 - 0
RegAuth/Models/_43pBezaeva2Context.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.EntityFrameworkCore;
+
+namespace RegAuth.Models;
+
+public partial class _43pBezaeva2Context : DbContext
+{
+    public _43pBezaeva2Context()
+    {
+    }
+
+    public _43pBezaeva2Context(DbContextOptions<_43pBezaeva2Context> options)
+        : base(options)
+    {
+    }
+
+    public virtual DbSet<Role> Roles { get; set; }
+
+    public virtual DbSet<User> Users { get; set; }
+
+    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
+        => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.local;Port=5432;Database=43P_Bezaeva2;Username=43P;Password=444444");
+
+    protected override void OnModelCreating(ModelBuilder modelBuilder)
+    {
+        modelBuilder.Entity<Role>(entity =>
+        {
+            entity.HasKey(e => e.Id).HasName("role_pk");
+
+            entity.ToTable("role");
+
+            entity.Property(e => e.Id).HasColumnName("id");
+            entity.Property(e => e.Role1)
+                .HasColumnType("character varying")
+                .HasColumnName("role");
+        });
+
+        modelBuilder.Entity<User>(entity =>
+        {
+            entity.HasKey(e => e.Id).HasName("users_pk");
+
+            entity.ToTable("users");
+
+            entity.Property(e => e.Id).HasColumnName("id");
+            entity.Property(e => e.Fio)
+                .HasColumnType("character varying")
+                .HasColumnName("fio");
+            entity.Property(e => e.Img).HasColumnName("img");
+            entity.Property(e => e.Login)
+                .HasColumnType("character varying")
+                .HasColumnName("login");
+            entity.Property(e => e.Password).HasColumnName("password");
+            entity.Property(e => e.Roleid)
+                .ValueGeneratedOnAdd()
+                .HasColumnName("roleid");
+
+            entity.HasOne(d => d.Role).WithMany(p => p.Users)
+                .HasForeignKey(d => d.Roleid)
+                .OnDelete(DeleteBehavior.ClientSetNull)
+                .HasConstraintName("users_role_fk");
+        });
+
+        OnModelCreatingPartial(modelBuilder);
+    }
+
+    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
+}

+ 24 - 0
RegAuth/Program.cs

@@ -0,0 +1,24 @@
+using Avalonia;
+using Avalonia.ReactiveUI;
+using System;
+
+namespace RegAuth
+{
+    internal sealed class Program
+    {
+        // Initialization code. Don't use any Avalonia, third-party APIs or any
+        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
+        // yet and stuff might break.
+        [STAThread]
+        public static void Main(string[] args) => BuildAvaloniaApp()
+            .StartWithClassicDesktopLifetime(args);
+
+        // Avalonia configuration, don't remove; also used by visual designer.
+        public static AppBuilder BuildAvaloniaApp()
+            => AppBuilder.Configure<App>()
+                .UsePlatformDetect()
+                .WithInterFont()
+                .LogToTrace()
+                .UseReactiveUI();
+    }
+}

+ 30 - 0
RegAuth/RegAuth.csproj

@@ -0,0 +1,30 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <Nullable>enable</Nullable>
+    <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
+    <ApplicationManifest>app.manifest</ApplicationManifest>
+    <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Folder Include="Models\" />
+    <AvaloniaResource Include="Assets\**" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Avalonia" Version="11.1.0" />
+    <PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
+    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
+    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
+    <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
+    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
+    <PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.1" />
+  </ItemGroup>
+</Project>

+ 34 - 0
RegAuth/ViewLocator.cs

@@ -0,0 +1,34 @@
+using Avalonia.Controls;
+using Avalonia.Controls.Templates;
+using RegAuth.ViewModels;
+using System;
+
+namespace RegAuth
+{
+    public class ViewLocator : IDataTemplate
+    {
+
+        public Control? Build(object? data)
+        {
+            if (data is null)
+                return null;
+
+            var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
+            var type = Type.GetType(name);
+
+            if (type != null)
+            {
+                var control = (Control)Activator.CreateInstance(type)!;
+                control.DataContext = data;
+                return control;
+            }
+
+            return new TextBlock { Text = "Not Found: " + name };
+        }
+
+        public bool Match(object? data)
+        {
+            return data is ViewModelBase;
+        }
+    }
+}

+ 23 - 0
RegAuth/ViewModels/AuthViewModel.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+using ReactiveUI;
+using System.Text;
+using RegAuth.Models;
+using Microsoft.EntityFrameworkCore;
+using System.Linq;
+namespace RegAuth.ViewModels
+{
+	internal class AuthViewModel : ViewModelBase
+    {
+		string _login = "";
+		string _password = "";
+		public string Login { get=>_login; set=>_login = value; }
+		public string Password { get=>_password; set=>_password = value; }
+	    public void AuthUser()
+		{
+			byte[] _hashPassword = MD5.HashData(Encoding.ASCII.GetBytes(_password));
+		User user = MainWindowViewModel.myConnection.Users.Include(x=>x.Roleid).FirstOrDefault(x=>x.Login == _login && x.Password == _hashPassword);
+		}
+	}
+}

+ 21 - 0
RegAuth/ViewModels/MainViewModel.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using ReactiveUI;
+
+namespace RegAuth.ViewModels
+{
+	internal class MainViewModel : ViewModelBase
+	{
+        public void ToAuth()
+        {
+            MainWindowViewModel.Instance.Uc = new Auth();
+        }
+
+        public void ToReg()
+        {
+
+            MainWindowViewModel.Instance.Uc = new Reg();
+        }
+
+    }
+}

+ 18 - 0
RegAuth/ViewModels/MainWindowViewModel.cs

@@ -0,0 +1,18 @@
+using Avalonia.Controls;
+using ReactiveUI;
+using RegAuth.Models;
+
+namespace RegAuth.ViewModels
+{
+    public class MainWindowViewModel : ViewModelBase
+    {
+        public static MainWindowViewModel Instance;
+        public static _43pBezaeva2Context myConnection = new _43pBezaeva2Context();
+        public MainWindowViewModel()
+        {
+            Instance = this;
+        }
+        UserControl _uc = new Main();
+        public UserControl Uc { get => _uc; set => this.RaiseAndSetIfChanged(ref _uc, value); }
+    }
+}

+ 29 - 0
RegAuth/ViewModels/RegViewModel.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using ReactiveUI;
+using RegAuth.Models;
+using System.Security.Cryptography;
+using System.Text;
+namespace RegAuth.ViewModels
+{
+	internal class RegViewModel : ViewModelBase 
+    { 
+        User _newUser = new User();
+        public User NewUser { get => _newUser; set => this.RaiseAndSetIfChanged(ref _newUser, value); }
+        string _password;
+        public string Password { get => _password; set => _password = value; }
+
+        public void AddUser()
+        {
+            if (_password != string.Empty)
+            {
+                NewUser.Password = MD5.HashData(Encoding.ASCII.GetBytes(Password));
+            }
+            NewUser.Roleid = 1;
+            MainWindowViewModel.myConnection.Users.Add(NewUser);
+            MainWindowViewModel.myConnection.SaveChanges();
+            MainWindowViewModel.Instance.Uc = new Main();
+        }
+    }
+}

+ 8 - 0
RegAuth/ViewModels/ViewModelBase.cs

@@ -0,0 +1,8 @@
+using ReactiveUI;
+
+namespace RegAuth.ViewModels
+{
+    public class ViewModelBase : ReactiveObject
+    {
+    }
+}

+ 10 - 0
RegAuth/Views/Auth.axaml

@@ -0,0 +1,10 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+              xmlns:vm="using:RegAuth.ViewModels"
+			 x:DataType="vm:AuthViewModel"
+			 x:Class="RegAuth.Auth">
+  Welcome to Avalonia!
+</UserControl>

+ 16 - 0
RegAuth/Views/Auth.axaml.cs

@@ -0,0 +1,16 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using RegAuth.ViewModels;
+
+namespace RegAuth;
+
+public partial class Auth : UserControl
+{
+    public Auth()
+    {
+        
+        InitializeComponent();
+        DataContext = new AuthViewModel();
+    }
+}

+ 16 - 0
RegAuth/Views/Main.axaml

@@ -0,0 +1,16 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+                xmlns:vm="using:RegAuth.ViewModels"
+			 x:DataType="vm:MainViewModel"
+			 x:Class="RegAuth.Main">
+	<Grid>
+		<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
+		
+			<Button Command="{Binding ToAuth}">Авторизация</Button>
+			<Button Command="{Binding ToReg}">Регистрация</Button>
+		</StackPanel>
+	</Grid>
+</UserControl>

+ 15 - 0
RegAuth/Views/Main.axaml.cs

@@ -0,0 +1,15 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using RegAuth.ViewModels;
+
+namespace RegAuth;
+
+public partial class Main : UserControl
+{
+    public Main()
+    {
+        InitializeComponent();
+        DataContext = new MainViewModel();
+    }
+}

+ 21 - 0
RegAuth/Views/MainWindow.axaml

@@ -0,0 +1,21 @@
+<Window xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:vm="using:RegAuth.ViewModels"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+        x:Class="RegAuth.Views.MainWindow"
+        x:DataType="vm:MainWindowViewModel"
+        Icon="/Assets/avalonia-logo.ico"
+        Title="RegAuth">
+
+    <Design.DataContext>
+        <!-- This only sets the DataContext for the previewer in an IDE,
+             to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
+        <vm:MainWindowViewModel/>
+    </Design.DataContext>
+
+	<UserControl Content="{Binding Uc}">
+
+	</UserControl>
+</Window>

+ 12 - 0
RegAuth/Views/MainWindow.axaml.cs

@@ -0,0 +1,12 @@
+using Avalonia.Controls;
+
+namespace RegAuth.Views
+{
+    public partial class MainWindow : Window
+    {
+        public MainWindow()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 20 - 0
RegAuth/Views/Reg.axaml

@@ -0,0 +1,20 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+              xmlns:vm="using:RegAuth.ViewModels"
+			 x:DataType="vm:RegViewModel"
+			 x:Class="RegAuth.Reg">
+	<Grid>
+		<StackPanel>
+			<TextBlock>Введите имя</TextBlock>
+			<TextBox Text="{Binding NewUser.Fio}"></TextBox>
+			<TextBlock>Введите логин</TextBlock>
+			<TextBox Text="{Binding NewUser.Login}"></TextBox>
+			<TextBlock>Введите пароль</TextBlock>
+			<TextBox PasswordChar="*" Text="{Binding Password}"></TextBox>
+			<Button Command="{Binding AddUser}">Зарегистировать</Button>
+		</StackPanel>
+	</Grid>
+</UserControl>

+ 15 - 0
RegAuth/Views/Reg.axaml.cs

@@ -0,0 +1,15 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using RegAuth.ViewModels;
+
+namespace RegAuth;
+
+public partial class Reg : UserControl
+{
+    public Reg()
+    {
+        InitializeComponent();
+        DataContext = new RegViewModel();
+    }
+}

+ 18 - 0
RegAuth/app.manifest

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <!-- This manifest is used on Windows only.
+       Don't remove it as it might cause problems with window transparency and embedded controls.
+       For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
+  <assemblyIdentity version="1.0.0.0" name="RegAuth.Desktop"/>
+
+  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+    <application>
+      <!-- A list of the Windows versions that this application has been tested on
+           and is designed to work with. Uncomment the appropriate elements
+           and Windows will automatically select the most compatible environment. -->
+
+      <!-- Windows 10 -->
+      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
+    </application>
+  </compatibility>
+</assembly>