|
5 | 5 | "encoding/base64"
|
6 | 6 | "encoding/json"
|
7 | 7 | "errors"
|
| 8 | + "github.com/bwmarrin/discordgo" |
8 | 9 | "math/rand"
|
9 | 10 | "net/http"
|
10 | 11 | "net/url"
|
@@ -283,19 +284,33 @@ func (a *App) HandleDiscordCallback(w http.ResponseWriter, r *http.Request) {
|
283 | 284 | // Check if internal or external, based on redirect_uri host
|
284 | 285 | ipAddr := logging.RequestGetRemoteAddress(r)
|
285 | 286 |
|
286 |
| - userIsLongEnoughInServer, err := a.Service.IsUserLongEnoughInServer(ctx, discordUser.ID) |
| 287 | + createdAt, err := discordgo.SnowflakeTimestamp(strconv.FormatInt(discordUser.ID, 10)) |
287 | 288 | if err != nil {
|
288 | 289 | 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)) |
290 | 291 | return
|
291 | 292 | }
|
292 | 293 |
|
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) |
295 | 297 | writeError(ctx, w, perr("access denied", http.StatusForbidden))
|
296 | 298 | return
|
297 | 299 | }
|
298 | 300 |
|
| 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 | + |
299 | 314 | // Logging into FPFSS itself
|
300 | 315 | authToken, err := a.Service.SaveUser(ctx, discordUser, types.AuthScopeAll, "FPFSS", ipAddr)
|
301 | 316 | if err != nil {
|
|
0 commit comments