diff --git a/DatabaseMigrations/1.sql b/DatabaseMigrations/1.sql index 1ab66fbc..94a0283d 100644 --- a/DatabaseMigrations/1.sql +++ b/DatabaseMigrations/1.sql @@ -1,15 +1,15 @@ -create table ProfileCardLocations +create table Locations ( - UserId int not null, - LocationX int not null, - LocationY int not null + Id int not null, + X int not null, + Y int not null ); -create unique index ProfileCardLocations_UserId_uindex +create unique index Locations_UserId_uindex on Locations (Id); alter table Locations - add constraint ProfileCardLocations_pk + add constraint Locations_pk primary key (Id); alter table Users diff --git a/DatabaseMigrations/4.sql b/DatabaseMigrations/4.sql index 070ca7ff..10c7ec2c 100644 --- a/DatabaseMigrations/4.sql +++ b/DatabaseMigrations/4.sql @@ -1,8 +1,5 @@ create table Tokens ( UserId int not null, - MMAuth text not null + UserToken text not null ); - -create unique index Tokens_MMAuth_uindex - on Tokens (MMAuth); diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs index 1aca2991..c5d9ce24 100644 --- a/ProjectLighthouse/Database.cs +++ b/ProjectLighthouse/Database.cs @@ -39,17 +39,13 @@ namespace ProjectLighthouse { // MM_AUTH=psn_name:?:timestamp, potentially a user creation date?:?:user id?:user's IP:?:password? SHA1 // just blindly trust the token for now while we get it working public async Task AuthenticateUser(string mmAuth) { + if(!mmAuth.Contains(':')) return false; + Token token = new() { - MMAuth = mmAuth + UserToken = mmAuth }; - string[] split; - try { - split = mmAuth.Split(":"); - } - catch(ArgumentOutOfRangeException e) { - return false; // Token doesn't contain :, cant be a valid token - } + string[] split = mmAuth.Split(":"); // TODO: don't use psn name to authenticate User user = await this.Users.FirstOrDefaultAsync(u => u.Username == split[0]) @@ -63,7 +59,7 @@ namespace ProjectLighthouse { public async Task IsUserAuthenticated(string mmAuth) => await UserFromMMAuth(mmAuth) != null; public async Task UserFromMMAuth(string mmAuth) { - Token? token = await Tokens.FirstOrDefaultAsync(t => t.MMAuth == mmAuth); + Token? token = await Tokens.FirstOrDefaultAsync(t => t.UserToken == mmAuth); if(token == null) return null; return await Users.FirstOrDefaultAsync(u => u.UserId == token.UserId); } diff --git a/ProjectLighthouse/Types/Token.cs b/ProjectLighthouse/Types/Token.cs index 61455594..961a90eb 100644 --- a/ProjectLighthouse/Types/Token.cs +++ b/ProjectLighthouse/Types/Token.cs @@ -4,6 +4,6 @@ namespace ProjectLighthouse.Types { [Keyless] public class Token { public int UserId { get; set; } - public string MMAuth { get; set; } + public string UserToken { get; set; } } } \ No newline at end of file