import { Router } from "express"; import { GetAccount } from "./account"; import { GetContactInfos } from "./contact"; import { GetJWTByUser } from "./jwt"; import Login from "./login"; import Register from "./register"; import { DeleteToken, GetToken } from "./token"; import TwoFactorRoute from "./twofactor"; const UserRoute: Router = Router(); /** * @api {post} /user/register * @apiName UserRegister * * @apiGroup user * @apiPermission none * * @apiParam {String} mail EMail linked to this Account * @apiParam {String} username The new Username * @apiParam {String} password Password hashed and salted like specification * @apiParam {String} salt The Salt used for password hashing * @apiParam {String} regcode The regcode, that should be used * @apiParam {String} gender Gender can be: "male", "female", "other", "none" * @apiParam {String} name The real name of the User * * @apiSuccess {Boolean} success * * @apiErrorExample {Object} Error-Response: { error: [ { message: "Some Error", field: "username" } ], status: 400 } */ UserRoute.post("/register", Register); /** * @api {post} /user/login?type=:type * @apiName UserLogin * * @apiParam {String} type Type could be either "username" or "password" * * @apiGroup user * @apiPermission none * * @apiParam {String} username Username (either username or uid required) * @apiParam {String} uid (either username or uid required) * @apiParam {String} password Password hashed and salted like specification (only on type password) * @apiParam {Number} time in milliseconds used to hash password. This is used to make passwords "expire" * * @apiSuccess {String} uid On type = "username" * @apiSuccess {String} salt On type = "username" * * @apiSuccess {String} login On type = "password". Login Token * @apiSuccess {String} special On type = "password". Special Token * @apiSuccess {Object[]} tfa Will be set when TwoFactorAuthentication is required * @apiSuccess {String} tfa.id The ID of the TFA Method * @apiSuccess {String} tfa.name The name of the TFA Method * @apiSuccess {String} tfa.type The type of the TFA Method */ UserRoute.post("/login", Login); UserRoute.use("/twofactor", TwoFactorRoute); /** * @api {get} /user/token * @apiName UserGetToken * * @apiGroup user * @apiPermission user * * @apiSuccess {Object[]} token * @apiSuccess {String} token.id The Token ID * @apiSuccess {String} token.special Identifies Special Token * @apiSuccess {String} token.ip IP the token was optained from * @apiSuccess {String} token.browser The Browser the token was optained from (User Agent) * @apiSuccess {Boolean} token.isthis Shows if it is token used by this session */ UserRoute.get("/token", GetToken); /** * @api {delete} /user/token/:id * @apiParam {String} id The id of the token to be deleted * * @apiName UserDeleteToken * * * @apiGroup user * @apiPermission user * * @apiSuccess {Boolean} success */ UserRoute.delete("/token/:id", DeleteToken); /** * @api {delete} /user/account * @apiName UserGetAccount * * @apiGroup user * @apiPermission user * * @apiSuccess {Boolean} success * @apiSuccess {Object[]} user * @apiSuccess {String} user.id User ID * @apiSuccess {String} user.name Full name of the user * @apiSuccess {String} user.username Username of user * @apiSuccess {Date} user.birthday Birthday * @apiSuccess {Number} user.gender Gender of user (none = 0, male = 1, female = 2, other = 3) */ UserRoute.get("/account", GetAccount); /** * @api {delete} /user/account * @apiName UserGetAccount * * @apiGroup user * @apiPermission user * * @apiSuccess {Boolean} success * @apiSuccess {Object} contact * @apiSuccess {Object[]} user.mail EMail addresses * @apiSuccess {Object[]} user.phone Phone numbers */ UserRoute.get("/contact", GetContactInfos); UserRoute.get("/jwt", GetJWTByUser); export default UserRoute;