Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implemented ReCaptcha Verification in sign_up process #2446

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ dependencies {
//Smart LOck authentication
implementation "com.google.android.gms:play-services-auth:${rootConfiguration.playServiceAuthVersion}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootConfiguration.kotlinVersion}"
implementation "com.google.android.gms:play-services-safetynet:${rootConfiguration.safetynetVersion}"

//Stetho
debugImplementation "com.facebook.stetho:stetho:${rootConfiguration.stethoVersion}"

//Stetho network helper
debugImplementation "com.facebook.stetho:stetho-okhttp3:${rootConfiguration.stethoVersion}"

releaseImplementation "com.github.iamareebjamal:stetho-noop:1.2.1"
}
1 change: 1 addition & 0 deletions app/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ ext {
playServiceAuthVersion='16.0.1'
shimmerVersion = "0.5.0"
stethoVersion = "1.5.1"
safetynetVersion = "16.0.0"
koinVersion = "2.0.1"
}
4 changes: 2 additions & 2 deletions app/src/main/java/org/fossasia/susi/ai/data/SignUpModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class SignUpModel : ISignUpModel {

private lateinit var authResponseCall: Call<SignUpResponse>

override fun signUp(email: String, password: String, listener: ISignUpModel.OnSignUpFinishedListener) {
override fun signUp(email: String, password: String, recaptchaResponse: String, listener: ISignUpModel.OnSignUpFinishedListener) {

authResponseCall = ClientBuilder.susiApi
.signUp(email, password)
.signUp(email, password, recaptchaResponse)

authResponseCall.enqueue(object : Callback<SignUpResponse> {
override fun onResponse(call: Call<SignUpResponse>, response: Response<SignUpResponse>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ISignUpModel {
fun onSuccess(response: Response<SignUpResponse>)
}

fun signUp(email: String, password: String, listener: OnSignUpFinishedListener)
fun signUp(email: String, password: String, recaptchaResponse: String, listener: OnSignUpFinishedListener)

fun cancelSignUp()
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ interface SusiService {
@POST("/aaa/signup.json")
fun signUp(
@Query("signup") email: String,
@Query("password") password: String
@Query("password") password: String,
@Query("g-recaptcha-response") recaptchaResponse: String
): Call<SignUpResponse>

/**
Expand Down
51 changes: 36 additions & 15 deletions app/src/main/java/org/fossasia/susi/ai/signup/SignUpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import com.google.android.gms.safetynet.SafetyNet
import com.google.android.gms.tasks.OnFailureListener
import com.google.android.gms.tasks.OnSuccessListener
import kotlinx.android.synthetic.main.activity_sign_up.*
import org.fossasia.susi.ai.R
import org.fossasia.susi.ai.chat.ChatActivity
Expand All @@ -22,6 +25,7 @@ import org.fossasia.susi.ai.login.LoginActivity
import org.fossasia.susi.ai.signup.contract.ISignUpPresenter
import org.fossasia.susi.ai.signup.contract.ISignUpView
import org.fossasia.susi.ai.skills.SkillsActivity
import timber.log.Timber
import org.koin.android.ext.android.inject
import org.koin.core.parameter.parametersOf

Expand All @@ -39,7 +43,7 @@ class SignUpActivity : AppCompatActivity(), ISignUpView {
private lateinit var forgotPasswordProgressDialog: Dialog
private lateinit var builder: AlertDialog.Builder
private var checkDialog: Boolean = false

private val RECAPTCHA_KEY = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sign_up)
Expand Down Expand Up @@ -99,8 +103,7 @@ class SignUpActivity : AppCompatActivity(), ISignUpView {
startActivity(intent)
finish()
})
setNegativeButton(android.R.string.no, DialogInterface.OnClickListener {
dialog, id -> dialog.cancel()
setNegativeButton(android.R.string.no, DialogInterface.OnClickListener { dialog, id -> dialog.cancel()
})
show()
}
Expand Down Expand Up @@ -249,21 +252,39 @@ class SignUpActivity : AppCompatActivity(), ISignUpView {
}

private fun signUp() {

signUp.setOnClickListener {
verifyRecaptcha()
}
}

email.error = null
password.error = null
confirmPassword.error = null
inputUrlSignUp.error = null

val stringEmail = email.editText?.text.toString()
val stringPassword = password.editText?.text.toString()
val stringConfirmPassword = confirmPassword.editText?.text.toString()
val stringURL = inputUrlSignUp.editText?.text.toString()
fun verifyRecaptcha() {
if (RECAPTCHA_KEY != "") {
SafetyNet.getClient(this).verifyWithRecaptcha(RECAPTCHA_KEY)
.addOnSuccessListener(this, OnSuccessListener { response ->
val userResponseToken = response.tokenResult
Timber.d("Great", "Captcha verification started")
if (response.tokenResult?.isNotEmpty() == true) {
email.error = null
password.error = null
confirmPassword.error = null
inputUrlSignUp.error = null

val stringEmail = email.editText?.text.toString()
val stringPassword = password.editText?.text.toString()
val stringConfirmPassword = confirmPassword.editText?.text.toString()
val stringURL = inputUrlSignUp.editText?.text.toString()
signUpPresenter.signUp(stringEmail, stringPassword, stringConfirmPassword, !customServerSignUp.isChecked, stringURL, acceptTermsAndConditions.isChecked, userResponseToken)
}
})
.addOnFailureListener(this, OnFailureListener { e ->
Timber.e("Error: " + e)
})
} else { Toast.makeText(this, "NO ReCaptcha key available", Toast.LENGTH_LONG).show() }
}

signUpPresenter.signUp(stringEmail, stringPassword, stringConfirmPassword, !customServerSignUp.isChecked, stringURL, acceptTermsAndConditions.isChecked)
}
override fun onDestroy() {
signUpPresenter.onDetach()
super.onDestroy()
}

override fun showForgotPasswordProgress(boolean: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SignUpPresenter(private val forgotPasswordModel: ForgotPasswordModel, priv
private var settingView: ISettingsView? = null
lateinit var email: String

override fun signUp(email: String, password: String, conpass: String, isSusiServerSelected: Boolean, url: String, isTermsAndConditionSelected: Boolean) {
override fun signUp(email: String, password: String, conpass: String, isSusiServerSelected: Boolean, url: String, isTermsAndConditionSelected: Boolean, recaptchaResponse: String) {

if (email.isEmpty()) {
signUpView?.invalidCredentials(true, Constant.EMAIL)
Expand Down Expand Up @@ -80,7 +80,7 @@ class SignUpPresenter(private val forgotPasswordModel: ForgotPasswordModel, priv

this.email = email
signUpView?.showProgress(true)
signUpModel.signUp(email.trim { it <= ' ' }.toLowerCase(), password, this)
signUpModel.signUp(email.trim { it <= ' ' }.toLowerCase(), password, recaptchaResponse, this)
}

override fun onError(throwable: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ package org.fossasia.susi.ai.signup.contract

interface ISignUpPresenter {

fun signUp(email: String, password: String, conpass: String, isSusiServerSelected: Boolean, url: String, isTermsAndConditionSelected: Boolean)
fun onAttach(signUpView: ISignUpView)

fun signUp(email: String, password: String, conpass: String, isSusiServerSelected: Boolean, url: String, isTermsAndConditionSelected: Boolean, recaptchaResponse: String)

fun cancelSignUp()

Expand Down