Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
e63200ef
Commit
e63200ef
authored
Dec 22, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add TODO and validate inputs.
parent
9f2c01e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
31 deletions
+51
-31
SignupPresenter.kt
...oid/authentication/signup/presentation/SignupPresenter.kt
+29
-15
TwoFAPresenter.kt
...d/authentication/twofactor/presentation/TwoFAPresenter.kt
+22
-16
No files found.
app/src/main/java/chat/rocket/android/authentication/signup/presentation/SignupPresenter.kt
View file @
e63200ef
package
chat.rocket.android.authentication.signup.presentation
package
chat.rocket.android.authentication.signup.presentation
import
android.widget.EditText
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.util.launchUI
import
chat.rocket.android.util.launchUI
import
chat.rocket.android.util.textContent
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.RocketChatClient
...
@@ -20,7 +22,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
...
@@ -20,7 +22,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
private
val
okHttpClient
:
OkHttpClient
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
private
val
repository
:
AuthTokenRepository
)
{
// TODO: Create a single entry point to RocketChatClient
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
...
@@ -29,24 +31,36 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
...
@@ -29,24 +31,36 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
platformLogger
=
logger
platformLogger
=
logger
}
}
fun
signup
(
email
:
String
,
name
:
String
,
username
:
String
,
password
:
String
)
{
fun
signup
(
nameEditText
:
EditText
,
emailEditText
:
EditText
,
usernameEditText
:
EditText
,
passwordEditText
:
EditText
)
{
// TODO - validate input
val
name
=
nameEditText
.
textContent
val
email
=
emailEditText
.
textContent
val
username
=
usernameEditText
.
textContent
val
password
=
passwordEditText
.
textContent
launchUI
(
strategy
)
{
when
{
view
.
showLoading
()
name
.
isBlank
()
->
view
.
shakeView
(
nameEditText
)
email
.
isBlank
()
->
view
.
shakeView
(
emailEditText
)
username
.
isBlank
()
->
view
.
shakeView
(
usernameEditText
)
password
.
isEmpty
()
->
view
.
shakeView
(
passwordEditText
)
else
->
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
try
{
val
user
=
client
.
signup
(
email
,
name
,
username
,
password
)
val
user
=
client
.
signup
(
email
,
name
,
username
,
password
)
Timber
.
d
(
"Created user: $user"
)
Timber
.
d
(
"Created user: $user"
)
val
token
=
client
.
login
(
username
,
password
)
val
token
=
client
.
login
(
username
,
password
)
Timber
.
d
(
"Logged in: $token"
)
Timber
.
d
(
"Logged in: $token"
)
navigator
.
toChatList
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
}
catch
(
ex
:
RocketChatException
)
{
view
.
onSignupError
(
ex
.
message
)
val
errorMessage
=
ex
.
message
}
finally
{
if
(
errorMessage
!=
null
)
{
view
.
hideLoading
()
view
.
showMessage
(
errorMessage
)
}
}
finally
{
view
.
hideLoading
()
}
}
}
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/authentication/twofactor/presentation/TwoFAPresenter.kt
View file @
e63200ef
package
chat.rocket.android.authentication.twofactor.presentation
package
chat.rocket.android.authentication.twofactor.presentation
import
android.widget.EditText
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.util.launchUI
import
chat.rocket.android.util.launchUI
import
chat.rocket.android.util.textContent
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.RocketChatClient
...
@@ -18,7 +20,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
...
@@ -18,7 +20,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
private
val
okHttpClient
:
OkHttpClient
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
private
val
repository
:
AuthTokenRepository
)
{
// TODO: Create a single entry point to RocketChatClient
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
...
@@ -27,22 +29,26 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
...
@@ -27,22 +29,26 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
platformLogger
=
logger
platformLogger
=
logger
}
}
fun
authenticate
(
username
:
String
,
password
:
String
,
pin
:
String
)
{
// TODO: If the usernameOrEmail and password was informed by the user on the previous screen, then we should pass only the pin, like this: fun authenticate(pin: EditText)
// TODO - validate input
fun
authenticate
(
usernameOrEmail
:
String
,
password
:
String
,
pin
:
EditText
)
{
val
twoFACode
=
pin
.
textContent
launchUI
(
strategy
)
{
if
(
twoFACode
.
isBlank
())
{
view
.
showLoading
()
view
.
shakeView
(
pin
)
try
{
}
else
{
val
token
=
client
.
login
(
username
,
password
,
pin
)
launchUI
(
strategy
)
{
view
.
showLoading
()
navigator
.
toChatList
()
try
{
}
catch
(
ex
:
RocketChatException
)
{
val
token
=
client
.
login
(
usernameOrEmail
,
password
,
twoFACode
)
val
errorMessage
=
ex
.
message
// Todo Salve token.
if
(
errorMessage
!=
null
)
{
navigator
.
toChatList
()
view
.
showMessage
(
errorMessage
)
}
catch
(
ex
:
RocketChatException
)
{
val
errorMessage
=
ex
.
message
if
(
errorMessage
!=
null
)
{
view
.
showMessage
(
errorMessage
)
}
}
finally
{
view
.
hideLoading
()
}
}
}
finally
{
view
.
hideLoading
()
}
}
}
}
}
}
...
...
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