-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
246 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
myconext-server/src/main/java/myconext/cron/NudgeAppMail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package myconext.cron; | ||
|
||
import myconext.mail.MailBox; | ||
import myconext.manage.Manage; | ||
import myconext.model.User; | ||
import myconext.repository.UserRepository; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Component | ||
public class NudgeAppMail { | ||
|
||
private static final Log LOG = LogFactory.getLog(NudgeAppMail.class); | ||
|
||
private final MailBox mailBox; | ||
private final UserRepository userRepository; | ||
private final boolean nudgeAppMailFeature; | ||
private final boolean cronJobResponsible; | ||
private final long nudgeAppMailDaysAfterCreation; | ||
|
||
@Autowired | ||
public NudgeAppMail(MailBox mailBox, | ||
UserRepository userRepository, | ||
@Value("${cron.node-cron-job-responsible}") boolean cronJobResponsible, | ||
@Value("${cron.nudge-app-mail-days-after-creation}") long nudgeAppMailDaysAfterCreation, | ||
@Value("${feature.nudge_app_mail}") boolean nudgeAppMailFeature) { | ||
this.mailBox = mailBox; | ||
this.userRepository = userRepository; | ||
this.cronJobResponsible = cronJobResponsible; | ||
this.nudgeAppMailDaysAfterCreation = nudgeAppMailDaysAfterCreation; | ||
this.nudgeAppMailFeature = nudgeAppMailFeature; | ||
} | ||
|
||
@Scheduled(cron = "${cron.nudge-app-mail-expression}") | ||
@SuppressWarnings("unchecked") | ||
public void mailUsersWithoutApp() { | ||
if (!nudgeAppMailFeature || !cronJobResponsible) { | ||
return; | ||
} | ||
long start = System.currentTimeMillis(); | ||
try { | ||
long createdBefore = (new Date().getTime() - (nudgeAppMailDaysAfterCreation * 24 * 60 * 60 * 1000)) / 1000; | ||
List<User> users = userRepository.findByNoEduIDApp(createdBefore); | ||
|
||
users.forEach(user -> { | ||
mailBox.sendNudgeAppMail(user); | ||
user.setNudgeAppMailSend(true); | ||
userRepository.save(user); | ||
}); | ||
|
||
LOG.info(String.format("Mailed %s users to nudge the app in %s ms", | ||
users.size(), System.currentTimeMillis() - start)); | ||
} catch (Exception e) { | ||
LOG.error("Error in mailUsersWithInstitutionMail", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
myconext-server/src/main/resources/mail_templates/institution_mail_warning_en.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Hi {{name}}, | ||
|
||
You have created an eduID with your institutional account. If you're using your institution account, and you have | ||
completed your education, you will lose access to your eduID. While you can use your eduID after graduation. | ||
That's why we recommend that you just use your own email. You can change your email address | ||
in the {{mySurfConextURL}} settings of your eduID account | ||
completed your education, you will lose access to your eduID. While you can use your eduID after graduation. | ||
That's why we recommend that you just use your own email. You can change your email address | ||
in the {{mySurfConextURL}} settings of your eduID account | ||
|
||
{{> footer_en.txt}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
myconext-server/src/main/resources/mail_templates/nudge_eduid_app_en.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{title}}</title> | ||
</head> | ||
<body> | ||
<div class="main" style="font-family: Helvetica, Arial, sans-serif;line-height: 18px;font-size: 14px;color: #353535;"> | ||
<div class="head" style="background-color: #f5f5f5;padding: 30px 0 20px 60px;"> | ||
<p class="title" style="font-weight: 600;font-size: 38px;line-height: 38px; margin: 0;margin-bottom: 10px"> | ||
Install the eduID app</p> | ||
</div> | ||
<div class="middle" style="padding: 20px 0 40px 60px;max-width: 600px;"> | ||
<p>Hi <strong>{{name}}</strong>,</p> | ||
<p>You have created an eduID account, but have not installed the app. It is much more convenient if you install | ||
the app, so you can log in faster. Go to <a href="{{mySurfConextURL}}">{{mySurfConextURL}}</a> to link | ||
your account to your eduID app.</p> | ||
<br/> | ||
<p> | ||
Kind regards, | ||
eduID. | ||
</p> | ||
</div> | ||
{{> footer_nl.html}} | ||
</div> | ||
</body> | ||
</html> |
6 changes: 6 additions & 0 deletions
6
myconext-server/src/main/resources/mail_templates/nudge_eduid_app_en.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Hi {{name}}, | ||
|
||
You have created an eduID account, but have not installed the app. It is much more convenient if you install | ||
the app, so you can log in faster. Go to {{mySurfConextURL}} to link your account to your eduID app. | ||
|
||
{{> footer_en.txt}} |
29 changes: 29 additions & 0 deletions
29
myconext-server/src/main/resources/mail_templates/nudge_eduid_app_nl.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{title}}</title> | ||
</head> | ||
<body> | ||
<div class="main" style="font-family: Helvetica, Arial, sans-serif;line-height: 18px;font-size: 14px;color: #353535;"> | ||
<div class="head" style="background-color: #f5f5f5;padding: 30px 0 20px 60px;"> | ||
<p class="title" style="font-weight: 600;font-size: 38px;line-height: 38px; margin: 0;margin-bottom: 10px">You | ||
have created an eduID with your institutional account</p> | ||
</div> | ||
<div class="middle" style="padding: 20px 0 40px 60px;max-width: 600px;"> | ||
<p>Hi <strong>{{name}}</strong>,</p> | ||
<p> | ||
Je hebt een eduID account aangemaakt maar de app niet geïnstalleerd. Het is super veel handiger als je de | ||
app wel installeert, daarmee kan je sneller inloggen. Ga naar | ||
<a href="{{mySurfConextURL}}">{{mySurfConextURL}}</a> om je account aan je eduID app te koppelen. | ||
|
||
</p> | ||
<br/> | ||
<p> | ||
Kind regards, | ||
eduID. | ||
</p> | ||
</div> | ||
{{> footer_nl.html}} | ||
</div> | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
myconext-server/src/main/resources/mail_templates/nudge_eduid_app_nl.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Hoi {{name}}, | ||
|
||
Je hebt een eduID account aangemaakt maar de app niet geïnstalleerd. Het is super veel handiger als je de app wel | ||
installeert, daarmee kan je sneller inloggen. Ga naar {{mySurfConextURL}} om je account aan je eduID app te koppelen. | ||
|
||
Vriendelijke groetjes, | ||
eduID. | ||
|
||
{{> footer_nl.txt}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
myconext-server/src/test/java/myconext/cron/NudgeAppMailTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package myconext.cron; | ||
|
||
import myconext.AbstractIntegrationTest; | ||
import myconext.AbstractMailBoxTest; | ||
import myconext.model.User; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import javax.mail.internet.MimeMessage; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
properties = { | ||
"mongodb_db=surf_id_test", | ||
"cron.node-cron-job-responsible=true", | ||
"email_guessing_sleep_millis=1", | ||
"sp_entity_id=https://engine.test.surfconext.nl/authentication/sp/metadata", | ||
"sp_entity_metadata_url=https://engine.test.surfconext.nl/authentication/sp/metadata", | ||
"spring.main.lazy-initialization=true", | ||
"eduid_api.oidcng_introspection_uri=http://localhost:8098/introspect", | ||
"cron.service-name-resolver-initial-delay-milliseconds=60000", | ||
"oidc.base-url=http://localhost:8098/", | ||
"sso_mfa_duration_seconds=-1000", | ||
"feature.requires_signed_authn_request=false", | ||
"feature.deny_disposable_email_providers=false", | ||
"verify.base_uri=http://localhost:8098" | ||
}) | ||
public class NudgeAppMailTest extends AbstractMailBoxTest { | ||
|
||
@Autowired | ||
protected NudgeAppMail nudgeAppMail; | ||
|
||
@Test | ||
public void mailUsersWithoutApp() { | ||
nudgeAppMail.mailUsersWithoutApp(); | ||
|
||
List<MimeMessage> mimeMessages = mailMessages(); | ||
|
||
assertEquals(1, mimeMessages.size()); | ||
|
||
User mary = userRepository.findOneUserByEmail("[email protected]"); | ||
assertTrue(mary.isNudgeAppMailSend()); | ||
} | ||
|
||
} |