Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Game Client Android
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
22
Issues
22
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Akamu
Game Client Android
Commits
f54fd033
Commit
f54fd033
authored
Nov 06, 2020
by
Antonia Wüst
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
#64
parent
f66f6925
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
49 deletions
+89
-49
app/src/main/java/de/akamu/tudarmstadt/features/password/ChangePasswordActivity.kt
...u/tudarmstadt/features/password/ChangePasswordActivity.kt
+31
-12
app/src/main/java/de/akamu/tudarmstadt/features/password/ChangePasswordContract.kt
...u/tudarmstadt/features/password/ChangePasswordContract.kt
+6
-0
app/src/main/java/de/akamu/tudarmstadt/features/password/ChangePasswordPresenter.kt
.../tudarmstadt/features/password/ChangePasswordPresenter.kt
+48
-35
app/src/main/java/de/akamu/tudarmstadt/features/signup/password/PasswordFragment.kt
.../tudarmstadt/features/signup/password/PasswordFragment.kt
+4
-2
No files found.
app/src/main/java/de/akamu/tudarmstadt/features/password/ChangePasswordActivity.kt
View file @
f54fd033
...
...
@@ -10,6 +10,7 @@ import de.akamu.tudarmstadt.data.user.UserDataSourceImpl
import
de.akamu.tudarmstadt.interactors.UserInteractor
import
de.akamu.tudarmstadt.model.User
import
de.akamu.tudarmstadt.util.AppUserUtil
import
de.akamu.tudarmstadt.util.Constants
import
kotlinx.android.synthetic.main.activity_change_password.*
class
ChangePasswordActivity
:
...
...
@@ -19,7 +20,7 @@ class ChangePasswordActivity :
override
lateinit
var
presenter
:
ChangePasswordContract
.
Presenter
private
var
user
:
User
?
=
null
private
var
user
:
User
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -38,7 +39,8 @@ class ChangePasswordActivity :
}
override
fun
onClick
(
v
:
View
?)
{
if
(
v
!!
.
id
==
changepw_confirm_btn
.
id
)
{
if
(
v
!!
.
id
==
changepw_confirm_btn
.
id
)
{
enableChangePasswordButton
(
false
)
val
currentPw
=
changepw_current
.
text
.
toString
()
val
newPw
=
changepw_new
.
text
.
toString
()
val
newPw2
=
changepw_confirm_new
.
text
.
toString
()
...
...
@@ -47,13 +49,17 @@ class ChangePasswordActivity :
}
override
fun
showChangePasswordSuccess
()
{
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
R
.
string
.
password_changed
,
Snackbar
.
LENGTH_LONG
).
show
()
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
R
.
string
.
password_changed
,
Snackbar
.
LENGTH_LONG
).
show
()
}
override
fun
showChangePasswordFailed
(
reason
:
String
)
{
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
getString
(
R
.
string
.
failed_to_change_password
)
+
reason
,
Snackbar
.
LENGTH_LONG
).
show
()
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
getString
(
R
.
string
.
failed_to_change_password
)
+
reason
,
Snackbar
.
LENGTH_LONG
).
show
()
}
override
fun
hideProgress
()
{
...
...
@@ -66,19 +72,28 @@ class ChangePasswordActivity :
}
override
fun
showPasswordIncorrect
()
{
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
getString
(
R
.
string
.
failed_to_change_password
)
+
getString
(
R
.
string
.
error_invalid_password
),
Snackbar
.
LENGTH_LONG
).
show
()
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
getString
(
R
.
string
.
failed_to_change_password
)
+
getString
(
R
.
string
.
error_invalid_password
),
Snackbar
.
LENGTH_LONG
).
show
()
changepw_current
.
error
=
getString
(
R
.
string
.
error_invalid_password
)
}
override
fun
showPasswordsMismatch
()
{
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
getString
(
R
.
string
.
failed_to_change_password
)
+
getString
(
R
.
string
.
error_invalid_password_notequal
),
Snackbar
.
LENGTH_LONG
).
show
()
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
getString
(
R
.
string
.
failed_to_change_password
)
+
getString
(
R
.
string
.
error_invalid_password_notequal
),
Snackbar
.
LENGTH_LONG
).
show
()
}
override
fun
showPasswordTooShort
()
{
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
getString
(
R
.
string
.
failed_to_change_password
)
+
getString
(
R
.
string
.
error_invalid_password_short
),
Snackbar
.
LENGTH_LONG
).
show
()
Snackbar
.
make
(
findViewById
(
R
.
id
.
coordinator_change_password
),
getString
(
R
.
string
.
failed_to_change_password
)
+
getString
(
R
.
string
.
error_invalid_password_short
),
Snackbar
.
LENGTH_LONG
).
show
()
}
override
fun
showOldPasswordEmpty
()
{
...
...
@@ -93,4 +108,8 @@ class ChangePasswordActivity :
override
fun
handleUnauthorizedEvent
()
{
//Don't handle unauthorized event
}
override
fun
enableChangePasswordButton
(
isEnabled
:
Boolean
)
{
changepw_confirm_btn
.
isEnabled
=
isEnabled
}
}
app/src/main/java/de/akamu/tudarmstadt/features/password/ChangePasswordContract.kt
View file @
f54fd033
...
...
@@ -9,8 +9,10 @@ interface ChangePasswordContract {
interface
View
:
BaseView
<
Presenter
>
{
/** Let the user know that changing his/her password was successful **/
fun
showChangePasswordSuccess
()
/** Let the user know that changing his/her password has failed due to [reason] **/
fun
showChangePasswordFailed
(
reason
:
String
)
/** Show an indeterminate progress bar to the user while processing the changed password **/
fun
showPasswordGetsVerified
()
fun
showPasswordIncorrect
()
...
...
@@ -18,8 +20,12 @@ interface ChangePasswordContract {
fun
showPasswordTooShort
()
fun
showUpdatingPassword
()
fun
showOldPasswordEmpty
()
/** Hide the indeterminate progress bar, that is shown to the user while processing the changed password **/
fun
hideProgress
()
/** Enables / Disables change password button **/
fun
enableChangePasswordButton
(
isEnabled
:
Boolean
)
}
interface
Presenter
:
BasePresenter
{
...
...
app/src/main/java/de/akamu/tudarmstadt/features/password/ChangePasswordPresenter.kt
View file @
f54fd033
...
...
@@ -7,10 +7,11 @@ import de.akamu.tudarmstadt.interactors.UserInteractor
import
de.akamu.tudarmstadt.model.User
import
de.akamu.tudarmstadt.util.Constants
class
ChangePasswordPresenter
(
private
val
interactor
:
PasswordInteractor
,
private
val
userInteractor
:
UserInteractor
,
private
var
view
:
ChangePasswordContract
.
View
?)
:
ChangePasswordContract
.
Presenter
{
class
ChangePasswordPresenter
(
private
val
interactor
:
PasswordInteractor
,
private
val
userInteractor
:
UserInteractor
,
private
var
view
:
ChangePasswordContract
.
View
?
)
:
ChangePasswordContract
.
Presenter
{
init
{
view
?.
presenter
=
this
...
...
@@ -20,11 +21,13 @@ class ChangePasswordPresenter(private val interactor: PasswordInteractor,
if
(
currentPw
.
isEmpty
())
{
view
?.
showOldPasswordEmpty
()
view
?.
enableChangePasswordButton
(
true
)
return
}
// Check if new passwords are valid
if
(!
isPasswordValid
(
newPw
,
newPw2
))
{
if
(!
isPasswordValid
(
newPw
,
newPw2
))
{
view
?.
enableChangePasswordButton
(
true
)
return
}
...
...
@@ -33,22 +36,28 @@ class ChangePasswordPresenter(private val interactor: PasswordInteractor,
AkamuFirebase
.
loadFirebaseToken
(
object
:
AkamuFirebase
.
GetFirebaseTokenCallback
{
override
fun
onGetFirebaseTokenSuccess
(
firebaseToken
:
String
)
{
interactor
.
verifyPassword
(
user
,
currentPw
,
firebaseToken
,
object
:
PasswordDataSource
.
VerifyPasswordCallback
{
override
fun
passwordCorrect
()
{
user
.
password
=
newPw
updateUserWithNewPW
(
newPw
)
}
override
fun
passwordInCorrect
()
{
view
?.
showPasswordIncorrect
()
view
?.
hideProgress
()
}
override
fun
passwordError
(
msg
:
String
)
{
view
?.
showChangePasswordFailed
(
msg
)
view
?.
hideProgress
()
}
})
interactor
.
verifyPassword
(
user
,
currentPw
,
firebaseToken
,
object
:
PasswordDataSource
.
VerifyPasswordCallback
{
override
fun
passwordCorrect
()
{
user
.
password
=
newPw
updateUserWithNewPW
(
newPw
)
}
override
fun
passwordInCorrect
()
{
view
?.
showPasswordIncorrect
()
view
?.
hideProgress
()
view
?.
enableChangePasswordButton
(
true
)
}
override
fun
passwordError
(
msg
:
String
)
{
view
?.
showChangePasswordFailed
(
msg
)
view
?.
hideProgress
()
view
?.
enableChangePasswordButton
(
true
)
}
})
}
override
fun
onGetFirebaseTokenFail
(
error
:
String
)
{
...
...
@@ -62,14 +71,14 @@ class ChangePasswordPresenter(private val interactor: PasswordInteractor,
view
=
null
}
private
fun
isPasswordValid
(
newPw
:
String
,
newPw2
:
String
)
:
Boolean
{
private
fun
isPasswordValid
(
newPw
:
String
,
newPw2
:
String
):
Boolean
{
if
(
newPw
.
isEmpty
()
||
newPw2
.
isEmpty
()
||
newPw
.
length
<
Constants
.
MIN_PASSWORD_LENGTH
)
{
if
(
newPw
.
isEmpty
()
||
newPw2
.
isEmpty
()
||
newPw
.
length
<
Constants
.
MIN_PASSWORD_LENGTH
)
{
view
?.
showPasswordTooShort
()
return
false
}
if
(
newPw
!=
newPw2
)
{
if
(
newPw
!=
newPw2
)
{
view
?.
showPasswordsMismatch
()
return
false
}
...
...
@@ -81,17 +90,21 @@ class ChangePasswordPresenter(private val interactor: PasswordInteractor,
private
fun
updateUserWithNewPW
(
newPassword
:
String
)
{
view
?.
showUpdatingPassword
()
userInteractor
.
updateUserPasswordInServer
(
newPassword
,
object
:
UserDataSource
.
UpdateUserCallback
{
override
fun
onUpdateUserSuccess
()
{
view
?.
showChangePasswordSuccess
()
view
?.
hideProgress
()
}
override
fun
onUpdateUserFail
(
reason
:
String
)
{
view
?.
showChangePasswordFailed
(
reason
)
view
?.
hideProgress
()
}
})
userInteractor
.
updateUserPasswordInServer
(
newPassword
,
object
:
UserDataSource
.
UpdateUserCallback
{
override
fun
onUpdateUserSuccess
()
{
view
?.
showChangePasswordSuccess
()
view
?.
hideProgress
()
view
?.
enableChangePasswordButton
(
true
)
}
override
fun
onUpdateUserFail
(
reason
:
String
)
{
view
?.
showChangePasswordFailed
(
reason
)
view
?.
hideProgress
()
view
?.
enableChangePasswordButton
(
true
)
}
})
}
}
\ No newline at end of file
app/src/main/java/de/akamu/tudarmstadt/features/signup/password/PasswordFragment.kt
View file @
f54fd033
...
...
@@ -40,8 +40,10 @@ class PasswordFragment : Fragment(), PasswordContract.View, Step {
val
v
=
inflater
.
inflate
(
R
.
layout
.
fragment_password
,
container
,
false
)
presenter
=
PasswordPresenter
(
this
)
errorStringTooShort
=
getString
(
R
.
string
.
error_invalid_password_short
)
errorStringTooLong
=
getString
(
R
.
string
.
error_invalid_password_long
)
errorStringTooShort
=
getString
(
R
.
string
.
error_invalid_password_short
,
Constants
.
MIN_PASSWORD_LENGTH
)
errorStringTooLong
=
getString
(
R
.
string
.
error_invalid_password_long
,
Constants
.
MAX_PASSWORD_LENGTH
)
errorStringNotEqual
=
getString
(
R
.
string
.
error_invalid_password_notequal
)
errorStringNotUpperLower
=
getString
(
R
.
string
.
error_invalid_password_notupperlower
)
return
v
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment