diff --git a/csharp/InnovEnergy.sln b/csharp/InnovEnergy.sln
index 9247b7144..69f33a105 100644
--- a/csharp/InnovEnergy.sln
+++ b/csharp/InnovEnergy.sln
@@ -24,8 +24,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "S3", "lib/S3/S3.csproj", "{
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "deprecated", "deprecated", "{46DE03C4-52D1-47AA-8E60-8BB15361D723}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsController", "app/CsController/CsController.csproj", "{72DBBE42-A09F-43C0-9613-331039857056}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SaliMax", "app/SaliMax/SaliMax.csproj", "{25073794-D859-4824-9984-194C7E928496}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatusApi", "lib/StatusApi/StatusApi.csproj", "{9D17E78C-8A70-43DB-A619-DC12D20D023D}"
@@ -112,10 +110,6 @@ Global
{C3639841-13F4-4F24-99C6-7D965593BF89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3639841-13F4-4F24-99C6-7D965593BF89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3639841-13F4-4F24-99C6-7D965593BF89}.Release|Any CPU.Build.0 = Release|Any CPU
- {72DBBE42-A09F-43C0-9613-331039857056}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {72DBBE42-A09F-43C0-9613-331039857056}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {72DBBE42-A09F-43C0-9613-331039857056}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {72DBBE42-A09F-43C0-9613-331039857056}.Release|Any CPU.Build.0 = Release|Any CPU
{25073794-D859-4824-9984-194C7E928496}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25073794-D859-4824-9984-194C7E928496}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25073794-D859-4824-9984-194C7E928496}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -195,7 +189,6 @@ Global
{E3A5F3A3-72A5-47CC-85C6-2D8E962A0EC1} = {145597B4-3E30-45E6-9F72-4DD43194539A}
{46DE03C4-52D1-47AA-8E60-8BB15361D723} = {AD5B98A8-AB7F-4DA2-B66D-5B4E63E7D854}
{4A67D79F-F0C9-4BBC-9601-D5948E6C05D3} = {46DE03C4-52D1-47AA-8E60-8BB15361D723}
- {72DBBE42-A09F-43C0-9613-331039857056} = {145597B4-3E30-45E6-9F72-4DD43194539A}
{25073794-D859-4824-9984-194C7E928496} = {145597B4-3E30-45E6-9F72-4DD43194539A}
{9D17E78C-8A70-43DB-A619-DC12D20D023D} = {AD5B98A8-AB7F-4DA2-B66D-5B4E63E7D854}
{C3639841-13F4-4F24-99C6-7D965593BF89} = {46DE03C4-52D1-47AA-8E60-8BB15361D723}
diff --git a/csharp/app/Backend/Backend.csproj b/csharp/app/Backend/Backend.csproj
index c082226db..e6a136cb1 100644
--- a/csharp/app/Backend/Backend.csproj
+++ b/csharp/app/Backend/Backend.csproj
@@ -4,6 +4,8 @@
net6.0
enable
enable
+ preview
+ Innovenergy.Backend
diff --git a/csharp/app/Backend/Controllers/Controller.cs b/csharp/app/Backend/Controllers/Controller.cs
index 32b53084e..10110397e 100644
--- a/csharp/app/Backend/Controllers/Controller.cs
+++ b/csharp/app/Backend/Controllers/Controller.cs
@@ -1,21 +1,21 @@
using System.Net;
using System.Text;
-using System.Text.Json;
-using Backend.Database;
-using Backend.Model;
-using Backend.Model.Relations;
-using Backend.Utils;
+using Innovenergy.Backend.Database;
+using Innovenergy.Backend.Model;
+using Innovenergy.Backend.Model.Relations;
+using Innovenergy.Backend.Utils;
using Microsoft.AspNetCore.Mvc;
using HttpContextAccessor = Microsoft.AspNetCore.Http.HttpContextAccessor;
-namespace Backend.Controllers;
+namespace Innovenergy.Backend.Controllers;
[ApiController]
[Route("api/")]
public class Controller
{
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+ [Returns]
+ [Returns(HttpStatusCode.Unauthorized)]
+ [Returns(HttpStatusCode.BadRequest)]
[HttpPost($"{nameof(Login)}")]
public Object Login(Credentials credentials)
{
@@ -29,181 +29,175 @@ public class Controller
if (user is null)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
- // if (!VerifyPassword(password, user))
- // return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+ #if !DEBUG
+ if (!VerifyPassword(credentials.Password, user))
+ return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+ #endif
var ses = new Session(user);
db.NewSession(ses);
return ses.Token;
}
- private static Boolean VerifyPassword(String password, User user)
- {
- var pwdBytes = Encoding.UTF8.GetBytes(password);
- var saltBytes = Encoding.UTF8.GetBytes(user.Salt + "innovEnergy");
- var pwdHash = Crypto.ComputeHash(pwdBytes, saltBytes);
- return user.Password == pwdHash;
- }
-
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+ [Returns(HttpStatusCode.OK)]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpPost($"{nameof(Logout)}")]
public Object Logout()
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
+ var caller = GetCaller();
- if (currentUser is null)
- return new HttpResponseMessage(HttpStatusCode.Conflict);
+ if (caller is null)
+ return new HttpResponseMessage(HttpStatusCode.Unauthorized);
- return db.DeleteSession(currentUser.Id);
+ using var db = Db.Connect();
+ return db.DeleteSession(caller.Id);
}
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
- [HttpPost($"{nameof(UpdateS3Creds)}")]
- public Object UpdateS3Creds()
+
+ [Returns(HttpStatusCode.OK)]
+ [Returns(HttpStatusCode.Unauthorized)]
+ [HttpPost($"{nameof(UpdateS3Credentials)}")]
+ public Object UpdateS3Credentials()
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- using var db = Db.Connect();
- var currentUser = (User)ctx!.Items["User"]!;
+ // TODO: S3Credentials should be per session, not per user
- return db.CreateAndSaveUserS3ApiKey(currentUser);
+ var caller = GetCaller();
+ if (caller is null)
+ return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+
+ using var db = Db.Connect();
+
+ return db.CreateAndSaveUserS3ApiKey(caller);
}
- [ProducesResponseType(typeof(User), 200)]
- [ProducesResponseType(401)]
+ [Returns]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpGet($"{nameof(GetUserById)}")]
public Object GetUserById(Int64 id)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
- var viewedUser = db.GetUserById(id);
-
- //using the same error to prevent fishing for ids
- if (currentUser == null || viewedUser == null || !db.IsParentOfChild(currentUser, viewedUser))
+ var caller = GetCaller();
+ if (caller is null)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+
+ using var db = Db.Connect();
- return viewedUser;
+ var user = db
+ .GetDescendantUsers(caller)
+ .FirstOrDefault(u => u.Id == id);
+
+ return user as Object ?? new HttpResponseMessage(HttpStatusCode.Unauthorized);
}
- [ProducesResponseType(typeof(Installation), 200)]
- [ProducesResponseType(401)]
+
+ [Returns]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpGet($"{nameof(GetInstallationById)}")]
public Object GetInstallationById(Int64 id)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
-
- if (currentUser == null)
+ var caller = GetCaller();
+ if (caller == null)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+ using var db = Db.Connect();
+
var installation = db
- .GetAllAccessibleInstallations(currentUser)
+ .GetAllAccessibleInstallations(caller)
.FirstOrDefault(i => i.Id == id);
- if (installation is null)
- return new HttpResponseMessage(HttpStatusCode.NotFound);
-
- return installation;
+ return installation as Object ?? new HttpResponseMessage(HttpStatusCode.NotFound);
}
- [ProducesResponseType(typeof(Folder), 200)]
- [ProducesResponseType(401)]
+
+ [Returns]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpGet($"{nameof(GetFolderById)}")]
public Object GetFolderById(Int64 id)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
+ var caller = GetCaller();
+ if (caller == null)
+ return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+
using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
-
+
var folder = db
- .GetAllAccessibleFolders(currentUser!)
+ .GetAllAccessibleFolders(caller)
.FirstOrDefault(f => f.Id == id);
- if(folder is null)
- return new HttpResponseMessage(HttpStatusCode.NotFound);
-
- return folder;
+ return folder as Object ?? new HttpResponseMessage(HttpStatusCode.NotFound);
}
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+
+ [Returns] // assuming swagger knows about arrays but not lists (JSON)
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpGet($"{nameof(GetAllInstallations)}/")]
public Object GetAllInstallations()
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- using var db = Db.Connect();
- var user = (User)ctx.Items["User"];
-
- if (user == null)
+ var caller = GetCaller();
+ if (caller == null)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+
+ using var db = Db.Connect();
- return db.GetAllAccessibleInstallations(user).ToList();
+ return db
+ .GetAllAccessibleInstallations(caller)
+ .ToList(); // important!
}
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+
+ [Returns] // assuming swagger knows about arrays but not lists (JSON)
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpGet($"{nameof(GetAllFolders)}/")]
public Object GetAllFolders()
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- var user = (User)ctx.Items["User"];
-
- using var db = Db.Connect();
-
- if (user == null)
+ var caller = GetCaller();
+ if (caller == null)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
-
- return db.GetAllAccessibleFolders(user).ToList();
+
+ using var db = Db.Connect();
+ return db
+ .GetAllAccessibleFolders(caller)
+ .ToList(); // important!
}
+
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+ [Returns(HttpStatusCode.OK)]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpPut($"{nameof(UpdateUser)}/")]
public Object UpdateUser(User updatedUser)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
-
- if (currentUser == null || !currentUser.HasWriteAccess || !db.IsParentOfChild(currentUser, updatedUser))
+ // TODO: distinguish between create and update
+
+ var caller = GetCaller();
+ if (caller == null)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
- return db.GetUserById(updatedUser.Id) != null ? db.UpdateUser(updatedUser) : db.CreateUser(updatedUser);
+ using var db = Db.Connect();
+
+ return db.GetUserById(updatedUser.Id) != null
+ ? db.UpdateUser(updatedUser)
+ : db.CreateUser(updatedUser);
}
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+
+ [Returns(HttpStatusCode.OK)]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpPut($"{nameof(UpdateInstallation)}/")]
public Object UpdateInstallation(Installation updatedInstallation)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
+ var caller = GetCaller();
- var currentUser = (User)ctx.Items["User"];
-
- if (currentUser == null || !currentUser.HasWriteAccess)
+ if (caller is null || !caller.HasWriteAccess)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
-
+
using var db = Db.Connect();
- var hasAccess = db.GetAllAccessibleInstallations(currentUser)
- .Any(i => i.Id == updatedInstallation.Id);
- if (!hasAccess)
+ var hasAccessToInstallation = db
+ .GetAllAccessibleInstallations(caller)
+ .Any(i => i.Id == updatedInstallation.Id);
+
+ if (!hasAccessToInstallation)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
// TODO: accessibility by other users etc
@@ -213,64 +207,68 @@ public class Controller
}
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+ [Returns(HttpStatusCode.OK)]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpPut($"{nameof(UpdateFolder)}/")]
- public Object UpdateFolder(Folder updatedFolder)
+ public Object UpdateFolder(Folder folder)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
-
- if (currentUser == null || !currentUser.HasWriteAccess)
+ var caller = GetCaller();
+
+ if (caller is null || !caller.HasWriteAccess)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
- var hasAccess = db.GetAllAccessibleFolders(currentUser)
- .Any(f => f.Id == updatedFolder.Id);
+ using var db = Db.Connect();
+
+ var hasAccessToFolder = db
+ .GetAllAccessibleFolders(caller)
+ .Any(f => f.Id == folder.Id);
- if (!hasAccess)
+ if (!hasAccessToFolder)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
// TODO: accessibility by other users etc
// TODO: sanity check changes
- return db.UpdateFolder(updatedFolder);
+ return db.UpdateFolder(folder);
}
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+ [Returns(HttpStatusCode.OK)]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpDelete($"{nameof(DeleteUser)}/")]
public Object DeleteUser(Int64 userId)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
- using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
- var userToBeDeleted = db.GetUserById(userId);
+ var caller = GetCaller();
- if (currentUser == null
- || userToBeDeleted == null
- || !currentUser.HasWriteAccess
- || !db.IsParentOfChild(currentUser,userToBeDeleted))
+ if (caller is null || !caller.HasWriteAccess)
+ return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+
+ using var db = Db.Connect();
+
+ var userToBeDeleted = db
+ .GetDescendantUsers(caller)
+ .FirstOrDefault(u => u.Id == userId);
+
+ if (userToBeDeleted is null)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
return db.DeleteUser(userToBeDeleted);
}
- [ProducesResponseType(200)]
- [ProducesResponseType(401)]
+ [Returns(HttpStatusCode.OK)]
+ [Returns(HttpStatusCode.Unauthorized)]
[HttpDelete($"{nameof(DeleteInstallation)}/")]
- public Object DeleteInstallation(Int64 idOfInstallationToBeDeleted)
+ public Object DeleteInstallation(Int64 installationId)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
+ var caller = GetCaller();
+
+ if (caller is null || !caller.HasWriteAccess)
+ return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+
using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
var installationToBeDeleted = db
- .GetAllAccessibleInstallations(currentUser!)
- .FirstOrDefault(i => i.Id == idOfInstallationToBeDeleted);
+ .GetAllAccessibleInstallations(caller)
+ .FirstOrDefault(i => i.Id == installationId);
if (installationToBeDeleted is null)
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
@@ -278,18 +276,20 @@ public class Controller
return db.DeleteInstallation(installationToBeDeleted);
}
+
[ProducesResponseType(200)]
[ProducesResponseType(401)]
[HttpDelete($"{nameof(DeleteFolder)}/")]
public Object DeleteFolder(Int64 folderId)
{
- var ctxAccessor = new HttpContextAccessor();
- var ctx = ctxAccessor.HttpContext;
+ var caller = GetCaller();
+ if (caller == null)
+ return new HttpResponseMessage(HttpStatusCode.Unauthorized);
+
using var db = Db.Connect();
- var currentUser = (User)ctx.Items["User"];
var folderToDelete = db
- .GetAllAccessibleFolders(currentUser!)
+ .GetAllAccessibleFolders(caller)
.FirstOrDefault(f => f.Id == folderId);
if (folderToDelete is null)
@@ -299,5 +299,22 @@ public class Controller
}
+ private static User? GetCaller()
+ {
+ var ctxAccessor = new HttpContextAccessor();
+ return ctxAccessor.HttpContext?.Items["User"] as User;
+ }
+
+ private static Boolean VerifyPassword(String password, User user)
+ {
+ var pwdBytes = Encoding.UTF8.GetBytes(password);
+ var saltBytes = Encoding.UTF8.GetBytes(user.Salt + "innovEnergy");
+ var pwdHash = Crypto.ComputeHash(pwdBytes, saltBytes);
+
+ return user.Password == pwdHash;
+ }
+
}
+
+
diff --git a/csharp/app/Backend/Controllers/Credentials.cs b/csharp/app/Backend/Controllers/Credentials.cs
index 43c86a811..2c5c72b45 100644
--- a/csharp/app/Backend/Controllers/Credentials.cs
+++ b/csharp/app/Backend/Controllers/Credentials.cs
@@ -1,3 +1,6 @@
-namespace Backend.Controllers;
+using System.Diagnostics.CodeAnalysis;
+namespace Innovenergy.Backend.Controllers;
+
+[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public record Credentials(String Username, String Password);
\ No newline at end of file
diff --git a/csharp/app/Backend/Controllers/ReturnsAttribute.cs b/csharp/app/Backend/Controllers/ReturnsAttribute.cs
new file mode 100644
index 000000000..6d94088f5
--- /dev/null
+++ b/csharp/app/Backend/Controllers/ReturnsAttribute.cs
@@ -0,0 +1,22 @@
+using System.Net;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Innovenergy.Backend.Controllers;
+
+public class ReturnsAttribute : ProducesResponseTypeAttribute
+{
+ public ReturnsAttribute(HttpStatusCode statusCode) : base((Int32)statusCode)
+ {
+ }
+}
+
+public class ReturnsAttribute : ProducesResponseTypeAttribute
+{
+ public ReturnsAttribute(HttpStatusCode statusCode) : base(typeof(T), (Int32)statusCode)
+ {
+ }
+
+ public ReturnsAttribute() : base(typeof(T), (Int32)HttpStatusCode.OK)
+ {
+ }
+}
\ No newline at end of file
diff --git a/csharp/app/Backend/Database/Db.cs b/csharp/app/Backend/Database/Db.cs
index 92d31ca84..aaabfbfd9 100644
--- a/csharp/app/Backend/Database/Db.cs
+++ b/csharp/app/Backend/Database/Db.cs
@@ -1,11 +1,11 @@
using System.Diagnostics.CodeAnalysis;
-using Backend.Model;
-using Backend.Model.Relations;
-using Backend.Utils;
+using Innovenergy.Backend.Model;
+using Innovenergy.Backend.Model.Relations;
+using Innovenergy.Backend.Utils;
using InnovEnergy.Lib.Utils;
using SQLite;
-namespace Backend.Database;
+namespace Innovenergy.Backend.Database;
public partial class Db : IDisposable
{
@@ -97,6 +97,8 @@ public partial class Db : IDisposable
return direct.Concat(fromFolders);
}
+
+
public IEnumerable GetAllAccessibleFolders(User user)
{
diff --git a/csharp/app/Backend/Database/Fake.cs b/csharp/app/Backend/Database/Fake.cs
index 94325df6d..427c78434 100644
--- a/csharp/app/Backend/Database/Fake.cs
+++ b/csharp/app/Backend/Database/Fake.cs
@@ -1,6 +1,6 @@
-using Backend.Model.Relations;
+using Innovenergy.Backend.Model.Relations;
-namespace Backend.Database;
+namespace Innovenergy.Backend.Database;
public partial class Db
{
diff --git a/csharp/app/Backend/Database/Folder.cs b/csharp/app/Backend/Database/Folder.cs
index f7411e017..34e20f529 100644
--- a/csharp/app/Backend/Database/Folder.cs
+++ b/csharp/app/Backend/Database/Folder.cs
@@ -1,9 +1,9 @@
-using Backend.Model;
-using Backend.Utils;
+using Innovenergy.Backend.Model;
+using Innovenergy.Backend.Utils;
using InnovEnergy.Lib.Utils;
using SQLite;
-namespace Backend.Database;
+namespace Innovenergy.Backend.Database;
public partial class Db
{
@@ -37,6 +37,15 @@ public partial class Db
return Installations.Where(f => f.ParentId == parent.Id);
}
+ public IEnumerable GetChildUsers(User parent)
+ {
+ return Users.Where(f => f.ParentId == parent.Id);
+ }
+
+ public IEnumerable GetDescendantUsers(User parent)
+ {
+ return parent.Traverse(GetChildUsers);
+ }
public Result CreateFolder(Folder folder)
{
diff --git a/csharp/app/Backend/Database/Installation.cs b/csharp/app/Backend/Database/Installation.cs
index 5473892af..a362a39df 100644
--- a/csharp/app/Backend/Database/Installation.cs
+++ b/csharp/app/Backend/Database/Installation.cs
@@ -1,8 +1,8 @@
-using Backend.Model;
-using Backend.Utils;
+using Innovenergy.Backend.Model;
+using Innovenergy.Backend.Utils;
using SQLite;
-namespace Backend.Database;
+namespace Innovenergy.Backend.Database;
public partial class Db
{
diff --git a/csharp/app/Backend/Database/User.cs b/csharp/app/Backend/Database/User.cs
index cda467968..e002c48be 100644
--- a/csharp/app/Backend/Database/User.cs
+++ b/csharp/app/Backend/Database/User.cs
@@ -1,18 +1,16 @@
-using System.Net;
using System.Net.Mail;
using System.Security.Cryptography;
using System.Text;
-using System.Text.Json;
-using Backend.Model;
-using Backend.Utils;
using Flurl.Http;
+using Innovenergy.Backend.Model;
+using Innovenergy.Backend.Utils;
using InnovEnergy.Lib.Utils;
-using Microsoft.AspNetCore.DataProtection;
using SQLite;
+
#pragma warning disable CS0472
#pragma warning disable CS8602
-namespace Backend.Database;
+namespace Innovenergy.Backend.Database;
public partial class Db
{
@@ -22,16 +20,16 @@ public partial class Db
public User? GetUserById(Int64 id)
{
- return Users.FirstOrDefault(u => u.Id == id);
+ return Users.FirstOrDefault(u => u.Id == id);
}
-
+
public Boolean IsParentOfChild(User parent, User child)
{
var parentPointer = child.ParentId;
-
+
if (parent.Id == child.Id)
return true;
-
+
while (parentPointer != null && parentPointer != parent.Id)
{
parentPointer = GetUserById(parentPointer).ParentId;
@@ -46,10 +44,10 @@ public partial class Db
{
if (GetUserByEmail(user.Email) is not null)
return Result.Error("User with that email already exists");
-
+
//Salting and Hashing password
var salt = Crypto.GenerateSalt();
- var hashedPassword = Crypto.ComputeHash(Encoding.UTF8.GetBytes(user.Password),
+ var hashedPassword = Crypto.ComputeHash(Encoding.UTF8.GetBytes(user.Password),
Encoding.UTF8.GetBytes(salt + "innovEnergy"));
user.Salt = salt;
@@ -57,49 +55,51 @@ public partial class Db
return Create(user);
}
-
+
public Object CreateAndSaveUserS3ApiKey(User user)
{
//EXOSCALE API URL
- const String url = "https://api-ch-dk-2.exoscale.com/v2/access-key";
+ const String url = "https://api-ch-dk-2.exoscale.com/v2/access-key";
const String secret = "S2K1okphiCSNK4mzqr4swguFzngWAMb1OoSlZsJa9F0";
const String apiKey = "EXOb98ec9008e3ec16e19d7b593";
var payload = new
- { name = user.Email,
- operations = new List {"getObject", "listBucket"},
- content = new List