Class EmailVerificationService
java.lang.Object
com.codename1.backend.security.mail.EmailVerificationService
- All Implemented Interfaces:
EmailAddressResolver
Proves that an address is a user's, by mailing it a link.
verification.send(username, "ada@example.com", "https://example.com/verify-email");
// ... the link is opened
String username = verification.confirm(token); // null unless it is good
http.emailVerification() adds the address the link opens. An address is
proved once and stays so until send(String, String, String) is called with another one.
The service is an EmailAddressResolver too: it answers a user's proved
address, so a password reset or a sign-in code goes to an address the user
has shown to be theirs.
http.authorizeHttpRequests(a -> a
.requestMatchers("/billing/**").access(verification.verified())
.anyRequest().authenticated());
The mail is plain by default. Name a template to send the application's
own: it is rendered with link, username and minutes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe purpose of the tokens this service gives out.Fields inherited from interface EmailAddressResolver
USERNAME -
Constructor Summary
ConstructorsConstructorDescriptionEmailVerificationService(OneTimeTokenService tokens, MailSender mail, VerifiedEmailRepository repository) -
Method Summary
Modifier and TypeMethodDescriptionThe clock the moment of proof is read from; a test sets its own.Takes the token of a link.The addressusernamehas proved; failing that, the user name where it is an address.voidForgetsusername's address and any link mailed to it.getVerifiedEmail(String username) The addressusernamehas proved, or null.booleanisVerified(String username) Whetherusernamehas proved their address.voidRecordsemailas the addressusernameclaims and mails it a link toconfirmUrlwith atokenparameter added.The subject of the mail.The template the mail is rendered from, such asmail/verify-email, in place of the plain mail.validityMinutes(int validityMinutes) How long a link works; a day unless set.verified()Grants a request to a signed-in user who has proved their address.
-
Field Details
-
PURPOSE
-
-
Constructor Details
-
EmailVerificationService
public EmailVerificationService(OneTimeTokenService tokens, MailSender mail, VerifiedEmailRepository repository)
-
-
Method Details
-
clock
The clock the moment of proof is read from; a test sets its own. -
validityMinutes
How long a link works; a day unless set. -
subject
The subject of the mail. -
template
The template the mail is rendered from, such asmail/verify-email, in place of the plain mail. -
send
Records
emailas the addressusernameclaims and mails it a link toconfirmUrlwith atokenparameter added. Whatever address the user had proved is no longer theirs until this one is.Parameters
confirmUrl: the whole address the link opens,https://example.com/verify-email
Throws
IllegalArgumentException:emailis not an addressIOException: the mail could not be handed over
- Throws:
IOException
-
confirm
-
isVerified
Whetherusernamehas proved their address. -
getVerifiedEmail
-
forget
Forgetsusername's address and any link mailed to it. -
emailFor
The addressusernamehas proved; failing that, the user name where it is an address.- Specified by:
emailForin interfaceEmailAddressResolver
-
verified
Grants a request to a signed-in user who has proved their address.
-