Skip to content

4. Controllers

Yunus Emre Bulut edited this page Jan 15, 2022 · 7 revisions

The Whoo Class

You can use all controller class this pattern

$whoo = new Whoo('ControllerClassName', $argumentsArray);

$whoo->success(function() {/* if everything OK, this block is running */});

$whoo->exception('ExceptionNameWithoutSuffix', function() {/* catching exceptions */})

$whoo->run();

SignUp

This class provides user to create a new account. You can set username or use SetUsername class after this class.

Construction

SignUp([
    email email[1:255], 
    str password[8:50], 
    str passwordAgain[8:50] (optional), 
    str username[1:40] (optional)
]);

Exceptions

Name Precondition Condition
NotUniqueEmailException n/a email is not unique in Whoo database
UnmatchedPasswordsException passing optional passwordAgain password and passwordAgain are not matched
NotUniqueUsernameException use_username config true and passing optional username username is not unique

SignIn

This class provides user to generate JWT using email and password. You can get generated JWT from $jwt attribute of created SignIn object. You can also check passwords that it is same or not same using passwordAgain optional key.

Construction

SignIn([
    email email[1:255], 
    str password[8:50], 
    str passwordAgain[8:50] (optional)
]);

Exceptions

Name Precondition Condition
IncorrectPasswordException n/a password is incorrect
NotFoundException n/a There is no account with this email
NullUsernameException deny_if_not_set_username config true The user has not a username
NotVerifiedEmailException deny_if_not_verified_to_sign_in config true The user has not verified own email.
TwoFactorAuthEnabledException n/a Two-factor authentication setting of user's account is open
UnmatchedPasswordsException passing optional passwordAgain password and passwordAgain are not matched

SignInByUsername

This class provides user to generate JWT using username and password. You can get generated JWT from $jwt attribute of created SignInByUsername object. You can also check passwords that it is same or not same using passwordAgain optional key.

Construction

SignInByUsername([
    str username[1:40], 
    str password[8:50], 
    str passwordAgain[8:50] (optional)
]);

Exceptions

Name Precondition Condition
IncorrectPasswordException n/a password is incorrect
NotFoundException n/a There is no account with this email
NotVerifiedEmailException deny_if_not_verified_to_sign_in config true The user has not verified own email.
TwoFactorAuthEnabledException n/a Two-factor authentication setting of user's account is open
UnmatchedPasswordsException passing optional passwordAgain password and passwordAgain are not matched

SignInByProvider

This class provides user to generate JWT using OAuth2 provider. You can get generated JWT from $jwt attribute of created SignInByProvider object.

Construction

SignInByProvider([
    email email[1:255], 
    str provider[1:255], 
    str providerId[1:255]
]);

Exceptions

Name Precondition Condition
SignUpByEmailException deny_if_sign_up_before_by_email config true The user has been registered not using provider.
NullUsernameException use_username config true The user has not a username

SetUsername

If you want to set username of new user after using sign up classes, you can use this class. tempToken is unique token for each new user who has not username. You can send temporary token to new user directly.

Construction

SetUsername([
    str tempToken[60:60], 
    str username[1:40]
]);

Exceptions

Name Precondition Condition
InvalidTemporaryTokenException n/a tempToken is invalid
NotUniqueUsernameException n/a username is not unique
NotNullUsernameException n/a The user has a username

SetAuthCodeForEmailVerification

This class provides user to generate random authentication code for to be used in VerifyEmail class. If it done successfully, you can get authentication code from attribute of created SetAuthCodeForEmailVerification object. It's name is $authCode

Construction

SetAuthCodeForEmailVerification([
    email email[1:255]
]);

Exceptions

Name Precondition Condition
NotFoundException n/a There is no account with this email

VerifyEmail

This class provides user to verify email of users.

Construction

VerifyEmail([
    email email[1:255], 
    str authCode[1:10]
]);

Exceptions

Name Precondition Condition
InvalidCodeException n/a authCode is invalid
TrialCountOverException n/a Number of attempts exceeded the trial_max_count_to_verify_email config
TimeOutCodeException n/a Time of authentication code is over
NotFoundException n/a There is no account with this email
NotFoundAuthCodeException n/a Authentication code has not been created for this operation

