Skip to content

Commit 227cfb2

Browse files
committed
add age check on login
1 parent ace3b1b commit 227cfb2

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

transport/auth.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"encoding/json"
77
"errors"
8+
"github.com/bwmarrin/discordgo"
89
"math/rand"
910
"net/http"
1011
"net/url"
@@ -283,19 +284,33 @@ func (a *App) HandleDiscordCallback(w http.ResponseWriter, r *http.Request) {
283284
// Check if internal or external, based on redirect_uri host
284285
ipAddr := logging.RequestGetRemoteAddress(r)
285286

286-
userIsLongEnoughInServer, err := a.Service.IsUserLongEnoughInServer(ctx, discordUser.ID)
287+
createdAt, err := discordgo.SnowflakeTimestamp(strconv.FormatInt(discordUser.ID, 10))
287288
if err != nil {
288289
utils.LogCtx(ctx).Error(err)
289-
writeError(ctx, w, perr("discord check failed", http.StatusInternalServerError))
290+
writeError(ctx, w, perr("user ID error", http.StatusInternalServerError))
290291
return
291292
}
292293

293-
if !userIsLongEnoughInServer {
294-
utils.LogCtx(ctx).Warnf("user %d forbidden from logging in, not long enough in server", discordUser.ID)
294+
ageThreshold := time.Now().Add(-time.Hour * 24 * 30)
295+
if !createdAt.Before(ageThreshold) {
296+
utils.LogCtx(ctx).Warnf("user %d forbidden from logging in, account not old enough", discordUser.ID)
295297
writeError(ctx, w, perr("access denied", http.StatusForbidden))
296298
return
297299
}
298300

301+
//userIsLongEnoughInServer, err := a.Service.IsUserLongEnoughInServer(ctx, discordUser.ID)
302+
//if err != nil {
303+
// utils.LogCtx(ctx).Error(err)
304+
// writeError(ctx, w, perr("discord check failed", http.StatusInternalServerError))
305+
// return
306+
//}
307+
//
308+
//if !userIsLongEnoughInServer {
309+
// utils.LogCtx(ctx).Warnf("user %d forbidden from logging in, not long enough in server", discordUser.ID)
310+
// writeError(ctx, w, perr("access denied", http.StatusForbidden))
311+
// return
312+
//}
313+
299314
// Logging into FPFSS itself
300315
authToken, err := a.Service.SaveUser(ctx, discordUser, types.AuthScopeAll, "FPFSS", ipAddr)
301316
if err != nil {

0 commit comments

Comments
 (0)