Compare commits
No commits in common. "7fb0408b52990f5adfb698ff5ffd5941f5f5891b" and "798702f677940a7550d1b474f67ef817cb131fbd" have entirely different histories.
7fb0408b52
...
798702f677
6 changed files with 34 additions and 25 deletions
Binary file not shown.
|
@ -42,6 +42,7 @@ import dev.peerat.framework.Response;
|
|||
import dev.peerat.framework.Route;
|
||||
import dev.peerat.framework.Router;
|
||||
import dev.peerat.framework.Locker.Key;
|
||||
import dev.peerat.framework.utils.json.JsonMap;
|
||||
|
||||
public class Main{
|
||||
public static void main(String[] args) throws Exception{
|
||||
|
@ -100,7 +101,6 @@ public class Main{
|
|||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
locker.remove(key);
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
@ -108,7 +108,7 @@ public class Main{
|
|||
router.listen(config.getTcpPort(), config.useSsl());
|
||||
}
|
||||
|
||||
private static void initRoutes(Router<PeerAtUser> router, DatabaseRepository repo, Configuration config) throws Exception{
|
||||
private static void initRoutes(Router<PeerAtUser> router, DatabaseRepository repo, Configuration config){
|
||||
Map<String, Integer> playersWaiting = new HashMap<>();
|
||||
Mail mail = config.getMail();
|
||||
Locker<Group> groupLock = new Locker<>();
|
||||
|
@ -122,7 +122,7 @@ public class Main{
|
|||
register(new ChangePassword(repo)).
|
||||
register(new ForgotPassword(router, repo, mail)).
|
||||
|
||||
register(new DynamicLogs(router.getLogger(), repo)).
|
||||
register(new DynamicLogs(router, repo)).
|
||||
|
||||
register(new ChapterElement(repo)).
|
||||
register(new ChapterList(repo)).
|
||||
|
|
|
@ -62,15 +62,12 @@ public class PuzzleResponse implements Response {
|
|||
}
|
||||
|
||||
Puzzle currentPuzzle = databaseRepo.getPuzzle(received.getPuzzleId());
|
||||
if(!currentPuzzle.hasStarted()){
|
||||
Chapter chapter = this.databaseRepo.getChapter(currentPuzzle);
|
||||
if(chapter.getStartDate() != null){
|
||||
if(LocalDateTime.now().isBefore(chapter.getStartDate().toLocalDateTime())){
|
||||
context.response(423);
|
||||
return;
|
||||
}
|
||||
|
||||
Chapter chapter = this.databaseRepo.getChapter(currentPuzzle);
|
||||
if(!chapter.hasStarted()){
|
||||
context.response(423);
|
||||
return;
|
||||
}
|
||||
if(chapter.getEndDate() != null){
|
||||
if(LocalDateTime.now().isAfter(chapter.getEndDate().toLocalDateTime())){
|
||||
|
|
|
@ -13,25 +13,34 @@ import dev.peerat.framework.Locker;
|
|||
import dev.peerat.framework.Locker.Key;
|
||||
import dev.peerat.framework.Response;
|
||||
import dev.peerat.framework.Route;
|
||||
import dev.peerat.framework.Router;
|
||||
import dev.peerat.framework.utils.json.JsonMap;
|
||||
|
||||
public class DynamicLogs implements Response{
|
||||
|
||||
private Router<PeerAtUser> router;
|
||||
private Locker<Context> locker; //Context
|
||||
private DatabaseRepository repo;
|
||||
|
||||
public DynamicLogs(Locker<Context> locker, DatabaseRepository repo){
|
||||
this.locker = locker;
|
||||
public DynamicLogs(Router<PeerAtUser> router, DatabaseRepository repo){
|
||||
this.router = router;
|
||||
this.locker = router.getLogger();
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
@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")
|
||||
|
||||
@Route(path = "^/admin/logs$", needLogin = true, websocket = true)
|
||||
@Route(path = "^/admin/logs$", websocket = true)
|
||||
public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception{
|
||||
Group group = this.repo.getPlayerGroup(context.<PeerAtUser>getUser().getId(), 1);
|
||||
if(!group.getName().equalsIgnoreCase("Quarter-Master - Battles PAC x CEI")) return;
|
||||
JsonMap auth = reader.readJson();
|
||||
PeerAtUser user = this.router.getUser(auth.get("token"));
|
||||
|
||||
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();
|
||||
|
||||
|
@ -50,7 +59,9 @@ public class DynamicLogs implements Response{
|
|||
writer.write(json.toString());
|
||||
writer.flush();
|
||||
}
|
||||
}catch(Exception e){}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
locker.remove(key);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,19 +53,20 @@ public class MailConfirmation extends FormResponse {
|
|||
String initUsersFilesPath,
|
||||
String gitToken,
|
||||
Map<String, Integer> playersWaiting,
|
||||
Mail mail) throws NoSuchAlgorithmException{
|
||||
|
||||
Mail mail){
|
||||
this.databaseRepo = databaseRepo;
|
||||
this.router = router;
|
||||
this.usersFilesPath = initUsersFilesPath;
|
||||
this.gitToken = gitToken;
|
||||
this.playersWaiting = playersWaiting;
|
||||
this.mail = mail;
|
||||
|
||||
try {
|
||||
generator = KeyPairGenerator.getInstance("RSA");
|
||||
generator.initialize(4096);
|
||||
} catch (NoSuchAlgorithmException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
encoder = Base64.getEncoder();
|
||||
|
||||
}
|
||||
|
||||
@RouteDoc(path = "/confirmation", responseCode = 200, responseDescription = "L'utilisateur est inscrit")
|
||||
|
|
|
@ -18,8 +18,8 @@ public abstract class FormResponse implements Response{
|
|||
this.checker = new HashMap<>();
|
||||
}
|
||||
|
||||
public void validator(String key, String regex){
|
||||
this.checker.put(key, Pattern.compile(regex));
|
||||
public void validator(String key, Pattern regex){
|
||||
this.checker.put(key, regex);
|
||||
}
|
||||
|
||||
public <T extends Json> T json(HttpReader reader) throws Exception{
|
||||
|
|
Loading…
Add table
Reference in a new issue