Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@ 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}"
}
1 change: 1 addition & 0 deletions app/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ ext {
mockitoCoreVersion = '1.10.19'
playServiceAuthVersion='16.0.1'
shimmerVersion = "0.5.0"
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 @@ -72,7 +72,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
47 changes: 33 additions & 14 deletions app/src/main/java/org/fossasia/susi/ai/signup/SignUpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
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 +26,7 @@ import org.fossasia.susi.ai.login.ForgotPass
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 +42,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.

Remove

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -100,8 +106,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 @@ -252,21 +258,34 @@ 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
Log.d("KHANKI", "Started recaptcha verification")
Copy link
Member

Choose a reason for hiding this comment

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

@atm1504 Please remove this.

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()
Log.d("KHANKI", "Signned up")
Copy link
Member

Choose a reason for hiding this comment

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

@atm1504 Please remove this.

signUpPresenter.signUp(stringEmail, stringPassword, stringConfirmPassword, !customServerSignUp.isChecked, stringURL, acceptTermsAndConditions.isChecked, userResponseToken)
}
})
.addOnFailureListener(this, OnFailureListener { e ->
Timber.e("Error: " + e)
})
}

override fun onDestroy() {
signUpPresenter.onDetach()
super.onDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +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)
Expand Down Expand Up @@ -90,7 +90,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