E-Mail Verification
A verified e-mail lets the user:
- reset a forgotten password,
- recover a disabled account,
- make their e-mail public,
- log in with the e-mail, when the account was created with a
username.
An e-mail confirmed through signup confirmation is already verified.
Verifying the e-mail
verifyEmail() works in two calls. The user must be signed in.
- Without arguments, it e-mails a verification code to the user.
- With the code, it verifies the e-mail.
import com.skapi.Skapi
import kotlinx.serialization.json.jsonPrimitive
val skapi = Skapi("<Project ID>")
skapi.login("user@example.com", "password")
println(skapi.verifyEmail()) // SUCCESS: Verification code has been sent.
val code = askForCode() // your screen: "Code from the e-mail"
println(skapi.verifyEmail(code)) // SUCCESS: "email" is verified.
println(skapi.user!!["email_verified"]!!.jsonPrimitive.content) // trueimport com.skapi.java.SkapiJava;
SkapiJava skapi = new SkapiJava("<Project ID>");
skapi.login("user@example.com", "password").get();
System.out.println(skapi.verifyEmail().get()); // SUCCESS: Verification code has been sent.
String code = askForCode(); // your screen: "Code from the e-mail"
System.out.println(skapi.verifyEmail(code).get()); // SUCCESS: "email" is verified.
System.out.println(skapi.getUser().get("email_verified")); // trueWhen the e-mail is already verified, verifyEmail() returns SUCCESS: "email" is verified. and sends nothing.
To use one of your project's uploaded templates for the code e-mail, pass its message ID: verifyEmail(template = jsonOf("verification" to "<message_id>")).
Changing the e-mail with updateProfile() makes it unverified again.
Going back to the last verified e-mail
When a user changed their e-mail and has not verified the new one, lastVerifiedEmail() returns their previous verified address. lastVerifiedEmail(revert = true) switches the account back to that address, verified, and returns the updated profile.
println(skapi.lastVerifiedEmail().jsonPrimitive.content) // old@example.com
val user = skapi.lastVerifiedEmail(revert = true).jsonObject
println(user["email"]!!.jsonPrimitive.content) // old@example.comSystem.out.println(skapi.lastVerifiedEmail().get()); // old@example.com
Map<String, Object> user = (Map<String, Object>) skapi.lastVerifiedEmail(true).get();
System.out.println(user.get("email")); // old@example.comWhen the current e-mail is verified, it returns the current e-mail. When there is no earlier verified address, it throws NOT_EXISTS.
