Compare commits

..

11 commits

6 changed files with 25 additions and 34 deletions

Binary file not shown.

View file

@ -42,7 +42,6 @@ import dev.peerat.framework.Response;
import dev.peerat.framework.Route; import dev.peerat.framework.Route;
import dev.peerat.framework.Router; import dev.peerat.framework.Router;
import dev.peerat.framework.Locker.Key; import dev.peerat.framework.Locker.Key;
import dev.peerat.framework.utils.json.JsonMap;
public class Main{ public class Main{
public static void main(String[] args) throws Exception{ public static void main(String[] args) throws Exception{
@ -101,6 +100,7 @@ public class Main{
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }
locker.remove(key);
} }
}).start(); }).start();
@ -108,7 +108,7 @@ public class Main{
router.listen(config.getTcpPort(), config.useSsl()); router.listen(config.getTcpPort(), config.useSsl());
} }
private static void initRoutes(Router<PeerAtUser> router, DatabaseRepository repo, Configuration config){ private static void initRoutes(Router<PeerAtUser> router, DatabaseRepository repo, Configuration config) throws Exception{
Map<String, Integer> playersWaiting = new HashMap<>(); Map<String, Integer> playersWaiting = new HashMap<>();
Mail mail = config.getMail(); Mail mail = config.getMail();
Locker<Group> groupLock = new Locker<>(); Locker<Group> groupLock = new Locker<>();
@ -122,7 +122,7 @@ public class Main{
register(new ChangePassword(repo)). register(new ChangePassword(repo)).
register(new ForgotPassword(router, repo, mail)). register(new ForgotPassword(router, repo, mail)).
register(new DynamicLogs(router, repo)). register(new DynamicLogs(router.getLogger(), repo)).
register(new ChapterElement(repo)). register(new ChapterElement(repo)).
register(new ChapterList(repo)). register(new ChapterList(repo)).

View file

@ -62,12 +62,15 @@ public class PuzzleResponse implements Response {
} }
Puzzle currentPuzzle = databaseRepo.getPuzzle(received.getPuzzleId()); Puzzle currentPuzzle = databaseRepo.getPuzzle(received.getPuzzleId());
Chapter chapter = this.databaseRepo.getChapter(currentPuzzle); if(!currentPuzzle.hasStarted()){
if(chapter.getStartDate() != null){
if(LocalDateTime.now().isBefore(chapter.getStartDate().toLocalDateTime())){
context.response(423); context.response(423);
return; return;
} }
Chapter chapter = this.databaseRepo.getChapter(currentPuzzle);
if(!chapter.hasStarted()){
context.response(423);
return;
} }
if(chapter.getEndDate() != null){ if(chapter.getEndDate() != null){
if(LocalDateTime.now().isAfter(chapter.getEndDate().toLocalDateTime())){ if(LocalDateTime.now().isAfter(chapter.getEndDate().toLocalDateTime())){

View file

@ -13,34 +13,25 @@ import dev.peerat.framework.Locker;
import dev.peerat.framework.Locker.Key; import dev.peerat.framework.Locker.Key;
import dev.peerat.framework.Response; import dev.peerat.framework.Response;
import dev.peerat.framework.Route; import dev.peerat.framework.Route;
import dev.peerat.framework.Router;
import dev.peerat.framework.utils.json.JsonMap; import dev.peerat.framework.utils.json.JsonMap;
public class DynamicLogs implements Response{ public class DynamicLogs implements Response{
private Router<PeerAtUser> router;
private Locker<Context> locker; //Context private Locker<Context> locker; //Context
private DatabaseRepository repo; private DatabaseRepository repo;
public DynamicLogs(Router<PeerAtUser> router, DatabaseRepository repo){ public DynamicLogs(Locker<Context> locker, DatabaseRepository repo){
this.router = router; this.locker = locker;
this.locker = router.getLogger();
this.repo = repo; this.repo = repo;
} }
@RouteDoc(path = "/admin/logs", responseCode = 200, responseDescription = "L'utilisateur peux voir les logs en directe") @RouteDoc(path = "/admin/logs", responseCode = 200, responseDescription = "L'utilisateur peux voir les logs en directe")
@RouteDoc(responseCode = 401, responseDescription = "L'utilisateur n'a pas accès à cette ressource") @RouteDoc(responseCode = 401, responseDescription = "L'utilisateur n'a pas accès à cette ressource")
@Route(path = "^/admin/logs$", websocket = true) @Route(path = "^/admin/logs$", needLogin = true, websocket = true)
public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception{ public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception{
JsonMap auth = reader.readJson(); Group group = this.repo.getPlayerGroup(context.<PeerAtUser>getUser().getId(), 1);
PeerAtUser user = this.router.getUser(auth.get("token")); if(!group.getName().equalsIgnoreCase("Quarter-Master - Battles PAC x CEI")) return;
Group group = this.repo.getPlayerGroup(user.getId(), 1);
if(!group.getName().equalsIgnoreCase("Quarter-Master - Battles PAC x CEI")){
context.response(423);
return;
}
Key key = new Key(); Key key = new Key();
@ -59,9 +50,7 @@ public class DynamicLogs implements Response{
writer.write(json.toString()); writer.write(json.toString());
writer.flush(); writer.flush();
} }
}catch(Exception e){ }catch(Exception e){}
e.printStackTrace();
}
locker.remove(key); locker.remove(key);
} }

View file

@ -53,20 +53,19 @@ public class MailConfirmation extends FormResponse {
String initUsersFilesPath, String initUsersFilesPath,
String gitToken, String gitToken,
Map<String, Integer> playersWaiting, Map<String, Integer> playersWaiting,
Mail mail){ Mail mail) throws NoSuchAlgorithmException{
this.databaseRepo = databaseRepo; this.databaseRepo = databaseRepo;
this.router = router; this.router = router;
this.usersFilesPath = initUsersFilesPath; this.usersFilesPath = initUsersFilesPath;
this.gitToken = gitToken; this.gitToken = gitToken;
this.playersWaiting = playersWaiting; this.playersWaiting = playersWaiting;
this.mail = mail; this.mail = mail;
try {
generator = KeyPairGenerator.getInstance("RSA"); generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(4096); generator.initialize(4096);
} catch (NoSuchAlgorithmException e){
e.printStackTrace();
}
encoder = Base64.getEncoder(); encoder = Base64.getEncoder();
} }
@RouteDoc(path = "/confirmation", responseCode = 200, responseDescription = "L'utilisateur est inscrit") @RouteDoc(path = "/confirmation", responseCode = 200, responseDescription = "L'utilisateur est inscrit")

View file

@ -18,8 +18,8 @@ public abstract class FormResponse implements Response{
this.checker = new HashMap<>(); this.checker = new HashMap<>();
} }
public void validator(String key, Pattern regex){ public void validator(String key, String regex){
this.checker.put(key, regex); this.checker.put(key, Pattern.compile(regex));
} }
public <T extends Json> T json(HttpReader reader) throws Exception{ public <T extends Json> T json(HttpReader reader) throws Exception{