diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java index 0573c2c3..c6766218 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java @@ -30,6 +30,7 @@ public class User { private long id; @Column(unique = true) public String username; + public String email; @Column(unique = true) public UUID uuid; @Column(name = "password") diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 0e6c98d6..6749d352 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -20,14 +20,7 @@ import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.launchserver.socket.response.admin.AddLogListenerResponse; import pro.gravit.launchserver.socket.response.admin.ExecCommandResponse; -import pro.gravit.launchserver.socket.response.auth.AuthResponse; -import pro.gravit.launchserver.socket.response.auth.CheckServerResponse; -import pro.gravit.launchserver.socket.response.auth.GetAvailabilityAuthResponse; -import pro.gravit.launchserver.socket.response.auth.JoinServerResponse; -import pro.gravit.launchserver.socket.response.auth.ProfilesResponse; -import pro.gravit.launchserver.socket.response.auth.RegisterResponse; -import pro.gravit.launchserver.socket.response.auth.RestoreSessionResponse; -import pro.gravit.launchserver.socket.response.auth.SetProfileResponse; +import pro.gravit.launchserver.socket.response.auth.*; import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUsername; @@ -130,6 +123,7 @@ public static void registerResponses() { providers.register("verifySecureToken", VerifySecureTokenResponse.class); providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class); providers.register("register", RegisterResponse.class); + providers.register("setPassword", SetPasswordResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java index c9ae5f91..1db67efd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java @@ -14,6 +14,7 @@ public class RegisterResponse extends SimpleResponse { public String login; public String password; + public String email; public byte[] verifyHash; @Override public void execute(ChannelHandlerContext ctx, Client client) throws Exception @@ -32,6 +33,7 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception } User user = new User(); user.username = login; + user.email = email; user.setPassword(password); user.uuid = UUID.randomUUID(); server.config.dao.userService.saveUser(user); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java new file mode 100644 index 00000000..93f2fb26 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java @@ -0,0 +1,55 @@ +package pro.gravit.launchserver.socket.response.auth; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.request.SetPasswordRequestEvent; +import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class SetPasswordResponse extends SimpleResponse { + public String oldPassword; + public String newPassword; + public String username; + @Override + public String getType() { + return "setPassword"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + if(( oldPassword == null && username == null ) || newPassword == null) + { + sendError("Request invalid"); + return; + } + if(!client.isAuth) + { + sendError("You not authorized"); + return; + } + if(username != null && !client.permissions.canAdmin) + { + sendError("You not admin"); + return; + } + if(username != null) + { + User user = server.config.dao.userService.findUserByUsername(username); + user.setPassword(newPassword); + sendResult(new SetPasswordRequestEvent()); + } + else + { + User user = server.config.dao.userService.findUserByUsername(client.username); + if(user.verifyPassword(oldPassword)) + { + user.setPassword(newPassword); + sendResult(new SetPasswordRequestEvent()); + } + else + { + sendError("Old password incorrect"); + } + } + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 65f7fde2..a1556111 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -111,13 +111,13 @@ public void start(String... args) throws Throwable { } }; } - LauncherGuardManager.initGuard(false); if(UpdateRequest.getController() == null) UpdateRequest.setController(new LauncherUpdateController()); Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this)); runtimeProvider.preLoad(); + LauncherGuardManager.initGuard(false); FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID); FunctionalBridge.getHWID.start(); LogHelper.debug("Dir: %s", DirBridge.dir); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetPasswordRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetPasswordRequestEvent.java new file mode 100644 index 00000000..96efa2c0 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetPasswordRequestEvent.java @@ -0,0 +1,10 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class SetPasswordRequestEvent extends RequestEvent { + @Override + public String getType() { + return "setPassword"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java index eaab1413..51c8b784 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java @@ -127,8 +127,8 @@ public LauncherModule preInit() * Modify module description, dependencies * Add modules * Read configuration - * @param initContext