package top.quantic.sentry.service;

import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.quantic.sentry.config.SentryProperties;

@Service
public class DiscordService implements InitializingBean {

    private static final Logger log = LoggerFactory.getLogger(DiscordService.class);

    private final UserService userService;
    private final SentryProperties sentryProperties;

    @Autowired
    public DiscordService(UserService userService, SentryProperties sentryProperties) {
        this.userService = userService;
        this.sentryProperties = sentryProperties;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        // avoid leaving the application exposed with default credentials
        userService.changePassword("system", RandomStringUtils.random(10));
        userService.changePassword("anonymousUser", RandomStringUtils.random(10));
        userService.deleteUser("admin");
        userService.deleteUser("user");
        if (sentryProperties.getDiscord().getAdministrators().isEmpty() && userService.getAdminCount() == 0) {
            log.info("No administrators set - Set at least one under 'sentry.discord.administrators' property");
        }
    }

}

@@ -34,59 +34,8 @@
 e;%0A%0A
-import org.apache.commons.lang3.RandomStringUtils;%0A
 impo
@@ -814,259 +814,9 @@
 t() 
-throws Exception %7B%0A        // avoid leaving the application exposed with default credentials%0A        userService.changePassword(%22system%22, RandomStringUtils.random(10));%0A        userService.changePassword(%22anonymousUser%22, RandomStringUtils.random(10));
+%7B
 %0A   
@@ -1026,16 +1026,20 @@
 g.info(%22
+*** 
 No admin
@@ -1058,23 +1058,18 @@
 t - 
-Set at least on
+Define som
 e un
@@ -1126,17 +1126,16 @@
       %7D%0A
+
     %7D%0A
-%0A
 %7D%0A

Remove password changing step