use of io.hops.hopsworks.common.user.QrCode in project hopsworks by logicalclocks.
the class UsersResource method getQRCode.
@POST
@Path("getQRCode")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the logged in User\'s QR code.", response = QrCode.class)
public Response getQRCode(@FormParam("password") String password, @Context HttpServletRequest req, @Context SecurityContext sc) throws UserException {
Users user = jWTHelper.getUserPrincipal(sc);
if (user == null) {
throw new UserException(RESTCodes.UserErrorCode.USER_WAS_NOT_FOUND, Level.FINE);
}
if (password == null || password.isEmpty()) {
throw new IllegalArgumentException("Password was not provided.");
}
QrCode qrCode = userController.getQRCode(user, password);
return Response.ok(qrCode).build();
}
use of io.hops.hopsworks.common.user.QrCode in project hopsworks by logicalclocks.
the class UsersResource method resetTwoFactor.
@POST
@Path("resetTwoFactor")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Reset logged in User\'s two factor setting.", response = QrCode.class)
public Response resetTwoFactor(@FormParam("password") String password, @Context HttpServletRequest req, @Context SecurityContext sc) throws UserException {
Users user = jWTHelper.getUserPrincipal(sc);
QrCode qrCode = userController.resetQRCode(user, password);
return Response.ok(qrCode).build();
}
use of io.hops.hopsworks.common.user.QrCode in project hopsworks by logicalclocks.
the class AuthService method register.
@POST
@Path("register")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTNotRequired
public Response register(UserDTO newUser, @Context HttpServletRequest req) throws UserException {
if (settings.isRegistrationDisabled()) {
throw new UserException(RESTCodes.UserErrorCode.ACCOUNT_REGISTRATION_ERROR, Level.FINE, "Registration not " + "allowed.");
}
RESTApiJsonResponse json = new RESTApiJsonResponse();
String linkUrl = FormatUtils.getUserURL(req) + settings.getEmailVerificationEndpoint();
QrCode qrCode = userController.registerUser(newUser, linkUrl);
if (authController.isTwoFactorEnabled(newUser.isTwoFactor())) {
return Response.ok(qrCode).build();
} else {
json.setSuccessMessage("We registered your account request. Please validate you email and we will " + "review your account within 48 hours.");
}
return Response.ok(json).build();
}
use of io.hops.hopsworks.common.user.QrCode in project hopsworks by logicalclocks.
the class UsersResource method changeTwoFactor.
@POST
@Path("twoFactor")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Updates logged in User\'s two factor setting.")
public Response changeTwoFactor(@FormParam("password") String password, @FormParam("twoFactor") boolean twoFactor, @Context HttpServletRequest req, @Context SecurityContext sc) throws UserException {
Users user = jWTHelper.getUserPrincipal(sc);
RESTApiJsonResponse json = new RESTApiJsonResponse();
if (user.getTwoFactor() == twoFactor) {
json.setSuccessMessage("No change made.");
return Response.ok().entity(json).build();
}
QrCode qrCode = userController.changeTwoFactor(user, password);
if (qrCode != null) {
return Response.ok(qrCode).build();
} else {
json.setSuccessMessage("Two factor authentication disabled.");
}
return Response.ok().entity(json).build();
}
Aggregations