Compare commits
11 commits
798702f677
...
7fb0408b52
Author | SHA1 | Date | |
---|---|---|---|
7fb0408b52 | |||
2fc73af4f2 | |||
ac8df18e99 | |||
d321a3e088 | |||
cf6167a12f | |||
bdd5fa4081 | |||
66eb81210c | |||
c6393ef4f3 | |||
93b048ed7d | |||
a0d7848109 | |||
abb46f0915 |
6 changed files with 25 additions and 34 deletions
Binary file not shown.
|
@ -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)).
|
||||||
|
|
|
@ -62,12 +62,15 @@ 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.getStartDate() != null){
|
if(!chapter.hasStarted()){
|
||||||
if(LocalDateTime.now().isBefore(chapter.getStartDate().toLocalDateTime())){
|
context.response(423);
|
||||||
context.response(423);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(chapter.getEndDate() != null){
|
if(chapter.getEndDate() != null){
|
||||||
if(LocalDateTime.now().isAfter(chapter.getEndDate().toLocalDateTime())){
|
if(LocalDateTime.now().isAfter(chapter.getEndDate().toLocalDateTime())){
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -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{
|
||||||
|
|
Loading…
Add table
Reference in a new issue