Skip to content

Commit

Permalink
remove check_username route
Browse files Browse the repository at this point in the history
  • Loading branch information
jendib committed Apr 3, 2024
1 parent 01d3e74 commit ae2423b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import com.sismics.util.filter.TokenBasedSecurityFilter;
import com.sismics.util.totp.GoogleAuthenticator;
import com.sismics.util.totp.GoogleAuthenticatorKey;
import org.apache.commons.lang3.StringUtils;

import jakarta.json.Json;
import jakarta.json.JsonArrayBuilder;
import jakarta.json.JsonObjectBuilder;
Expand All @@ -40,6 +38,8 @@
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.NewCookie;
import jakarta.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -256,39 +256,6 @@ public Response update(
return Response.ok().entity(response.build()).build();
}

/**
* Checks if a username is available.
* Search only on active accounts.
*
* @api {get} /user/check_username Check username availability
* @apiName GetUserCheckUsername
* @apiGroup User
* @apiParam {String} username Username
* @apiSuccess {String} status Status OK or KO
* @apiPermission none
* @apiVersion 1.5.0
*
* @param username Username to check
* @return Response
*/
@GET
@Path("check_username")
public Response checkUsername(
@QueryParam("username") String username) {
UserDao userDao = new UserDao();
User user = userDao.getActiveByUsername(username);

JsonObjectBuilder response = Json.createObjectBuilder();
if (user != null) {
response.add("status", "ko")
.add("message", "Username already registered");
} else {
response.add("status", "ok");
}

return Response.ok().entity(response.build()).build();
}

/**
* This resource is used to authenticate the user and create a user session.
* The "session" is only used to identify the user, no other data is stored in the session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ public void testUserResource() {
json = response.readEntity(JsonObject.class);
Assert.assertEquals("AlreadyExistingUsername", json.getString("type"));

// Check if a username is free : OK
target().path("/user/check_username").queryParam("username", "carol").request().get(JsonObject.class);

// Check if a username is free : KO
response = target().path("/user/check_username").queryParam("username", "alice").request().get();
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
json = response.readEntity(JsonObject.class);
Assert.assertEquals("ko", json.getString("status"));

// Login alice with extra whitespaces
response = target().path("/user/login").request()
.post(Entity.form(new Form()
Expand Down

0 comments on commit ae2423b

Please sign in to comment.