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