parent
34c852b12a
commit
c39a59e54e
@ -7,6 +7,7 @@ import { InvalidCredentialsError } from '../errors/AuthError';
|
|||||||
import { RunnerEmailNeededError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
import { RunnerEmailNeededError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||||
import { RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
import { RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
||||||
|
import { JwtCreator } from '../jwtcreator';
|
||||||
import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner';
|
import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner';
|
||||||
import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner';
|
import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner';
|
||||||
import { Runner } from '../models/entities/Runner';
|
import { Runner } from '../models/entities/Runner';
|
||||||
@ -58,7 +59,9 @@ export class RunnerSelfServiceController {
|
|||||||
let runner = await createRunner.toEntity(org);
|
let runner = await createRunner.toEntity(org);
|
||||||
runner = await this.runnerRepository.save(runner);
|
runner = await this.runnerRepository.save(runner);
|
||||||
|
|
||||||
return new ResponseSelfServiceRunner(await this.runnerRepository.findOne(runner, { relations: ['scans', 'group', 'scans.track', 'cards', 'distanceDonations', 'distanceDonations.donor', 'distanceDonations.runner', 'distanceDonations.runner.scans', 'distanceDonations.runner.scans.track'] }));
|
let response = new ResponseSelfServiceRunner(await this.runnerRepository.findOne(runner, { relations: ['scans', 'group', 'scans.track', 'cards', 'distanceDonations', 'distanceDonations.donor', 'distanceDonations.runner', 'distanceDonations.runner.scans', 'distanceDonations.runner.scans.track'] }));
|
||||||
|
response.token = JwtCreator.createSelfService(runner);
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
|
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
|
||||||
import * as jsonwebtoken from "jsonwebtoken";
|
import * as jsonwebtoken from "jsonwebtoken";
|
||||||
import { config } from './config';
|
import { config } from './config';
|
||||||
|
import { Runner } from './models/entities/Runner';
|
||||||
import { User } from './models/entities/User';
|
import { User } from './models/entities/User';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +35,19 @@ export class JwtCreator {
|
|||||||
}, config.jwt_secret)
|
}, config.jwt_secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new selfservice token for a given runner.
|
||||||
|
* @param runner Runner entity that the access token shall be created for.
|
||||||
|
* @param expiry_timestamp Timestamp for the token expiry. Will be set about 9999 years if none provided.
|
||||||
|
*/
|
||||||
|
public static createSelfService(runner: Runner, expiry_timestamp?: number) {
|
||||||
|
if (!expiry_timestamp) { expiry_timestamp = Math.floor(Date.now() / 1000) + 36000 * 60 * 24 * 365 * 9999; }
|
||||||
|
return jsonwebtoken.sign({
|
||||||
|
id: runner.id,
|
||||||
|
exp: expiry_timestamp
|
||||||
|
}, config.jwt_secret)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new password reset token for a given user.
|
* Creates a new password reset token for a given user.
|
||||||
* The token is valid for 15 minutes or 1 use - whatever comes first.
|
* The token is valid for 15 minutes or 1 use - whatever comes first.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { IsInt, IsString } from "class-validator";
|
import { IsInt, IsOptional, IsString } from "class-validator";
|
||||||
import { DistanceDonation } from '../entities/DistanceDonation';
|
import { DistanceDonation } from '../entities/DistanceDonation';
|
||||||
import { Runner } from '../entities/Runner';
|
import { Runner } from '../entities/Runner';
|
||||||
import { RunnerGroup } from '../entities/RunnerGroup';
|
import { RunnerGroup } from '../entities/RunnerGroup';
|
||||||
@ -36,6 +36,14 @@ export class ResponseSelfServiceRunner extends ResponseParticipant {
|
|||||||
@IsString()
|
@IsString()
|
||||||
donations: ResponseSelfServiceDonation[]
|
donations: ResponseSelfServiceDonation[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's self-service jwt for auth.
|
||||||
|
* Will only get delivered on registration/via email.
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
token: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a ResponseRunner object from a runner.
|
* Creates a ResponseRunner object from a runner.
|
||||||
* @param runner The user the response shall be build for.
|
* @param runner The user the response shall be build for.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user