Auth for everything (and everything auth) #6 #35

Merged
philipp merged 39 commits from feature/6-api_auth into dev 2020-12-18 21:53:18 +00:00
Showing only changes of commit 5dc9edfe40 - Show all commits

View File

@ -81,30 +81,6 @@ export class CreateUser {
throw new UsernameOrEmailNeededError(); throw new UsernameOrEmailNeededError();
} }
if (this.group) {
if (!Array.isArray(this.group)) {
this.group = [this.group]
}
const groupIDs: number[] = this.group
let errors = 0
const validateusergroups = async () => {
let foundgroups = []
for (const g of groupIDs) {
const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g });
if (found.length === 0) {
errors++
} else {
foundgroups.push(found[0])
}
}
newUser.groups = foundgroups
}
await validateusergroups()
if (errors !== 0) {
throw new UserGroupNotFoundError();
}
}
newUser.email = this.email newUser.email = this.email
newUser.username = this.username newUser.username = this.username
newUser.firstname = this.firstname newUser.firstname = this.firstname
@ -113,8 +89,34 @@ export class CreateUser {
newUser.uuid = uuid.v4() newUser.uuid = uuid.v4()
newUser.phone = this.phone newUser.phone = this.phone
newUser.password = await argon2.hash(this.password + newUser.uuid); newUser.password = await argon2.hash(this.password + newUser.uuid);
newUser.groups = await this.getGroups();
//TODO: ProfilePics //TODO: ProfilePics
return newUser; return newUser;
} }
public async getGroups() {
if (!this.group) { return null; }
let groups = new Array<UserGroup>();
if (!Array.isArray(this.group)) {
this.group = [this.group]
}
const groupIDs: number[] = this.group
let errors = 0
const validateusergroups = async () => {
for (const g of groupIDs) {
const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g });
if (found.length === 0) {
errors++
} else {
groups.push(found[0])
}
}
return groups;
}
await validateusergroups()
if (errors !== 0) {
throw new UserGroupNotFoundError();
}
}
} }