Skip to content

Commit 82fa238

Browse files
authored
Merge pull request #2 from MuShare/develop/pluto-master
Adapt for pluto master
2 parents 0a02a43 + 8f797e9 commit 82fa238

File tree

11 files changed

+34
-34
lines changed

11 files changed

+34
-34
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,7 @@ lint/intermediates/
8282
lint/generated/
8383
lint/outputs/
8484
lint/tmp/
85-
# lint/reports/
85+
# lint/reports/
86+
87+
# idea
88+
.idea/

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ allprojects {
2020
repositories {
2121
google()
2222
jcenter()
23-
2423
}
2524
}
2625

demoapp/src/main/java/com/mushare/demoapp/data/LoginDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LoginDataSource {
1616
// TODO: handle loggedInUser authentication
1717
//pluto?.registerByEmail(username, password, "Test", {
1818
//pluto?.resendValidationEmail(username, {
19-
pluto?.loginWithEmail(username, password, {
19+
pluto?.loginWithAccount(username, password, {
2020
pluto.myInfo({
2121
val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), it.name)
2222
onComplete(Result.Success(fakeUser))

demoapp/src/main/java/com/mushare/demoapp/ui/login/LoginActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ class LoginActivity : AppCompatActivity() {
2727

2828
setContentView(R.layout.activity_login)
2929

30-
Pluto.initialize(this,"https://staging.easyjapanese-api-gateway.mushare.cn/pluto/","org.mushare.easyjapanese")
30+
Pluto.initialize(
31+
this,
32+
"https://staging.easyjapanese-api-gateway.mushare.cn/pluto-master/",
33+
"org.mushare.easyjapanese"
34+
)
3135

3236
val username = findViewById<EditText>(R.id.username)
3337
val password = findViewById<EditText>(R.id.password)

demoapp/src/main/java/com/mushare/demoapp/ui/login/LoginViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ class LoginViewModel(private val loginRepository: LoginRepository) : ViewModel()
5151

5252
// A placeholder password validation check
5353
private fun isPasswordValid(password: String): Boolean {
54-
return password.length > 5
54+
return password.length > 2
5555
}
5656
}

pluto-kotlin-client-sdk/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ apply plugin: 'kotlin-android-extensions'
44
apply plugin: 'maven-publish'
55

66
buildscript {
7-
ext.versionCode = 10
8-
ext.versionName = '0.1.9'
7+
ext.versionCode = 11
8+
ext.versionName = '0.2'
99
}
1010

1111
android {

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/Pluto+Auth.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mushare.plutosdk
22

3-
import com.mushare.plutosdk.Pluto.Companion.appId
43
import retrofit2.Call
54
import retrofit2.Callback
65
import retrofit2.Response
@@ -22,12 +21,11 @@ fun Pluto.getToken(completion: (String?) -> Unit, handler: Pluto.PlutoRequestHan
2221
private fun Pluto.refreshToken(completion: (String?) -> Unit, handler: Pluto.PlutoRequestHandler? = null) {
2322
val userId = data.userId
2423
val refreshToken = data.refreshToken
25-
val deviceId = data.deviceID
26-
if (userId == null || refreshToken == null || deviceId == null) {
24+
if (userId == null || refreshToken == null) {
2725
completion(null)
2826
return
2927
}
30-
plutoService.refreshAuth(RefreshAuthPostData(refreshToken, userId, deviceId, appId)).apply {
28+
plutoService.refreshAuth(RefreshAuthPostData(refreshToken, userId)).apply {
3129
enqueue(object : Callback<PlutoResponseWithBody<RefreshAuthResponse>> {
3230
override fun onFailure(
3331
call: Call<PlutoResponseWithBody<RefreshAuthResponse>>,

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/Pluto+Login.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ fun Pluto.resendValidationEmail(address: String, success: () -> Unit, error: ((P
5757
}
5858
}
5959

60-
fun Pluto.loginWithEmail(address: String, password: String, success: (() -> Unit)? = null, error: ((PlutoError) -> Unit)? = null, handler: Pluto.PlutoRequestHandler? = null) {
60+
fun Pluto.loginWithAccount(address: String, password: String, success: (() -> Unit)? = null, error: ((PlutoError) -> Unit)? = null, handler: Pluto.PlutoRequestHandler? = null) {
6161
val deviceId = data.deviceID
6262
if (deviceId == null) {
6363
error?.invoke(PlutoError.badRequest)
6464
return
6565
}
66-
plutoService.loginWithEmail(LoginWithEmailPostData(address, password, deviceId, appId)).apply {
66+
plutoService.loginWithAccount(LoginWithAccountPostData(address, password, deviceId, appId)).apply {
6767
enqueue(object : Callback<PlutoResponseWithBody<LoginResponse>> {
6868
override fun onFailure(call: Call<PlutoResponseWithBody<LoginResponse>>, t: Throwable) {
6969
t.printStackTrace()
@@ -145,10 +145,8 @@ fun Pluto.logout() {
145145
private fun Pluto.handleLogin(response: PlutoResponseWithBody<LoginResponse>, success: (() -> Unit)?, error: ((PlutoError) -> Unit)?) {
146146
if (response.statusOK()) {
147147
val body = response.getBody()
148-
val refreshToken = body.refreshToken
149-
val jwt = body.jwt
150-
data.updateRefreshToken(refreshToken)
151-
if (!data.updateJwt(jwt)) {
148+
data.updateRefreshToken(body.refreshToken)
149+
if (!data.updateJwt(body.accessToken)) {
152150
error?.invoke(PlutoError.parseError)
153151
return
154152
}

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/PlutoModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ internal class PlutoModel(context: Context) {
6868
val body = JwtUtils.decodeBody(jwt) ?: return false
6969
return try {
7070
val json = JSONObject(body)
71-
_userId.value = json.getInt("userId")
72-
_expire.value = json.getInt("expire_time")
71+
_userId.value = json.getInt("sub")
72+
_expire.value = json.getInt("exp")
7373
_jwt.value = jwt
7474
true
7575
} catch (e: Exception) {

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/PlutoResponse.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RefreshAuthResponse(
3131

3232
class LoginResponse(
3333
@field:SerializedName("refresh_token") var refreshToken: String,
34-
@field:SerializedName("jwt") var jwt: String
34+
@field:SerializedName("access_token") var accessToken: String
3535
)
3636

3737
internal fun parseErrorCodeFromErrorBody(errorBody: ResponseBody?, gson: Gson): PlutoError {

0 commit comments

Comments
 (0)