Interface EmailCodeRepository

All Known Implementing Classes:
InMemoryEmailCodeRepository, JdbcEmailCodeRepository

public interface EmailCodeRepository
Where EmailCodeService keeps who signs in with a mailed code, and the hash of the code each is waiting to enter.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    clear(String username, String codeHash, boolean signedIn)
    Uses the waiting code up, if it is still the one with codeHash.
    boolean
    countAttempt(String username, int max)
    Counts one attempt against the waiting code.
    find(String username)
    What is held for username, or null.
    boolean
    saveCode(String username, String codeHash, long expiresAt, long sentAt, long sentBefore, int max)
    Keeps a new code for username in place of the one waiting, when the user signs in with a mailed code and the last was sent at or before sentBefore -- or after sentAt, which is a clock that was set back.
    void
    setEnabled(String username, boolean enabled)
    Turns the mailed code on or off for username.
  • Method Details

    • find

      EmailCode find(String username)
      What is held for username, or null.
    • setEnabled

      void setEnabled(String username, boolean enabled)
      Turns the mailed code on or off for username. Turning it off drops any code that is waiting.
    • saveCode

      boolean saveCode(String username, String codeHash, long expiresAt, long sentAt, long sentBefore, int max)

      Keeps a new code for username in place of the one waiting, when the user signs in with a mailed code and the last was sent at or before sentBefore -- or after sentAt, which is a clock that was set back. Of several callers at once one is answered true, so one mail leaves.

      The attempts counted against the code it replaces are counted against this one too, unless that code had run out or been used: asking for another is not a way to more tries. And a code with max attempts counted is not replaced before it runs out, so the wait that follows them ends at a moment that asking again does not move.

    • countAttempt

      boolean countAttempt(String username, int max)
      Counts one attempt against the waiting code. False when max have been counted already; of several callers at once, no more than max are answered true.
    • clear

      boolean clear(String username, String codeHash, boolean signedIn)
      Uses the waiting code up, if it is still the one with codeHash. Of two callers with the same code, one is answered true. signedIn says the code was typed in and accepted, which also forgets when it was sent: the next sign-in is then mailed a code at once. A code cleared because its mail failed keeps the time, so a failing send is still spaced out.