mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Обобщение UserDAO. Команда регистрации и стандартный UserDAO
This commit is contained in:
parent
aced376e5e
commit
e13c5580bc
10 changed files with 91 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
|||
package pro.gravit.launchserver.auth.handler;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.hibernate.User;
|
||||
import pro.gravit.launchserver.dao.User;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.hibernate.User;
|
||||
import pro.gravit.launchserver.dao.User;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package pro.gravit.launchserver.command.dao;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.launchserver.dao.User;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class RegisterCommand extends Command {
|
||||
public RegisterCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return "[login] [password]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "Register new user";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 2);
|
||||
User user = new User();
|
||||
user.username = args[0];
|
||||
user.setPassword(args[1]);
|
||||
user.uuid = UUID.randomUUID();
|
||||
LaunchServer.server.userService.saveUser(user);
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@
|
|||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.dao.LaunchServerDaoFactory;
|
||||
import pro.gravit.launchserver.hibernate.HibernateManager;
|
||||
import pro.gravit.launchserver.hibernate.User;
|
||||
import pro.gravit.launchserver.hibernate.UserDAOImpl;
|
||||
import pro.gravit.launchserver.dao.User;
|
||||
import pro.gravit.launchserver.dao.impl.HibernateUserDAOImpl;
|
||||
import pro.gravit.utils.helper.CommonHelper;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
@ -20,7 +20,7 @@ public class HibernateConfiguratorComponent extends Component {
|
|||
public boolean parallelHibernateInit;
|
||||
@Override
|
||||
public void preInit(LaunchServer launchServer) {
|
||||
LaunchServerDaoFactory.setUserDaoProvider(UserDAOImpl::new);
|
||||
LaunchServerDaoFactory.setUserDaoProvider(HibernateUserDAOImpl::new);
|
||||
Runnable init = () -> {
|
||||
Configuration cfg = new Configuration()
|
||||
.addAnnotatedClass(User.class)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package pro.gravit.launchserver.dao;
|
||||
|
||||
import pro.gravit.launchserver.dao.impl.DefaultUserDAOImpl;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class LaunchServerDaoFactory {
|
||||
private static Supplier<UserDAO> getUserDao;
|
||||
private static Supplier<UserDAO> getUserDao = DefaultUserDAOImpl::new;
|
||||
|
||||
public static void setUserDaoProvider(Supplier<UserDAO> getDao) {
|
||||
LaunchServerDaoFactory.getUserDao = getDao;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package pro.gravit.launchserver.hibernate;
|
||||
package pro.gravit.launchserver.dao;
|
||||
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
|
@ -1,7 +1,5 @@
|
|||
package pro.gravit.launchserver.dao;
|
||||
|
||||
import pro.gravit.launchserver.hibernate.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package pro.gravit.launchserver.dao;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.hibernate.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package pro.gravit.launchserver.dao.impl;
|
||||
|
||||
import pro.gravit.launchserver.dao.User;
|
||||
import pro.gravit.launchserver.dao.UserDAO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DefaultUserDAOImpl implements UserDAO {
|
||||
@Override
|
||||
public User findById(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findByUsername(String username) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findByUUID(UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(User user) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(User user) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(User user) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findAll() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package pro.gravit.launchserver.hibernate;
|
||||
package pro.gravit.launchserver.dao.impl;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import pro.gravit.launchserver.dao.User;
|
||||
import pro.gravit.launchserver.dao.UserDAO;
|
||||
import pro.gravit.launchserver.hibernate.HibernateManager;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
|
@ -11,7 +13,7 @@
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserDAOImpl implements UserDAO {
|
||||
public class HibernateUserDAOImpl implements UserDAO {
|
||||
|
||||
public User findById(int id) {
|
||||
return HibernateManager.sessionFactory.openSession().get(User.class, id);
|
Loading…
Reference in a new issue