Search in sources :

Example 1 with QrCode

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();
}
Also used : QrCode(io.hops.hopsworks.common.user.QrCode) Users(io.hops.hopsworks.persistence.entity.user.Users) UserException(io.hops.hopsworks.exceptions.UserException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with QrCode

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();
}
Also used : QrCode(io.hops.hopsworks.common.user.QrCode) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with QrCode

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();
}
Also used : QrCode(io.hops.hopsworks.common.user.QrCode) RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) UserException(io.hops.hopsworks.exceptions.UserException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTNotRequired(io.hops.hopsworks.api.filter.JWTNotRequired)

Example 4 with QrCode

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();
}
Also used : QrCode(io.hops.hopsworks.common.user.QrCode) RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

QrCode (io.hops.hopsworks.common.user.QrCode)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Users (io.hops.hopsworks.persistence.entity.user.Users)3 ApiOperation (io.swagger.annotations.ApiOperation)3 RESTApiJsonResponse (io.hops.hopsworks.api.util.RESTApiJsonResponse)2 UserException (io.hops.hopsworks.exceptions.UserException)2 JWTNotRequired (io.hops.hopsworks.api.filter.JWTNotRequired)1 Consumes (javax.ws.rs.Consumes)1