SignOut

This class provides user to destroy all token created by user.

Construction

SignOut([
    str jwt[1:5000]
]);

Exceptions

Name Precondition Condition
InvalidToken n/a jwt is invalid

SetAuthCodeToResetPassword

This class provides user to generate random authentication code for to be used in ResetPassword class. If it done successfully, you can get authentication code from attribute of created SetAuthCodeToResetPassword object. It's name is $authCode

Construction

SetAuthCodeToResetPassword([
    email email[1:255]
]);

Exceptions

Name Precondition Condition
NotFoundException n/a There is no account with this email
NotVerifiedEmailException deny_if_not_verified_to_reset_pw config true The user has not verified own email.

ResetPassword

This class provides user to reset own passwords.

Construction

ResetPassword([
    email email[1:255], 
    str newPassword[8:50], 
    str authCode[1:10]
]);

Exceptions

Name Precondition Condition
InvalidCodeException n/a authCode is invalid
NotFoundException n/a There is no account with this email
NotFoundAuthCodeException n/a Authentication code has not been created for this operation

ChangeEmail

This class provides user to change own email.

Construction

ChangeEmail([
    str jwt[1:5000], 
    email newEmail[1:255], 
    str password[8:50]
]);

Exceptions

Name Precondition Condition
InvalidToken n/a jwt is invalid
NotUniqueEmailException n/a email is not unique in Whoo database
IncorrectPasswordException n/a password is incorrect

ChangeUsername

This class provides user to change own username

Construction

ChangeUsername([
    str jwt[1:5000], 
    str newUsername[1:40]
]);

Exceptions

Name Precondition Condition
InvalidToken n/a jwt is invalid
NotUniqueUsernameException n/a username is not unique

ChangePassword

This class provides user to change own password

Construction

ChangePassword([
    str jwt[1:5000], 
    str password[8:50], 
    str newPassword[8:50]
]);

Exceptions

Name Precondition Condition
InvalidToken n/a jwt is invalid
IncorrectPasswordException n/a password is incorrect

SetAuthCodeToManage2FA

This class provides user to generate random authentication code for to be used in Manage2FA class. If it done successfully, you can get authentication code from attribute of created SetAuthCodeToManage2FA object. It's name is $authCode

Construction

SetAuthCodeToManage2FA([
    str jwt[1:5000], 
    str password[8:50]
]);

Exceptions

Name Precondition Condition
InvalidToken n/a jwt is invalid
IncorrectPasswordException n/a password is incorrect

Manage2FA

This class provides user to change two-factor authentication setting as true or false.

Construction

Manage2FA([
    str jwt[1:5000], 
    str authCode[1:10], 
    bool open
]);

Exceptions

Name Precondition Condition
InvalidToken n/a jwt is invalid
TrialCountOverException n/a Number of attempts exceeded the trial_max_count_to_manage_2fa config
InvalidCodeException n/a authCode is invalid

SignIn2FA

This class provides user to sign in using email if two-factor authentication setting of the user account is open

Construction

SignIn2FA([
    email email[1:255], 
    str authCode[1:10]
]);

Exceptions

Name Precondition Condition
NotFoundException n/a There is no account with this email
NotFoundAuthCodeException n/a Authentication code has not been created for this operation
TrialCountOverException n/a Number of attempts exceeded the trial_max_count_to_sign_in_2fa config
TimeOutCodeException n/a Time of authentication code is over
InvalidCodeException n/a authCode is invalid

SignInByUsername2FA

This class provides user to sign in using username if two-factor authentication setting of the user account is open

Construction

SignInByUsername2FA([
    str username[1:40], 
    str authCode[1:10]
]);

Exceptions

Name Precondition Condition
NotFoundException n/a There is no account with this email
NotFoundAuthCodeException n/a Authentication code has not been created for this operation
TrialCountOverException n/a Number of attempts exceeded the trial_max_count_to_sign_in_2fa config
TimeOutCodeException n/a Time of authentication code is over
InvalidCodeException n/a authCode is invalid