32 lines
1.1 KiB
Kotlin
32 lines
1.1 KiB
Kotlin
package com.danilafe.fencelessgrazing.requests
|
|
|
|
import com.android.volley.Response
|
|
import com.android.volley.toolbox.StringRequest
|
|
import com.danilafe.fencelessgrazing.model.LoginResult
|
|
|
|
/**
|
|
* A request to the `/login` endpoint of the API, intended to retrieve the JWT authentication
|
|
* token to be used for the remainder of the interaction with the API.
|
|
*
|
|
* @param baseUrl the base URL of the API.
|
|
* @param username the username with which to attempt to authenticate.
|
|
* @param password the password with which to attempt to authenticate.
|
|
* @param listener the listener that will be called if authentication succeeds.
|
|
* @param error the error listener for the request.
|
|
*/
|
|
class LoginRequest(
|
|
baseUrl: String,
|
|
private val username: String,
|
|
private val password: String,
|
|
listener: Response.Listener<LoginResult>,
|
|
error: Response.ErrorListener
|
|
) : StringRequest (
|
|
Method.POST, "${baseUrl}/login",
|
|
listener.toGsonListener(), error
|
|
) {
|
|
|
|
override fun getParams(): MutableMap<String, String> {
|
|
return mutableMapOf("username" to username, "password" to password)
|
|
}
|
|
|
|
} |