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.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{
|
||||||
|
@ -100,7 +101,6 @@ 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) throws Exception{
|
private static void initRoutes(Router<PeerAtUser> router, DatabaseRepository repo, Configuration config){
|
||||||
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.getLogger(), repo)).
|
register(new DynamicLogs(router, repo)).
|
||||||
|
|
||||||
register(new ChapterElement(repo)).
|
register(new ChapterElement(repo)).
|
||||||
register(new ChapterList(repo)).
|
register(new ChapterList(repo)).
|
||||||
|
|
|
@ -62,15 +62,12 @@ public class PuzzleResponse implements Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
Puzzle currentPuzzle = databaseRepo.getPuzzle(received.getPuzzleId());
|
Puzzle currentPuzzle = databaseRepo.getPuzzle(received.getPuzzleId());
|
||||||
if(!currentPuzzle.hasStarted()){
|
|
||||||
context.response(423);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Chapter chapter = this.databaseRepo.getChapter(currentPuzzle);
|
Chapter chapter = this.databaseRepo.getChapter(currentPuzzle);
|
||||||
if(!chapter.hasStarted()){
|
if(chapter.getStartDate() != null){
|
||||||
context.response(423);
|
if(LocalDateTime.now().isBefore(chapter.getStartDate().toLocalDateTime())){
|
||||||
return;
|
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())){
|
||||||
|
|
|
@ -13,25 +13,34 @@ 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(Locker<Context> locker, DatabaseRepository repo){
|
public DynamicLogs(Router<PeerAtUser> router, DatabaseRepository repo){
|
||||||
this.locker = locker;
|
this.router = router;
|
||||||
|
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$", needLogin = true, websocket = true)
|
@Route(path = "^/admin/logs$", 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{
|
||||||
Group group = this.repo.getPlayerGroup(context.<PeerAtUser>getUser().getId(), 1);
|
JsonMap auth = reader.readJson();
|
||||||
if(!group.getName().equalsIgnoreCase("Quarter-Master - Battles PAC x CEI")) return;
|
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();
|
Key key = new Key();
|
||||||
|
|
||||||
|
@ -50,7 +59,9 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,19 +53,20 @@ public class MailConfirmation extends FormResponse {
|
||||||
String initUsersFilesPath,
|
String initUsersFilesPath,
|
||||||
String gitToken,
|
String gitToken,
|
||||||
Map<String, Integer> playersWaiting,
|
Map<String, Integer> playersWaiting,
|
||||||
Mail mail) throws NoSuchAlgorithmException{
|
Mail mail){
|
||||||
|
|
||||||
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")
|
||||||
|
|
|
@ -18,8 +18,8 @@ public abstract class FormResponse implements Response{
|
||||||
this.checker = new HashMap<>();
|
this.checker = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validator(String key, String regex){
|
public void validator(String key, Pattern regex){
|
||||||
this.checker.put(key, Pattern.compile(regex));
|
this.checker.put(key, regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Json> T json(HttpReader reader) throws Exception{
|
public <T extends Json> T json(HttpReader reader) throws Exception{
|
||||||
|
|
Loading…
Add table
Reference in a new issue