User Authentication (C compatible) - modio/modio-sdk-legacy GitHub Wiki
modioEmailRequest
void modioEmailRequest(void* object, char* email, void (*callback)(void* object, ModioResponse response));
API endpoint used: Email Request
C++ wrapper: User Authentication#emailrequest
Requests a 5-digit security code to be sent via email. emailExchange should be called after to complete the authentication process.
Function parameters
Name | Type | Description |
---|---|---|
object | void* |
Context parameter. |
char* |
User's email. | |
callback | void (*callback)(void* object, ModioResponse response) |
Function called once the process finished. |
Callback parameters
Name | Type | Description |
---|---|---|
object | void* |
Context parameter. |
response | ModioResponse |
ModioResponse object that contains the mod.io response status. |
Example
void onEmailRequest(void* object, ModioResponse response)
{
if(response.code == 200)
{
//Email requested successfully
}
}
[...]
modioEmailRequest(NULL,"[email protected]",&onEmailRequest);
modioEmailExchange
void modioEmailExchange(void* object, char* security_code, void (*callback)(void* object, ModioResponse response));
API endpoint used: Email Exchange
C++ wrapper: User Authentication#emailexchange
Exchanges the 5-digit code for an authentication token. The token is handled internally by the SDK.
Function parameters
Name | Type | Description |
---|---|---|
object | void* |
Context parameter. |
security_code | char* |
5-digit code sent to users via email when emailRequest was called. |
callback | void (*callback)(void* object, ModioResponse response) |
Function called once the process finished. |
Callback parameters
Name | Type | Description |
---|---|---|
response | ModioResponse |
ModioResponse object that contains the mod.io response status |
Example
void onExchange(void* object, ModioResponse response)
{
if(response.code == 200)
{
//Code exchanged successfully
}
}
[...]
modioEmailExchange(NULL, "5UI23", &onExchange);
modioAuthenticateViaToken
void modioAuthenticateViaToken(char const* access_token);
C++ wrapper: User Authentication#authenticateviatoken
Authenticates the user by providing a valid mod.io token directly.
Function parameters
Name | Type | Description |
---|---|---|
access_token | char const* |
mod.io user authentication token. |
Example
modioAuthenticateViaToken("eykger...lkw421");
modioIsLoggedIn
bool modioIsLoggedIn();
C++ wrapper: User Authentication#isloggedin
Returns true if the user is logged in, otherwise returns false.
modioGetCurrentUser
const struct ModioUser modioGetCurrentUser();
Returns a ModioUser object corresponding to the current user logged in.
Example
if(modioIsLoggedIn())
{
printf("Logged in as %s\n", modioGetCurrentUser().username);
}else
{
printf("You are not logged in.\n");
}
modioLogout
void modioLogout();
C++ wrapper: User Authentication#logout
Logs out the user from mod.io.