diff --git a/csharp/App/Backend/Controllers/Controller.cs b/csharp/App/Backend/Controllers/Controller.cs index 2351d5e92..39aa52ccb 100644 --- a/csharp/App/Backend/Controllers/Controller.cs +++ b/csharp/App/Backend/Controllers/Controller.cs @@ -1,5 +1,6 @@ using System.Net; using System.Text; +using System.Web.Http; using InnovEnergy.App.Backend.Database; using InnovEnergy.App.Backend.Model; using InnovEnergy.App.Backend.Model.Relations; @@ -10,39 +11,38 @@ using HttpContextAccessor = Microsoft.AspNetCore.Http.HttpContextAccessor; namespace InnovEnergy.App.Backend.Controllers; [ApiController] -[Route("api/")] +[Microsoft.AspNetCore.Mvc.Route("api/")] public class Controller { [Returns] [Returns(HttpStatusCode.Unauthorized)] [Returns(HttpStatusCode.BadRequest)] - [HttpPost($"{nameof(Login)}")] + [Microsoft.AspNetCore.Mvc.HttpPost($"{nameof(Login)}")] public Object Login(Credentials credentials) { if (String.IsNullOrWhiteSpace(credentials.Username) || String.IsNullOrWhiteSpace(credentials.Password)) - return new HttpResponseMessage(HttpStatusCode.BadRequest); - + return new HttpResponseException(HttpStatusCode.BadRequest); + using var db = Db.Connect(); var user = db.GetUserByEmail(credentials.Username); - - if (user is null) - return new HttpResponseMessage(HttpStatusCode.Unauthorized); - #if !DEBUG + + if (user is null) + return new HttpResponseException(HttpStatusCode.BadRequest); + if (!VerifyPassword(credentials.Password, user)) - return new HttpResponseMessage(HttpStatusCode.Unauthorized); - #endif - + return new HttpResponseException(HttpStatusCode.Unauthorized); + var ses = new Session(user); db.NewSession(ses); - return ses.Token; + return new {ses.Token, user.Language}; } [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpPost($"{nameof(Logout)}")] + [Microsoft.AspNetCore.Mvc.HttpPost($"{nameof(Logout)}")] public Object Logout() { var caller = GetCaller(); @@ -57,7 +57,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpGet($"{nameof(GetInstallationS3Key)}")] + [Microsoft.AspNetCore.Mvc.HttpGet($"{nameof(GetInstallationS3Key)}")] public Object GetInstallationS3Key(Int64 installationId) { var caller = GetCaller(); @@ -82,7 +82,7 @@ public class Controller [Returns] [Returns(HttpStatusCode.Unauthorized)] - [HttpGet($"{nameof(GetUserById)}")] + [Microsoft.AspNetCore.Mvc.HttpGet($"{nameof(GetUserById)}")] public Object GetUserById(Int64 id) { var caller = GetCaller(); @@ -101,7 +101,7 @@ public class Controller [Returns] [Returns(HttpStatusCode.Unauthorized)] - [HttpGet($"{nameof(GetInstallationById)}")] + [Microsoft.AspNetCore.Mvc.HttpGet($"{nameof(GetInstallationById)}")] public Object GetInstallationById(Int64 id) { var caller = GetCaller(); @@ -120,7 +120,7 @@ public class Controller [Returns] [Returns(HttpStatusCode.Unauthorized)] - [HttpGet($"{nameof(GetFolderById)}")] + [Microsoft.AspNetCore.Mvc.HttpGet($"{nameof(GetFolderById)}")] public Object GetFolderById(Int64 id) { var caller = GetCaller(); @@ -139,7 +139,7 @@ public class Controller [Returns] // assuming swagger knows about arrays but not lists (JSON) [Returns(HttpStatusCode.Unauthorized)] - [HttpGet($"{nameof(GetAllInstallations)}/")] + [Microsoft.AspNetCore.Mvc.HttpGet($"{nameof(GetAllInstallations)}/")] public Object GetAllInstallations() { var caller = GetCaller(); @@ -156,7 +156,7 @@ public class Controller [Returns] // assuming swagger knows about arrays but not lists (JSON) [Returns(HttpStatusCode.Unauthorized)] - [HttpGet($"{nameof(GetAllFolders)}/")] + [Microsoft.AspNetCore.Mvc.HttpGet($"{nameof(GetAllFolders)}/")] public Object GetAllFolders() { var caller = GetCaller(); @@ -171,7 +171,7 @@ public class Controller [Returns] // assuming swagger knows about arrays but not lists (JSON) [Returns(HttpStatusCode.Unauthorized)] - [HttpGet($"{nameof(GetTree)}/")] + [Microsoft.AspNetCore.Mvc.HttpGet($"{nameof(GetTree)}/")] public Object GetTree() { var caller = GetCaller(); @@ -193,7 +193,7 @@ public class Controller [Returns] // assuming swagger knows about arrays but not lists (JSON) [Returns(HttpStatusCode.Unauthorized)] - [HttpGet($"{nameof(GetAllFoldersAndInstallations)}/")] + [Microsoft.AspNetCore.Mvc.HttpGet($"{nameof(GetAllFoldersAndInstallations)}/")] public Object GetAllFoldersAndInstallations() { var caller = GetCaller(); @@ -229,7 +229,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpPost($"{nameof(CreateUser)}/")] + [Microsoft.AspNetCore.Mvc.HttpPost($"{nameof(CreateUser)}/")] public Object CreateUser(User newUser) { var caller = GetCaller(); @@ -244,7 +244,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpPost($"{nameof(CreateInstallation)}/")] + [Microsoft.AspNetCore.Mvc.HttpPost($"{nameof(CreateInstallation)}/")] public Object CreateInstallation(Installation installation) { var caller = GetCaller(); @@ -260,7 +260,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpPost($"{nameof(CreateFolder)}/")] + [Microsoft.AspNetCore.Mvc.HttpPost($"{nameof(CreateFolder)}/")] public Object CreateFolder(Folder folder) { var caller = GetCaller(); @@ -275,7 +275,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpPut($"{nameof(UpdateUser)}/")] + [Microsoft.AspNetCore.Mvc.HttpPut($"{nameof(UpdateUser)}/")] public Object UpdateUser(User updatedUser) { var caller = GetCaller(); @@ -289,7 +289,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpPut($"{nameof(UpdateInstallation)}/")] + [Microsoft.AspNetCore.Mvc.HttpPut($"{nameof(UpdateInstallation)}/")] public Object UpdateInstallation(Installation installation) { var caller = GetCaller(); @@ -321,7 +321,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpPut($"{nameof(UpdateFolder)}/")] + [Microsoft.AspNetCore.Mvc.HttpPut($"{nameof(UpdateFolder)}/")] public Object UpdateFolder(Folder folder) { var caller = GetCaller(); @@ -353,7 +353,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpDelete($"{nameof(DeleteUser)}/")] + [Microsoft.AspNetCore.Mvc.HttpDelete($"{nameof(DeleteUser)}/")] public Object DeleteUser(Int64 userId) { var caller = GetCaller(); @@ -375,7 +375,7 @@ public class Controller [Returns(HttpStatusCode.OK)] [Returns(HttpStatusCode.Unauthorized)] - [HttpDelete($"{nameof(DeleteInstallation)}/")] + [Microsoft.AspNetCore.Mvc.HttpDelete($"{nameof(DeleteInstallation)}/")] public Object DeleteInstallation(Int64 installationId) { var caller = GetCaller(); @@ -398,7 +398,7 @@ public class Controller [ProducesResponseType(200)] [ProducesResponseType(401)] - [HttpDelete($"{nameof(DeleteFolder)}/")] + [Microsoft.AspNetCore.Mvc.HttpDelete($"{nameof(DeleteFolder)}/")] public Object DeleteFolder(Int64 folderId) { var caller = GetCaller(); diff --git a/csharp/App/Backend/Model/User.cs b/csharp/App/Backend/Model/User.cs index a6fd45c61..6e4e248ad 100644 --- a/csharp/App/Backend/Model/User.cs +++ b/csharp/App/Backend/Model/User.cs @@ -8,6 +8,7 @@ public class User : TreeNode public String Email { get; set; } = null!; public Boolean HasWriteAccess { get; set; } = false; public String Salt { get; set; } = null!; + public String Language { get; set; } = null!; public String Password { get; set; } = null!; // TODO: must reset pwd diff --git a/csharp/App/Backend/db.sqlite b/csharp/App/Backend/db.sqlite index 6b0d2d492..1d3664c4c 100644 Binary files a/csharp/App/Backend/db.sqlite and b/csharp/App/Backend/db.sqlite differ