Overview
The AuthManager class handles all authentication-related operations in Threadly, including login, logout, password reset, and password recovery. It supports multiple login methods (mobile, email, and user ID) and provides secure token-based authentication.
Constructor
Initializes the AuthManager and sets up SharedPreferences for storing authentication data.
Methods
LoginMobile
Authenticates a user using their mobile number and password.
public void LoginMobile(
String mobile,
String password,
NetworkCallbackInterfaceWithJsonObjectDelivery callback
)
callback
NetworkCallbackInterfaceWithJsonObjectDelivery
required
Callback interface to handle the response
Contains authentication token and user details
Example
AuthManager authManager = new AuthManager();
authManager.LoginMobile("+1234567890", "securePassword123",
new NetworkCallbackInterfaceWithJsonObjectDelivery() {
@Override
public void onSuccess(JSONObject response) {
// Handle successful login
String token = response.optString("token");
}
@Override
public void onError(String errorCode) {
// Handle error
}
});
LoginEmail
Authenticates a user using their email address and password.
public void LoginEmail(
String email,
String password,
NetworkCallbackInterfaceWithJsonObjectDelivery callback
)
callback
NetworkCallbackInterfaceWithJsonObjectDelivery
required
Callback interface to handle the response
Contains authentication token and user details
Example
AuthManager authManager = new AuthManager();
authManager.LoginEmail("[email protected]", "securePassword123",
new NetworkCallbackInterfaceWithJsonObjectDelivery() {
@Override
public void onSuccess(JSONObject response) {
// Handle successful login
}
@Override
public void onError(String errorCode) {
// Handle error
}
});
LoginUserId
Authenticates a user using their unique user ID and password.
public void LoginUserId(
String userId,
String password,
NetworkCallbackInterfaceWithJsonObjectDelivery callback
)
callback
NetworkCallbackInterfaceWithJsonObjectDelivery
required
Callback interface to handle the response
Contains authentication token and user details
logout
Logs out the current user and invalidates their session token.
public void logout(NetworkCallbackInterface callbackInterface)
callbackInterface
NetworkCallbackInterface
required
Callback interface to handle the response
Example
AuthManager authManager = new AuthManager();
authManager.logout(new NetworkCallbackInterface() {
@Override
public void onSuccess() {
// User successfully logged out
}
@Override
public void onError(String err) {
// Handle error
}
});
ForgetPasswordWithMobile
Resets the password for a user who authenticated via mobile number.
public void ForgetPasswordWithMobile(
String password,
String token,
NetworkCallbackInterface callback
)
Reset token received via SMS
callback
NetworkCallbackInterface
required
Callback interface to handle the response
Example
AuthManager authManager = new AuthManager();
authManager.ForgetPasswordWithMobile(
"newSecurePassword123",
"reset-token-from-sms",
new NetworkCallbackInterface() {
@Override
public void onSuccess() {
// Password successfully reset
}
@Override
public void onError(String err) {
// Handle error
}
});
ForgetPasswordWithEmail
Resets the password for a user who authenticated via email.
public void ForgetPasswordWithEmail(
String password,
String token,
NetworkCallbackInterface callback
)
Reset token received via email
callback
NetworkCallbackInterface
required
Callback interface to handle the response
ResetPassword
Changes the password for the currently logged-in user.
public void ResetPassword(
String oldPassword,
String newPassword,
NetworkCallbackInterfaceJsonObject callback
) throws JSONException
callback
NetworkCallbackInterfaceJsonObject
required
Callback interface to handle the response
Example
AuthManager authManager = new AuthManager();
try {
authManager.ResetPassword(
"currentPassword123",
"newStrongPassword456",
new NetworkCallbackInterfaceJsonObject() {
@Override
public void onSuccess(JSONObject response) {
// Password successfully changed
}
@Override
public void onError(int errorCode) {
// Handle error
}
});
} catch (JSONException e) {
// Handle exception
}
API Endpoints Used
POST /api/auth/login/mobile - Mobile login
POST /api/auth/login/email - Email login
POST /api/auth/login/userid - User ID login
GET /api/auth/logout - User logout
POST /api/auth/forget-password/mobile - Mobile password reset
POST /api/auth/forget-password/email - Email password reset
POST /api/auth/reset-password - Change password
- ProfileManager - User profile management
- See AuthManager.java:18 for implementation details