Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
# lint/reports/

# idea
.idea/
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ allprojects {
repositories {
google()
jcenter()

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LoginDataSource {
// TODO: handle loggedInUser authentication
//pluto?.registerByEmail(username, password, "Test", {
//pluto?.resendValidationEmail(username, {
pluto?.loginWithEmail(username, password, {
pluto?.loginWithAccount(username, password, {
pluto.myInfo({
val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), it.name)
onComplete(Result.Success(fakeUser))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class LoginActivity : AppCompatActivity() {

setContentView(R.layout.activity_login)

Pluto.initialize(this,"https://staging.easyjapanese-api-gateway.mushare.cn/pluto/","org.mushare.easyjapanese")
Pluto.initialize(
this,
"https://staging.easyjapanese-api-gateway.mushare.cn/pluto-master/",
"org.mushare.easyjapanese"
)

val username = findViewById<EditText>(R.id.username)
val password = findViewById<EditText>(R.id.password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ class LoginViewModel(private val loginRepository: LoginRepository) : ViewModel()

// A placeholder password validation check
private fun isPasswordValid(password: String): Boolean {
return password.length > 5
return password.length > 2
}
}
4 changes: 2 additions & 2 deletions pluto-kotlin-client-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'maven-publish'

buildscript {
ext.versionCode = 10
ext.versionName = '0.1.9'
ext.versionCode = 11
ext.versionName = '0.2'
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mushare.plutosdk

import com.mushare.plutosdk.Pluto.Companion.appId
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -22,12 +21,11 @@ fun Pluto.getToken(completion: (String?) -> Unit, handler: Pluto.PlutoRequestHan
private fun Pluto.refreshToken(completion: (String?) -> Unit, handler: Pluto.PlutoRequestHandler? = null) {
val userId = data.userId
val refreshToken = data.refreshToken
val deviceId = data.deviceID
if (userId == null || refreshToken == null || deviceId == null) {
if (userId == null || refreshToken == null) {
completion(null)
return
}
plutoService.refreshAuth(RefreshAuthPostData(refreshToken, userId, deviceId, appId)).apply {
plutoService.refreshAuth(RefreshAuthPostData(refreshToken, userId)).apply {
enqueue(object : Callback<PlutoResponseWithBody<RefreshAuthResponse>> {
override fun onFailure(
call: Call<PlutoResponseWithBody<RefreshAuthResponse>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ fun Pluto.resendValidationEmail(address: String, success: () -> Unit, error: ((P
}
}

fun Pluto.loginWithEmail(address: String, password: String, success: (() -> Unit)? = null, error: ((PlutoError) -> Unit)? = null, handler: Pluto.PlutoRequestHandler? = null) {
fun Pluto.loginWithAccount(address: String, password: String, success: (() -> Unit)? = null, error: ((PlutoError) -> Unit)? = null, handler: Pluto.PlutoRequestHandler? = null) {
val deviceId = data.deviceID
if (deviceId == null) {
error?.invoke(PlutoError.badRequest)
return
}
plutoService.loginWithEmail(LoginWithEmailPostData(address, password, deviceId, appId)).apply {
plutoService.loginWithAccount(LoginWithAccountPostData(address, password, deviceId, appId)).apply {
enqueue(object : Callback<PlutoResponseWithBody<LoginResponse>> {
override fun onFailure(call: Call<PlutoResponseWithBody<LoginResponse>>, t: Throwable) {
t.printStackTrace()
Expand Down Expand Up @@ -145,10 +145,8 @@ fun Pluto.logout() {
private fun Pluto.handleLogin(response: PlutoResponseWithBody<LoginResponse>, success: (() -> Unit)?, error: ((PlutoError) -> Unit)?) {
if (response.statusOK()) {
val body = response.getBody()
val refreshToken = body.refreshToken
val jwt = body.jwt
data.updateRefreshToken(refreshToken)
if (!data.updateJwt(jwt)) {
data.updateRefreshToken(body.refreshToken)
if (!data.updateJwt(body.accessToken)) {
error?.invoke(PlutoError.parseError)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ internal class PlutoModel(context: Context) {
val body = JwtUtils.decodeBody(jwt) ?: return false
return try {
val json = JSONObject(body)
_userId.value = json.getInt("userId")
_expire.value = json.getInt("expire_time")
_userId.value = json.getInt("sub")
_expire.value = json.getInt("exp")
_jwt.value = jwt
true
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RefreshAuthResponse(

class LoginResponse(
@field:SerializedName("refresh_token") var refreshToken: String,
@field:SerializedName("jwt") var jwt: String
@field:SerializedName("access_token") var accessToken: String
)

internal fun parseErrorCodeFromErrorBody(errorBody: ResponseBody?, gson: Gson): PlutoError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,48 @@ import retrofit2.Call
import retrofit2.http.*

interface PlutoService {
@POST("api/auth/refresh")
@POST("v1/token/refresh")
fun refreshAuth(
@Body body: RefreshAuthPostData
): Call<PlutoResponseWithBody<RefreshAuthResponse>>

@POST("api/user/register")
@POST("v1/user/register")
fun registerWithEmail(
@Body body: RegisterWithEmailPostData,
@Header("Accept-Language") language: String
): Call<PlutoResponse>

@POST("api/user/register/verify/mail")
@POST("v1/user/register/verify/mail")
fun resendValidationEmail(
@Body body: EmailPostData,
@Header("Accept-Language") language: String
): Call<PlutoResponse>

@POST("api/user/password/reset/mail")
@POST("v1/user/password/reset/mail")
fun resetPassword(
@Body body: EmailPostData,
@Header("Accept-Language") language: String
): Call<PlutoResponse>

@POST("api/user/login")
fun loginWithEmail(
@Body body: LoginWithEmailPostData
@POST("v1/user/login/account")
fun loginWithAccount(
@Body body: LoginWithAccountPostData
): Call<PlutoResponseWithBody<LoginResponse>>

@POST("api/user/login/google/mobile")
@POST("v1/user/login/google/mobile")
fun loginWithGoogle(
@Body body: LoginWithGooglePostData
): Call<PlutoResponseWithBody<LoginResponse>>

@GET("api/user/info/me")
@GET("v1/user/info")
fun getAccountInfo(
@HeaderMap authorizationHeader: Map<String, String>
): Call<PlutoResponseWithBody<PlutoUser>>
}

class RefreshAuthPostData(
@field:SerializedName("refresh_token") var refreshToken: String,
@field:SerializedName("user_id") var userId: Int,
@field:SerializedName("device_id") var deviceId: String,
@field:SerializedName("app_id") var appId: String
@field:SerializedName("user_id") var userId: Int
)

class RegisterWithEmailPostData(
Expand All @@ -61,8 +59,8 @@ class EmailPostData(
@field:SerializedName("mail") var mail: String
)

class LoginWithEmailPostData(
@field:SerializedName("mail") var mail: String,
class LoginWithAccountPostData(
@field:SerializedName("account") var account: String,
@field:SerializedName("password") var password: String,
@field:SerializedName("device_id") var deviceId: String,
@field:SerializedName("app_id") var appId: String
Expand Down