@@ -42,12 +42,12 @@ public AuthModule(final GMCServer srv) {
4242 this .captchaEnabled = Boolean .parseBoolean (this .srv .getConfig ().getProperty ("captcha.enabled" ));
4343 this .registerRoute (HttpMethod .POST , "/auth/register" , this ::handleRegister );
4444 this .registerRoute (HttpMethod .POST , "/auth/login" , this ::handleLogin );
45- this .registerRoute (HttpMethod .POST , "/auth/password-reset" , this ::handlePasswordReset );
45+ this .registerRoute (HttpMethod .POST , "/auth/password-reset" , this ::handlePasswordReset );
4646 this .registerRoute (HttpMethod .POST , "/auth/password-reset/confirm" , this ::handlePasswordResetLink );
4747
4848 this .registerAuthedRoute (HttpMethod .POST , "/auth/mfa" , this ::handleSubmitMfa );
4949 this .registerStrictAuthedRoute (HttpMethod .PUT , "/auth/mfa" , this ::handleActivateMfa );
50- this .registerStrictAuthedRoute (HttpMethod .DELETE , "/auth/mfa" , this ::handleDisableMfa );
50+ this .registerStrictAuthedRoute (HttpMethod .DELETE , "/auth/mfa" , this ::handleDisableMfa );
5151 }
5252
5353 private void handleRegister (final RoutingContext ctx ) {
@@ -97,38 +97,38 @@ private void handleRegister(final RoutingContext ctx) {
9797 final String captchaAnswer = obj .getString ("captchaAnswer" );
9898 final String captchaId = obj .getString ("captchaId" );
9999 this .srv .getWebClient ()
100- .postAbs (this .srv .getConfig ().getProperty ("captcha.url" ) + "/answer" )
101- .as (BodyCodec .jsonObject ())
102- .sendJsonObject (new JsonObject ().put ("answer" , captchaAnswer ).put ("id" , captchaId ))
103- .onSuccess (res -> {
104- final String captchaRes = res .body ().getString ("result" );
105- if ("True" .equals (captchaRes )) {
106- this .handleRegisterLogin (ctx , username , email , password );
107- } else if ("False" .equals (captchaRes )) {
108- this .error (ctx , 400 , "Captcha failed" , new JsonObject ().put ("captchaResponse" , captchaRes ));
109- } else if ("Expired" .equals (captchaRes )) {
110- this .error (ctx , 400 , "Captcha expired" , new JsonObject ().put ("captchaResponse" , captchaRes ));
111- } else {
112- this .log .error ("Received unexpected response from LibreCaptcha: '{}'" , captchaRes );
113- this .error (ctx , 502 , "Received unexpected response from LibreCaptcha" );
114- }
115- })
116- .onFailure (t -> {
117- this .log .info ("Failed to verify captcha" , t );
118- this .error (ctx , 502 , "Failed to verify captcha" );
119- });
100+ .postAbs (this .srv .getConfig ().getProperty ("captcha.url" ) + "/answer" )
101+ .as (BodyCodec .jsonObject ())
102+ .sendJsonObject (new JsonObject ().put ("answer" , captchaAnswer ).put ("id" , captchaId ))
103+ .onSuccess (res -> {
104+ final String captchaRes = res .body ().getString ("result" );
105+ if ("True" .equals (captchaRes )) {
106+ this .handleRegisterLogin (ctx , username , email , password );
107+ } else if ("False" .equals (captchaRes )) {
108+ this .error (ctx , 400 , "Captcha failed" , new JsonObject ().put ("captchaResponse" , captchaRes ));
109+ } else if ("Expired" .equals (captchaRes )) {
110+ this .error (ctx , 400 , "Captcha expired" , new JsonObject ().put ("captchaResponse" , captchaRes ));
111+ } else {
112+ this .log .error ("Received unexpected response from LibreCaptcha: '{}'" , captchaRes );
113+ this .error (ctx , 502 , "Received unexpected response from LibreCaptcha" );
114+ }
115+ })
116+ .onFailure (t -> {
117+ this .log .info ("Failed to verify captcha" , t );
118+ this .error (ctx , 502 , "Failed to verify captcha" );
119+ });
120120 } else {
121121 this .handleRegisterLogin (ctx , username , email , password );
122122 }
123123 }
124124
125125 private void handleRegisterLogin (final RoutingContext ctx , final String username , final String email ,
126- final String password ) {
126+ final String password ) {
127127 this .srv .getAuthenticator ().register (username , email , password ).onSuccess (user -> {
128128 final GenerateTokenAction action = this .srv .getUserManager ().userLogin ().setUser (user );
129129 action .execute ().onSuccess (token -> {
130130 ctx .response ()
131- .end (new JsonObject ().put ("token" , token .toString ()).put ("id" , user .getId ().toString ()).toBuffer ());
131+ .end (new JsonObject ().put ("token" , token .toString ()).put ("id" , user .getId ().toString ()).toBuffer ());
132132 }).onFailure (t -> this .error (ctx , 500 , "Failed to generate token: " + t .getMessage ()));
133133 }).onFailure (t -> {
134134 if (t instanceof IllegalStateException ) {
@@ -159,11 +159,11 @@ private void handleLogin(final RoutingContext ctx) {
159159 final GenerateTokenAction action = this .srv .getUserManager ().userLogin ().setUser (user );
160160 action .execute ().onSuccess (token -> {
161161 ctx .response ()
162- // .setStatusCode(user.isMfa() ? 100 : 200)
163- .end (new JsonObject ().put ("token" , token .toString ())
164- .put ("id" , user .getId ().toString ())
165- .put ("mfa" , user .isMfa ())
166- .toBuffer ());
162+ // .setStatusCode(user.isMfa() ? 100 : 200)
163+ .end (new JsonObject ().put ("token" , token .toString ())
164+ .put ("id" , user .getId ().toString ())
165+ .put ("mfa" , user .isMfa ())
166+ .toBuffer ());
167167 }).onFailure (t -> this .error (ctx , 500 , "Failed to generate token: " + t .getMessage ()));
168168 }).onFailure (t -> this .errorLogin (ctx , t ));
169169 }
@@ -193,7 +193,7 @@ private void handleSubmitMfa(final RoutingContext ctx) {
193193 this .srv .getMfaManager ().verifyCode ().setPass (pass ).setUser (user ).execute ().onSuccess (res -> {
194194 this .srv .getUserManager ().userLogin ().setUser (user ).setMfaPass (true ).execute ().onSuccess (token -> {
195195 ctx .response ()
196- .end (new JsonObject ().put ("token" , token .toString ()).put ("id" , user .getId ().toString ()).toBuffer ());
196+ .end (new JsonObject ().put ("token" , token .toString ()).put ("id" , user .getId ().toString ()).toBuffer ());
197197 }).onFailure (t -> this .errorLogin (ctx , t ));
198198 }).onFailure (t -> {
199199 if (t instanceof AuthenticationException ) {
@@ -225,15 +225,15 @@ private void handleActivateMfa(final RoutingContext ctx) {
225225 return ;
226226 }
227227 action .setPass (pass )
228- .execute ()
229- .onSuccess (res -> ctx .response ().end (new JsonObject ().toBuffer ()))
230- .onFailure (t -> {
231- if (t instanceof AuthenticationException ) {
232- this .error (ctx , 403 , "Invalid code" );
233- } else {
234- this .error (ctx , 500 , "Failed to confirm MFA setup: " + t .getMessage ());
235- }
236- });
228+ .execute ()
229+ .onSuccess (res -> ctx .response ().end (new JsonObject ().toBuffer ()))
230+ .onFailure (t -> {
231+ if (t instanceof AuthenticationException ) {
232+ this .error (ctx , 403 , "Invalid code" );
233+ } else {
234+ this .error (ctx , 500 , "Failed to confirm MFA setup: " + t .getMessage ());
235+ }
236+ });
237237 }
238238 }
239239
@@ -254,18 +254,18 @@ private void handleDisableMfa(final RoutingContext ctx) {
254254 }
255255
256256 this .srv .getMfaManager ()
257- .disableMfa ()
258- .setCode (pass )
259- .setUser (user )
260- .execute ()
261- .onSuccess (v -> this .error (ctx , 200 , "MFA has been disabled" ))
262- .onFailure (t -> {
263- if (t instanceof AuthenticationException ) {
264- this .error (ctx , 403 , "Invaild code" );
265- } else {
266- this .error (ctx , 500 , "Failed to disable MFA: " + t .getMessage ());
267- }
268- });
257+ .disableMfa ()
258+ .setCode (pass )
259+ .setUser (user )
260+ .execute ()
261+ .onSuccess (v -> this .error (ctx , 200 , "MFA has been disabled" ))
262+ .onFailure (t -> {
263+ if (t instanceof AuthenticationException ) {
264+ this .error (ctx , 403 , "Invaild code" );
265+ } else {
266+ this .error (ctx , 500 , "Failed to disable MFA: " + t .getMessage ());
267+ }
268+ });
269269 }
270270
271271 private void handlePasswordReset (final RoutingContext ctx ) {
@@ -303,7 +303,7 @@ private void handlePasswordResetLink(final RoutingContext ctx) {
303303 .find (Filters .eq ("passwordResetToken" , token ))
304304 .first ();
305305
306- if (user == null ) {
306+ if (user == null ) {
307307 this .error (ctx , 400 , "Invalid token" );
308308 return ;
309309 }
0 commit comments