@@ -263,31 +263,38 @@ final class Tournament(
263
263
fuccess(Redirect (routes.Tournament .home(1 )))
264
264
}
265
265
266
+ private def rateLimitCreation (me : UserModel , password : Option [String ], req : RequestHeader )(
267
+ create : => Fu [Result ]
268
+ ): Fu [Result ] = {
269
+ val cost =
270
+ if (me.hasTitle ||
271
+ env.streamer.liveStreamApi.isStreaming(me.id) ||
272
+ isGranted(_.ManageTournament , me) ||
273
+ password.isDefined) 1
274
+ else 4
275
+ CreateLimitPerUser (me.id, cost = cost) {
276
+ CreateLimitPerIP (HTTPRequest lastRemoteAddress req, cost = cost) {
277
+ create
278
+ }(rateLimited)
279
+ }(rateLimited)
280
+ }
281
+
266
282
def create = AuthBody { implicit ctx => me =>
267
283
NoLameOrBot {
268
284
teamC.teamsIBelongTo(me) flatMap { teams =>
269
285
implicit val req = ctx.body
270
286
negotiate(
271
287
html = forms(me).bindFromRequest.fold(
272
288
err => BadRequest (html.tournament.form(err, me, teams)).fuccess,
273
- setup => {
274
- val cost =
275
- if (me.hasTitle ||
276
- env.streamer.liveStreamApi.isStreaming(me.id) ||
277
- isGranted(_.ManageTournament ) ||
278
- setup.password.isDefined) 1
279
- else 4
280
- CreateLimitPerUser (me.id, cost = cost) {
281
- CreateLimitPerIP (HTTPRequest lastRemoteAddress ctx.req, cost = cost) {
282
- api.createTournament(setup, me, teams, getUserTeamIds) map { tour =>
283
- Redirect {
284
- if (tour.isTeamBattle) routes.Tournament .teamBattleEdit(tour.id)
285
- else routes.Tournament .show(tour.id)
286
- }.flashSuccess
287
- }
288
- }(rateLimited)
289
- }(rateLimited)
290
- }
289
+ setup =>
290
+ rateLimitCreation(me, setup.password, ctx.req) {
291
+ api.createTournament(setup, me, teams, getUserTeamIds) map { tour =>
292
+ Redirect {
293
+ if (tour.isTeamBattle) routes.Tournament .teamBattleEdit(tour.id)
294
+ else routes.Tournament .show(tour.id)
295
+ }.flashSuccess
296
+ }
297
+ }
291
298
),
292
299
api = _ => doApiCreate(me)
293
300
)
@@ -304,21 +311,23 @@ final class Tournament(
304
311
forms(me).bindFromRequest.fold(
305
312
jsonFormErrorDefaultLang,
306
313
setup =>
307
- teamC.teamsIBelongTo(me) flatMap { teams =>
308
- api.createTournament(setup, me, teams, getUserTeamIds) flatMap { tour =>
309
- jsonView(
310
- tour,
311
- none,
312
- none,
313
- getUserTeamIds,
314
- env.team.getTeamName,
315
- none,
316
- none,
317
- partial = false ,
318
- lila.i18n.defaultLang
319
- )
314
+ rateLimitCreation(me, setup.password, req) {
315
+ teamC.teamsIBelongTo(me) flatMap { teams =>
316
+ api.createTournament(setup, me, teams, getUserTeamIds) flatMap { tour =>
317
+ jsonView(
318
+ tour,
319
+ none,
320
+ none,
321
+ getUserTeamIds,
322
+ env.team.getTeamName,
323
+ none,
324
+ none,
325
+ partial = false ,
326
+ lila.i18n.defaultLang
327
+ ) map { Ok (_) }
328
+ }
320
329
}
321
- } map { Ok (_) }
330
+ }
322
331
)
323
332
324
333
def teamBattleEdit (id : String ) = Auth { implicit ctx => me =>
0 commit comments