From ccef96c6da37189d36bef5e82a9ec0e77bf6db9e Mon Sep 17 00:00:00 2001 From: Maciej Maciejewski Date: Thu, 24 Oct 2024 20:50:01 +0200 Subject: [PATCH] =?UTF-8?q?dodanie=20user=C3=B3w=20w=20klasie=20testowej?= =?UTF-8?q?=20user,=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/ProductController.cs | 2 +- TestClass.cs | 50 ++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Controllers/ProductController.cs b/Controllers/ProductController.cs index f1d03ba..e44a3ca 100644 --- a/Controllers/ProductController.cs +++ b/Controllers/ProductController.cs @@ -166,7 +166,7 @@ namespace FirmTracker_Server.Controllers [HttpGet] [ProducesResponseType(200)] // Created [ProducesResponseType(400)] // Bad Request - [Authorize(Roles =Roles.Admin)] + [Authorize(Roles = Roles.Admin + "," + Roles.User)] public IActionResult GetAllProducts() { var products = _productCrud.GetAllProducts(); diff --git a/TestClass.cs b/TestClass.cs index f06f43b..02cd16a 100644 --- a/TestClass.cs +++ b/TestClass.cs @@ -27,6 +27,7 @@ using AutoMapper; using FirmTracker_Server.Authentication; using Microsoft.AspNetCore.Identity; using FirmTracker_Server.Models; +using System.Data.SqlClient; namespace FirmTracker_Server { @@ -168,10 +169,53 @@ namespace FirmTracker_Server }; - + try + { + string appDirectory = Directory.GetCurrentDirectory(); + string configFilePath = Path.Combine(appDirectory, "appsettings.json"); + string connectionString = ""; + if (File.Exists(configFilePath)) + { + var config = new ConfigurationBuilder() + .AddJsonFile(configFilePath) + .Build(); + + var connectionstringsection = config.GetSection("AppSettings:ConnectionString"); + + connectionString = connectionstringsection.Value; + + //SessionFactory.Init(connectionString); + + string queryUser = "insert into Users(Email,PassHash,Role) select '123@wp.pl', 'GOsGemJarMJu8btZKF6Rung27JLZkdO7Wfd4CwLhL1k=','User'"; + string queryAdmin = "insert into Users(Email,PassHash,Role) select '321@wp.pl', 'GOsGemJarMJu8btZKF6Rung27JLZkdO7Wfd4CwLhL1k=','Admin'"; + + + SqlConnection connection = new SqlConnection(connectionString); + connection.Open(); + + SqlCommand command = new SqlCommand(queryUser, connection); + command.CommandTimeout = 200; + command.ExecuteNonQuery(); + connection.Close(); + + + SqlConnection connection2 = new SqlConnection(connectionString); + connection.Open(); + + SqlCommand command2 = new SqlCommand(queryAdmin, connection); + command2.CommandTimeout = 200; + command2.ExecuteNonQuery(); + connection2.Close(); + + } + + } + catch (Exception e) + { + Console.WriteLine("Nie udało się dodać kont użytkowników " + e.Message); + } + - - try {