-
Notifications
You must be signed in to change notification settings - Fork 0
Laurislopata/edit profile #82
Changes from all commits
9a2552e
c3ea79d
f833e83
e86eed9
2bee84e
cb23122
7038fa0
9c06b1d
df15c78
0fa1bde
d03ad41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,38 +38,83 @@ class SignInActivityTest { | |
Register::class.java | ||
) | ||
|
||
|
||
@Test | ||
fun logInCorrect() { | ||
val username = "john@test.com" | ||
fun logInIncorrect() { | ||
val username = "johnyyy@test.com" | ||
val password = "password" | ||
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) | ||
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) | ||
onView(withId(R.id.logIn)).perform(click()) | ||
Thread.sleep(3_000) | ||
onView(withId(R.id.email)).check(matches(withText("[email protected]"))) | ||
onView(withId(R.id.email)).check(matches(withText("Authentication error"))) | ||
} | ||
|
||
@Test | ||
fun logInIncorrect() { | ||
val username = "johnyyy@test.com" | ||
fun createAccountIncorrect() { | ||
val username = "john@test.com" | ||
val password = "password" | ||
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) | ||
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) | ||
onView(withId(R.id.logIn)).perform(click()) | ||
onView(withId(R.id.createAcc)).perform(click()) | ||
Thread.sleep(3_000) | ||
onView(withId(R.id.email)).check(matches(withText("Authentication error"))) | ||
} | ||
|
||
@Test | ||
fun createAccountIncorrect() { | ||
val username = "[email protected]" | ||
fun stringValidationEmptyUsername() { | ||
onView(withId(R.id.createAcc)).perform(click()) | ||
onView(withId(R.id.email)).check(matches(withText("Empty email or password"))) | ||
} | ||
|
||
@Test | ||
fun stringValidationEmptyUPassword() { | ||
onView(withId(R.id.createAcc)).perform(click()) | ||
onView(withId(R.id.email)).check(matches(withText("Empty email or password"))) | ||
} | ||
|
||
@Test | ||
fun stringValidationWrongEmail() { | ||
val username = "john" | ||
val password = "password" | ||
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) | ||
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) | ||
onView(withId(R.id.createAcc)).perform(click()) | ||
onView(withId(R.id.email)).check(matches(withText("Not an email"))) | ||
} | ||
|
||
@Test | ||
fun stringValidationShorPassword() { | ||
val username = "[email protected]" | ||
val password = "12345" | ||
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) | ||
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) | ||
onView(withId(R.id.createAcc)).perform(click()) | ||
onView(withId(R.id.email)).check(matches(withText("Password has to be at least 6 symbols"))) | ||
} | ||
|
||
@Test | ||
fun derinTest() { | ||
val a = FireBaseAuthenticator() | ||
a.googleActivityResult(-1,-1,null) | ||
onView(withId(R.id.email)).check(matches(withText("TextView"))) | ||
} | ||
|
||
@Test | ||
fun ardaTest() { | ||
val a = FireBaseAuthenticator() | ||
a.googleActivityResult(1000,-1,null) | ||
onView(withId(R.id.email)).check(matches(withText("TextView"))) | ||
} | ||
|
||
@Test | ||
fun logInCorrect() { | ||
val username = "[email protected]" | ||
val password = "password" | ||
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) | ||
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) | ||
onView(withId(R.id.logIn)).perform(click()) | ||
Thread.sleep(3_000) | ||
onView(withId(R.id.email)).check(matches(withText("Authentication error"))) | ||
onView(withId(R.id.email)).check(matches(withText("[email protected]"))) | ||
} | ||
|
||
@Test | ||
|
@@ -85,5 +130,4 @@ class SignInActivityTest { | |
} | ||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import com.google.firebase.auth.AuthResult | |
|
||
class Register : AppCompatActivity() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May add javadoc to class and methods ! Maybe some comments too |
||
|
||
// private lateinit var googleSignInClient: GoogleSignInClient | ||
private lateinit var googleSignInClient: GoogleSignInClient | ||
|
||
private lateinit var authenticator: FireBaseAuthenticator | ||
|
||
|
@@ -27,61 +27,79 @@ class Register : AppCompatActivity() { | |
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_google_log_in) | ||
|
||
// @FixMe | ||
// Commenting this for now until we find a proper way to test it, then will merge it to main | ||
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | ||
.requestEmail() | ||
.build() | ||
|
||
// val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | ||
// .requestEmail() | ||
// .build() | ||
|
||
// googleSignInClient = GoogleSignIn.getClient(this, gso) | ||
|
||
// Initialize Firebase Auth | ||
googleSignInClient = GoogleSignIn.getClient(this, gso) | ||
authenticator = FireBaseAuthenticator() | ||
|
||
val btCreateAcc = findViewById<Button>(R.id.createAcc) | ||
val btLogIn = findViewById<Button>(R.id.logIn) | ||
// val googleSignIn = findViewById<Button>(R.id.googleBtn) | ||
|
||
val googleSignIn = findViewById<Button>(R.id.googleBtn) | ||
|
||
val username = findViewById<EditText>(R.id.username) | ||
val password = findViewById<EditText>(R.id.password) | ||
email = findViewById<TextView>(R.id.email) | ||
email = findViewById(R.id.email) | ||
|
||
btCreateAcc.setOnClickListener { | ||
createAccount(username.text.toString(), password.text.toString()) | ||
authenticate(username.text.toString(), password.text.toString(), true) | ||
} | ||
|
||
btLogIn.setOnClickListener { | ||
signIn(username.text.toString(), password.text.toString()) | ||
authenticate(username.text.toString(), password.text.toString(), false) | ||
} | ||
|
||
// googleSignIn.setOnClickListener { | ||
// signInGoogle() | ||
// } | ||
|
||
|
||
googleSignIn.setOnClickListener { | ||
signInGoogle() | ||
} | ||
} | ||
|
||
public override fun onStart() { | ||
super.onStart() | ||
val currentUser = authenticator.auth.currentUser | ||
if (currentUser != null) { | ||
reload(); | ||
reload() | ||
} | ||
} | ||
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
updateUI(authenticator.googleActivityResult(requestCode, resultCode, data)); | ||
} | ||
|
||
private fun stringValidation(username: String, password: String): Boolean{ | ||
if(username.isEmpty() || password.isEmpty()) { | ||
email.text = "Empty email or password" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be using string.xml |
||
return false | ||
} | ||
|
||
if(!username.contains('@')) { | ||
email.text = "Not an email" | ||
return false | ||
} | ||
|
||
if(password.length < 6) { | ||
email.text = "Password has to be at least 6 symbols" | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
private fun authenticate(email: String, password: String, creatAcc: Boolean) { | ||
if(stringValidation(email, password)) { | ||
if(creatAcc) { | ||
createAccount(email, password) | ||
} | ||
else { | ||
signIn(email, password) | ||
} | ||
} | ||
} | ||
|
||
// @FixMe | ||
// Commenting this for now until we find a proper way to test it, then will merge it to main | ||
// public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
// super.onActivityResult(requestCode, resultCode, data) | ||
// updateUI(authenticator.googleActivityResult(requestCode, resultCode, data)); | ||
// } | ||
|
||
// private fun signInGoogle() { | ||
// val intent = googleSignInClient.signInIntent | ||
// startActivityForResult(intent, 1000) | ||
// } | ||
private fun signInGoogle() { | ||
val intent = googleSignInClient.signInIntent | ||
startActivityForResult(intent, 1000) | ||
} | ||
|
||
private fun createAccount(email: String, password: String) { | ||
authenticator.createAccount(email, password) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,18 +31,17 @@ class FireBaseAuthenticator() { | |
|
||
// @FixMe | ||
// Commenting this for now until we find a proper way to test it, then will merge it to main | ||
// fun googleActivityResult(requestCode: Int, resultCode: Int, data: Intent?): String? { | ||
// return if(requestCode == 1000) { | ||
// val task = GoogleSignIn.getSignedInAccountFromIntent(data) | ||
// try { | ||
// val account = task.getResult(ApiException::class.java)!! | ||
// account.email | ||
// } catch (e: ApiException) { | ||
// "Authentication error" | ||
// } | ||
// } else { | ||
// "Authentication error" | ||
// } | ||
// } | ||
|
||
fun googleActivityResult(requestCode: Int, resultCode: Int, data: Intent?): String? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc ? javadoc ? |
||
return if(requestCode == 1000) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe replace this magic number by a more meaningful name |
||
val task = GoogleSignIn.getSignedInAccountFromIntent(data) | ||
try { | ||
val account = task.getResult(ApiException::class.java)!! | ||
account.email | ||
} catch (e: ApiException) { | ||
"Authentication error" | ||
} | ||
} else { | ||
"Authentication error" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ package ch.sdp.vibester.profile | |
|
||
class ProfileDataProvider(userID: String, users: List<UserProfile> = emptyList(), scoreboard: List<Int> = emptyList()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc ? |
||
private lateinit var user: UserProfile | ||
private val userID:Int = userID.toInt() | ||
private val userID: Int = userID.toInt() | ||
private lateinit var users: List<UserProfile> | ||
private lateinit var scoreboard: List<Int> | ||
|
||
|
@@ -53,7 +53,7 @@ class ProfileDataProvider(userID: String, users: List<UserProfile> = emptyList() | |
/** | ||
* Retrieve profile data of user. | ||
*/ | ||
private fun getUserData():UserProfile { | ||
private fun getUserData(): UserProfile { | ||
return users[userID] | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a "TextView" here, is it shown explicitly on the screen?