Skip to content
Open
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: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,6 @@ dependencies {
debugImplementation "com.facebook.stetho:stetho-okhttp3:${rootConfiguration.stethoVersion}"

releaseImplementation "com.github.iamareebjamal:stetho-noop:1.2.1"

implementation "com.google.android.gms:play-services-safetynet:${rootConfiguration.safetynetVersion}"
}
1 change: 1 addition & 0 deletions app/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ ext {
playServiceAuthVersion='16.0.1'
shimmerVersion = "0.5.0"
stethoVersion = "1.5.1"
safetynetVersion = "16.0.0"
}
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
46 changes: 30 additions & 16 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

/**
* <h1>The SignUp activity.</h1>
Expand All @@ -37,6 +41,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 = "6LcKhbMUAAAAAGFbYZeNFzqol-7EjOHUK5MvEeOE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be hardcoded

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What else can I do to avoid this @iamareebjamal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See where all configs are placed


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -100,8 +105,8 @@ 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 @@ -251,20 +256,29 @@ class SignUpActivity : AppCompatActivity(), ISignUpView {

private fun signUp() {

signUp.setOnClickListener {

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)
}
verifyRecaptcha()
}
fun verifyRecaptcha() {

SafetyNet.getClient(this).verifyWithRecaptcha(RECAPTCHA_KEY)
.addOnSuccessListener(this, OnSuccessListener { response ->
val userResponseToken = response.tokenResult
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not correct way of using Timber.e

})
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class SignUpPresenter(signUpActivity: SignUpActivity) : ISignUpPresenter, ISignU
this.signUpView = signUpView
}

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)
return
Expand Down Expand Up @@ -90,7 +89,7 @@ class SignUpPresenter(signUpActivity: SignUpActivity) : ISignUpPresenter, ISignU

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 @@ -10,7 +10,7 @@ interface ISignUpPresenter {

fun onAttach(signUpView: ISignUpView)

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

fun onDetach()

Expand Down