login and signup endpoints complete, some auth framework in place for future
This commit is contained in:
Binary file not shown.
@@ -23,23 +23,66 @@ export class TokenTools extends BaseDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
static async delete(id) {
|
||||
let Auth = BaseDatabase.Auth;
|
||||
|
||||
try {
|
||||
await Auth.destroy({where: {id: id}});
|
||||
return 1;
|
||||
} catch (e) {
|
||||
Logger.error(`An error occured while deleting id ${id}: ${e}`);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static async getTokenByID(id) {
|
||||
let Auth = BaseDatabase.Auth;
|
||||
|
||||
try {
|
||||
let auth = await Auth.findOne({where: {id: id}});
|
||||
if (auth == null) return -1;
|
||||
return auth;
|
||||
} catch (e) {
|
||||
Logger.error(`An error occured while querying for id ${id}: ${e}`);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static async getIDByToken(token) {
|
||||
let Auth = BaseDatabase.Auth;
|
||||
|
||||
try {
|
||||
let auth = await Auth.findOne({where: {token: token}});
|
||||
if (auth == null) return -1;
|
||||
return auth;
|
||||
} catch (e) {
|
||||
Logger.error(`An error occured while querying for token ${token}: ${e}`);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static async getTokenByPassHash(hash) {
|
||||
let Auth = BaseDatabase.Auth;
|
||||
|
||||
try {
|
||||
let auth = await Auth.findOne({where: {passhash: hash}});
|
||||
if (auth == null) return -1;
|
||||
return auth;
|
||||
} catch (e) {
|
||||
Logger.error(`An error occured while querying for hash ${hash}: ${e}`);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static async updateToken(id, newToken) {
|
||||
let Auth = BaseDatabase.Auth;
|
||||
|
||||
try {
|
||||
await Auth.update({token: newToken}, {where: {id: id}});
|
||||
return 1;
|
||||
} catch (e) {
|
||||
Logger.error(`An error occured while updating for id ${id}: ${e}`);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user