Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Commit

Permalink
2020-04-22 Version 4.1.0: Closed #7 and closed #8
Browse files Browse the repository at this point in the history
  • Loading branch information
fartem committed Apr 22, 2020
1 parent ed54e0d commit f59e204
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 101 deletions.
13 changes: 4 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName '4.0.2'
versionName '4.1.0'

testInstrumentationRunner 'com.smlnskgmail.jaman.randomnotes.runner.AndroidJacocoTestRunner'

Expand Down Expand Up @@ -71,14 +71,9 @@ dependencies {
implementation 'com.smlnskgmail.jaman:adaptiverecyclerview:0.1.2'

// Parse
implementation 'com.github.parse-community.Parse-SDK-Android:parse:1.22.1'
implementation 'com.github.parse-community:ParseFacebookUtils-Android:1.14.0'

// Google
implementation 'com.google.android.gms:play-services-auth:18.0.0'

// Facebook
implementation 'com.facebook.android:facebook-login:5.1.0'
implementation 'com.github.parse-community.Parse-SDK-Android:parse:1.23.0'
implementation 'com.github.parse-community.Parse-SDK-Android:google:1.23.0'
implementation 'com.github.parse-community.Parse-SDK-Android:facebook:1.23.0'

// ORMLite
implementation 'com.j256.ormlite:ormlite-core:5.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package com.smlnskgmail.jaman.randomnotes
import com.smlnskgmail.jaman.randomnotes.auth.EmailAuthTest
import com.smlnskgmail.jaman.randomnotes.auth.FacebookAuthTest
import com.smlnskgmail.jaman.randomnotes.auth.GoogleAuthTest
import com.smlnskgmail.jaman.randomnotes.auth.verification.fake.FakeCloudAuthEmailVerificationTest
import com.smlnskgmail.jaman.randomnotes.auth.verification.fake.FakeCloudAuthPasswordVerificationTest
import com.smlnskgmail.jaman.randomnotes.auth.verification.parse.ParseServerAuthEmailVerificationTest
import com.smlnskgmail.jaman.randomnotes.auth.verification.parse.ParseServerAuthPasswordVerificationTest
import com.smlnskgmail.jaman.randomnotes.invite.InviteTest
import com.smlnskgmail.jaman.randomnotes.note.NoteCreationTest
import com.smlnskgmail.jaman.randomnotes.note.NoteDeletionTest
Expand All @@ -17,6 +21,10 @@ import org.junit.runners.Suite
NoteDeletionTest::class,
NotesSyncTest::class,
NotesRestoreTest::class,
ParseServerAuthEmailVerificationTest::class,
ParseServerAuthPasswordVerificationTest::class,
FakeCloudAuthEmailVerificationTest::class,
FakeCloudAuthPasswordVerificationTest::class,
EmailAuthTest::class,
GoogleAuthTest::class,
FacebookAuthTest::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.smlnskgmail.jaman.randomnotes.auth.verification

import android.content.Context
import androidx.test.platform.app.InstrumentationRegistry
import com.smlnskgmail.jaman.randomnotes.model.api.cloud.CloudAuth
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

abstract class BaseAuthEmailVerificationTest {

fun context(): Context {
return InstrumentationRegistry.getInstrumentation().context
}

@Test
fun validEmailAddressTest() {
assertTrue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import com.smlnskgmail.jaman.randomnotes.model.impl.cloud.parse.ParseServerAuth
class ParseServerAuthEmailVerificationTest : BaseAuthEmailVerificationTest() {

override fun cloudAuth(): CloudAuth {
return ParseServerAuth()
return ParseServerAuth(
context()
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import com.smlnskgmail.jaman.randomnotes.model.impl.cloud.parse.ParseServerAuth
class ParseServerAuthPasswordVerificationTest : BaseAuthEmailVerificationTest() {

override fun cloudAuth(): CloudAuth {
return ParseServerAuth()
return ParseServerAuth(
context()
)
}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/smlnskgmail/jaman/randomnotes/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class App : Application() {
@Suppress("ConstantConditionIf")
if (BuildConfig.CLOUD_REPOSITORY == "PARSE") {
cloudDataSource = ParseServerDataSource(this)
cloudAuth = ParseServerAuth()
cloudAuth = ParseServerAuth(this)
cloudInvite = ParseServerInvite()
} else {
cloudDataSource = FakeCloudDataSource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,25 @@ import android.content.Context
import android.content.Intent
import com.facebook.AccessToken
import com.facebook.login.LoginManager
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.ApiException
import com.parse.LogInCallback
import com.parse.ParseUser
import com.parse.facebook.ParseFacebookUtils
import com.parse.google.ParseGoogleUtils
import com.smlnskgmail.jaman.randomnotes.R
import com.smlnskgmail.jaman.randomnotes.model.api.cloud.CloudAuth
import java.util.regex.Pattern

class ParseServerAuth : CloudAuth {
class ParseServerAuth(
private val context: Context
) : CloudAuth {

companion object {

const val googleAuthRequest = 101

private const val minimumPasswordLength = 8
private const val maximumPasswordLength = 32

}

private var googleAuthCallback: GoogleAuthCallback? = null

override fun isAuthorized(): Boolean {
return ParseUser.getCurrentUser() != null
}
Expand All @@ -35,6 +32,9 @@ class ParseServerAuth : CloudAuth {
activity: Activity,
signInResult: (e: Exception?) -> Unit
) {
ParseFacebookUtils.initialize(
context
)
ParseFacebookUtils.logInWithReadPermissionsInBackground(
activity,
listOf("public_profile")
Expand Down Expand Up @@ -70,80 +70,34 @@ class ParseServerAuth : CloudAuth {
activity: Activity,
signInResult: (e: Exception?) -> Unit
) {
val signInOptions = getGoogleSignInOptions(activity)
val signInClient = GoogleSignIn.getClient(
activity,
signInOptions
ParseGoogleUtils.initialize(
context.getString(
R.string.google_web_app_token_id
)
)

googleAuthCallback = object : GoogleAuthCallback {
override fun sendResult(exception: Exception?) {
signInResult(exception)
ParseGoogleUtils.logIn(
activity,
LogInCallback { user, e ->
signInResult(e)
}
}

activity.startActivityForResult(
signInClient.signInIntent,
googleAuthRequest
)
}

private fun getGoogleSignInOptions(
context: Context
): GoogleSignInOptions {
return GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(context.getString(R.string.google_web_app_token_id))
.requestEmail()
.build()
}

override fun bindForAuth(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
if (requestCode == googleAuthRequest) {
bindForGoogle(data)
} else {
ParseFacebookUtils.onActivityResult(
requestCode,
resultCode,
data
)
}
}

private fun bindForGoogle(data: Intent?) {
try {
val signInAccount = GoogleSignIn.getSignedInAccountFromIntent(data)
.getResult(ApiException::class.java)
if (signInAccount != null) {
val authData: MutableMap<String, String?> = HashMap()
authData["id"] = signInAccount.id
authData["id_token"] = signInAccount.idToken
ParseUser.logInWithInBackground("google", authData)
.continueWith<Any?> {
if (it.result == null) {
googleAuthCallback!!.sendResult(null)
} else {
googleAuthCallback!!.sendResult(
IllegalStateException(
"Google auth error!"
)
)
}
}
} else {
googleAuthCallback!!.sendResult(
NullPointerException(
"Google account must not be null!"
)
)
}
} catch (e: ApiException) {
googleAuthCallback!!.sendResult(e)
}

ParseGoogleUtils.onActivityResult(
requestCode,
resultCode,
data
)
ParseFacebookUtils.onActivityResult(
requestCode,
resultCode,
data
)
}

override fun logOut(afterLogOut: (e: Exception?) -> Unit) {
Expand Down Expand Up @@ -183,10 +137,4 @@ class ParseServerAuth : CloudAuth {
return maximumPasswordLength
}

private interface GoogleAuthCallback {

fun sendResult(exception: Exception?)

}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.smlnskgmail.jaman.randomnotes

import com.smlnskgmail.jaman.randomnotes.auth.verification.fake.FakeCloudAuthEmailVerificationTest
import com.smlnskgmail.jaman.randomnotes.auth.verification.fake.FakeCloudAuthPasswordVerificationTest
import com.smlnskgmail.jaman.randomnotes.auth.verification.parse.ParseServerAuthEmailVerificationTest
import com.smlnskgmail.jaman.randomnotes.auth.verification.parse.ParseServerAuthPasswordVerificationTest
import com.smlnskgmail.jaman.randomnotes.entities.EntityWithIdTest
import com.smlnskgmail.jaman.randomnotes.entities.NoteTest
import org.junit.runner.RunWith
Expand All @@ -12,10 +8,6 @@ import org.junit.runners.Suite
@RunWith(Suite::class)
@Suite.SuiteClasses(
EntityWithIdTest::class,
NoteTest::class,
ParseServerAuthEmailVerificationTest::class,
ParseServerAuthPasswordVerificationTest::class,
FakeCloudAuthEmailVerificationTest::class,
FakeCloudAuthPasswordVerificationTest::class
NoteTest::class
)
class TestSuite
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.71'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'de.aaschmid:gradle-cpd-plugin:3.1'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'
Expand Down

0 comments on commit f59e204

Please sign in to comment.