Interface CredentialApi


public interface CredentialApi
CredentialApi contains all the api operations for handling Credential of the DzidziApp.

The credential api is the most important of the DzidziApp. This api is used to create the necessary users in the DzidziApp.

  • Method Details

    • findUserCredentialById

      Credential findUserCredentialById(UUID credentialId)
      Finds the user credential by id.
      Parameters:
      credentialId - the id of the user credential
      Returns:
      the credential found
      Throws:
      com.dzidzi.exception.EntityNotFoundException - when credential is not found
    • findCredentialsByCredentialIds

      List<Credential> findCredentialsByCredentialIds(List<UUID> credentialIds)
      Finds a list of credentials by the given credential ids
      Parameters:
      credentialIds - list of credential ids
      Returns:
      list of credentials
      Throws:
      com.dzidzi.exception.EntityNotFoundException - when credential is not found
    • findAllUsersCredentials

      List<Credential> findAllUsersCredentials()
      Finds the list of credentials and sort them by username in asc.
      Returns:
      the list of credentials
    • addNewUserCredentialByAdmin

      Credential addNewUserCredentialByAdmin(String email, UserRole role)
      Creates a user credential. This is created upon approval of the admin that is admin creates these users with UserRole.ADMIN, UserRole.SERVICE, UserRole.COURIER, UserRole.RESTAURANT_ADMIN. Only UserRole.ADMIN can access this method.
      Parameters:
      email - the email of the new user.
      role - the UserRole of the user ie RESTAURANT, ADMIN, COURIER OR SERVICE
      Returns:
      the Credential of the new user.
      Throws:
      com.dzidzi.exception.DzidziException - when email already exists for the roles other than UserRole.COURIER. One email can only have two roles that is only UserRole.USER and UserRole.COURIER.
    • findUserCredentialByVerificationCode

      Credential findUserCredentialByVerificationCode(String verificationCode)
      Finds the credential by verification code.
      Parameters:
      verificationCode - the verification code of the user
      Returns:
      the credential found
      Throws:
      com.dzidzi.exception.EntityNotFoundException - when entity is not found
    • changeUserPassword

      Credential changeUserPassword(String oldPass, String newPass, String username, UUID credentialId)
      Changes the existing password of the user.
      Parameters:
      oldPass - the existing password
      newPass - the new password
      username - the username
      credentialId - credential id
      Returns:
      the updated credential
      Throws:
      com.dzidzi.exception.DzidziException - when old password does not match password in the DB
    • passwordResetLink

      void passwordResetLink(String emailOrUsername, UserRole userRole)
      This generates a new password reset link for the given username or email and role. This link expires in 10min.
      Parameters:
      emailOrUsername - the email or username of user
      userRole - the user role
      Throws:
      com.dzidzi.exception.EntityNotFoundException - when the username or email doesn't exist
      com.dzidzi.exception.DzidziException - when the user signed up with a third party.
    • addNewPassword

      Credential addNewPassword(CreateNewPasswordRequest createNewPasswordRequest, String verificationCode)
      The new password and username to complete credential account creation.
      Parameters:
      createNewPasswordRequest - the CreateNewPasswordRequest to complete creating an account
      verificationCode - the verification code of the user credential
      Returns:
      the newly activated credential.
      Throws:
      com.dzidzi.exception.DzidziException - when repeated password does not match new password
    • removeUserAccount

      void removeUserAccount(UUID credentialId)
      Removes the account from the system.
      Parameters:
      credentialId - credential id
    • resetPassword

      void resetPassword(String password, String repeatedPassword, String passwordChangeCode)
      Sets a new user account password with the given password.
      Parameters:
      password - the new password to use
      repeatedPassword - the repeated password
      passwordChangeCode - the password change hashed code
    • deactivateUserAccountByAdmin

      void deactivateUserAccountByAdmin(String email, UserRole role)
      Deactivates account by admin. Roles that can be deactivated by admin are service, restaurant, courier and admin.
      Parameters:
      email - the user email
      role - the role
    • deactivateUserAccount

      void deactivateUserAccount(UUID credentialId)
      Deactivates account by admin if user is a courier, admin, restaurant, user and service. Only users with USER roles can deactivate themselves.
      Parameters:
      credentialId - the user id
    • reactivateUserAccountByAdmin

      void reactivateUserAccountByAdmin(UUID userId)
      Admin reactivates account that has been deactivated. Roles that can be reactivated by admin are service, restaurant, courier and admin.
      Parameters:
      userId - the id of the service, courier, restaurant or admin
    • getCurrentUserCredential

      Credential getCurrentUserCredential()
    • usernameExist

      boolean usernameExist(String username)
    • getUserDetails

      com.dzidzi.service.login.DzidziUserDetails getUserDetails(String username)
    • getUserDetails

      com.dzidzi.service.login.DzidziUserDetails getUserDetails(String email, UserRole role)