Fix migrations

This commit is contained in:
jvyden 2021-10-13 18:54:22 -04:00
parent 8aca781675
commit dc2c93647f
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 13 additions and 20 deletions

View file

@ -1,15 +1,15 @@
create table ProfileCardLocations create table Locations
( (
UserId int not null, Id int not null,
LocationX int not null, X int not null,
LocationY int not null Y int not null
); );
create unique index ProfileCardLocations_UserId_uindex create unique index Locations_UserId_uindex
on Locations (Id); on Locations (Id);
alter table Locations alter table Locations
add constraint ProfileCardLocations_pk add constraint Locations_pk
primary key (Id); primary key (Id);
alter table Users alter table Users

View file

@ -1,8 +1,5 @@
create table Tokens create table Tokens
( (
UserId int not null, UserId int not null,
MMAuth text not null UserToken text not null
); );
create unique index Tokens_MMAuth_uindex
on Tokens (MMAuth);

View file

@ -39,17 +39,13 @@ namespace ProjectLighthouse {
// MM_AUTH=psn_name:?:timestamp, potentially a user creation date?:?:user id?:user's IP:?:password? SHA1 // 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 // just blindly trust the token for now while we get it working
public async Task<bool> AuthenticateUser(string mmAuth) { public async Task<bool> AuthenticateUser(string mmAuth) {
if(!mmAuth.Contains(':')) return false;
Token token = new() { Token token = new() {
MMAuth = mmAuth UserToken = mmAuth
}; };
string[] split; string[] split = mmAuth.Split(":");
try {
split = mmAuth.Split(":");
}
catch(ArgumentOutOfRangeException e) {
return false; // Token doesn't contain :, cant be a valid token
}
// TODO: don't use psn name to authenticate // TODO: don't use psn name to authenticate
User user = await this.Users.FirstOrDefaultAsync(u => u.Username == split[0]) User user = await this.Users.FirstOrDefaultAsync(u => u.Username == split[0])
@ -63,7 +59,7 @@ namespace ProjectLighthouse {
public async Task<bool> IsUserAuthenticated(string mmAuth) => await UserFromMMAuth(mmAuth) != null; public async Task<bool> IsUserAuthenticated(string mmAuth) => await UserFromMMAuth(mmAuth) != null;
public async Task<User?> UserFromMMAuth(string mmAuth) { public async Task<User?> 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; if(token == null) return null;
return await Users.FirstOrDefaultAsync(u => u.UserId == token.UserId); return await Users.FirstOrDefaultAsync(u => u.UserId == token.UserId);
} }

View file

@ -4,6 +4,6 @@ namespace ProjectLighthouse.Types {
[Keyless] [Keyless]
public class Token { public class Token {
public int UserId { get; set; } public int UserId { get; set; }
public string MMAuth { get; set; } public string UserToken { get; set; }
} }
} }