Skip to content

Commit

Permalink
Applied correct database query casing (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-j-green authored Nov 25, 2023
1 parent 401a354 commit 006f337
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
4 changes: 2 additions & 2 deletions gaseous-server/Classes/Auth/Classes/UserTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public int Update(TUser user)

private SecurityProfileViewModel GetSecurityProfile(TUser user)
{
string sql = "SELECT SecurityProfile FROM users WHERE Id=@Id;";
string sql = "SELECT SecurityProfile FROM Users WHERE Id=@Id;";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("Id", user.Id);

Expand All @@ -360,7 +360,7 @@ private SecurityProfileViewModel GetSecurityProfile(TUser user)

private int SetSecurityProfile(TUser user, SecurityProfileViewModel securityProfile)
{
string commandText = "UPDATE users SET SecurityProfile=@SecurityProfile WHERE Id=@Id;";
string commandText = "UPDATE Users SET SecurityProfile=@SecurityProfile WHERE Id=@Id;";
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("Id", user.Id);
parameters.Add("SecurityProfile", Newtonsoft.Json.JsonConvert.SerializeObject(securityProfile));
Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Controllers/V1.1/FirstSetupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task<ActionResult> CreateAdminAccount(Authentication.RegisterViewMo
}
}

return NotFound();
return Problem(ModelState.ToString());
}
else
{
Expand Down
43 changes: 23 additions & 20 deletions gaseous-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@
options.Cookie.Name = "Gaseous.Identity";
options.ExpireTimeSpan = TimeSpan.FromDays(90);
options.SlidingExpiration = true;
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.Cookie.SameSite = SameSiteMode.Strict;
});
// builder.Services.AddIdentityCore<ApplicationUser>(options => {
// options.SignIn.RequireConfirmedAccount = false;
Expand Down Expand Up @@ -285,26 +288,26 @@
}
}

// set up administrator account
var userManager = scope.ServiceProvider.GetRequiredService<UserStore>();
if (await userManager.FindByNameAsync("admin@localhost", CancellationToken.None) == null)
{
ApplicationUser adminUser = new ApplicationUser{
Id = Guid.NewGuid().ToString(),
Email = "admin@localhost",
NormalizedEmail = "ADMIN@LOCALHOST",
EmailConfirmed = true,
UserName = "administrator",
NormalizedUserName = "ADMINISTRATOR"
};

//set user password
PasswordHasher<ApplicationUser> ph = new PasswordHasher<ApplicationUser>();
adminUser.PasswordHash = ph.HashPassword(adminUser, "letmein");

await userManager.CreateAsync(adminUser, CancellationToken.None);
await userManager.AddToRoleAsync(adminUser, "Admin", CancellationToken.None);
}
// // set up administrator account
// var userManager = scope.ServiceProvider.GetRequiredService<UserStore>();
// if (await userManager.FindByNameAsync("admin@localhost", CancellationToken.None) == null)
// {
// ApplicationUser adminUser = new ApplicationUser{
// Id = Guid.NewGuid().ToString(),
// Email = "admin@localhost",
// NormalizedEmail = "ADMIN@LOCALHOST",
// EmailConfirmed = true,
// UserName = "administrator",
// NormalizedUserName = "ADMINISTRATOR"
// };

// //set user password
// PasswordHasher<ApplicationUser> ph = new PasswordHasher<ApplicationUser>();
// adminUser.PasswordHash = ph.HashPassword(adminUser, "letmein");

// await userManager.CreateAsync(adminUser, CancellationToken.None);
// await userManager.AddToRoleAsync(adminUser, "Admin", CancellationToken.None);
// }
}

app.UseAuthorization();
Expand Down
7 changes: 7 additions & 0 deletions gaseous-server/Support/Database/MySQL/gaseous-1004.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ CREATE TABLE `GameLibraries` (
ALTER TABLE `Games_Roms`
ADD COLUMN `LibraryId` INT NULL DEFAULT 0 AFTER `MetadataVersion`;

CREATE TABLE `Relation_Game_AgeRatings` (
`GameId` BIGINT NOT NULL,
`AgeRatingsId` BIGINT NOT NULL,
PRIMARY KEY (`GameId`, `AgeRatingsId`),
INDEX `idx_PrimaryColumn` (`GameId` ASC) VISIBLE
);

CREATE TABLE `Relation_Game_Genres` (
`GameId` BIGINT NOT NULL,
`GenresId` BIGINT NOT NULL,
Expand Down
18 changes: 9 additions & 9 deletions gaseous-server/Support/Database/MySQL/gaseous-1005.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE TABLE `roles` (
CREATE TABLE `Roles` (
`Id` varchar(128) NOT NULL,
`Name` varchar(256) NOT NULL,
PRIMARY KEY (`Id`)
);

CREATE TABLE `users` (
CREATE TABLE `Users` (
`Id` varchar(128) NOT NULL,
`Email` varchar(256) DEFAULT NULL,
`EmailConfirmed` tinyint(1) NOT NULL,
Expand All @@ -24,31 +24,31 @@ CREATE TABLE `users` (
PRIMARY KEY (`Id`)
);

CREATE TABLE `userclaims` (
CREATE TABLE `UserClaims` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`UserId` varchar(128) NOT NULL,
`ClaimType` longtext,
`ClaimValue` longtext,
PRIMARY KEY (`Id`),
UNIQUE KEY `Id` (`Id`),
KEY `UserId` (`UserId`),
CONSTRAINT `ApplicationUser_Claims` FOREIGN KEY (`UserId`) REFERENCES `users` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
CONSTRAINT `ApplicationUser_Claims` FOREIGN KEY (`UserId`) REFERENCES `Users` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
);

CREATE TABLE `userlogins` (
CREATE TABLE `UserLogins` (
`LoginProvider` varchar(128) NOT NULL,
`ProviderKey` varchar(128) NOT NULL,
`UserId` varchar(128) NOT NULL,
PRIMARY KEY (`LoginProvider`,`ProviderKey`,`UserId`),
KEY `ApplicationUser_Logins` (`UserId`),
CONSTRAINT `ApplicationUser_Logins` FOREIGN KEY (`UserId`) REFERENCES `users` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
CONSTRAINT `ApplicationUser_Logins` FOREIGN KEY (`UserId`) REFERENCES `Users` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
);

CREATE TABLE `userroles` (
CREATE TABLE `UserRoles` (
`UserId` varchar(128) NOT NULL,
`RoleId` varchar(128) NOT NULL,
PRIMARY KEY (`UserId`,`RoleId`),
KEY `IdentityRole_Users` (`RoleId`),
CONSTRAINT `ApplicationUser_Roles` FOREIGN KEY (`UserId`) REFERENCES `users` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT `IdentityRole_Users` FOREIGN KEY (`RoleId`) REFERENCES `roles` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
CONSTRAINT `ApplicationUser_Roles` FOREIGN KEY (`UserId`) REFERENCES `Users` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT `IdentityRole_Users` FOREIGN KEY (`RoleId`) REFERENCES `Roles` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ;

0 comments on commit 006f337

Please sign in to comment.