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
a9d6efbc
Commit
a9d6efbc
authored
Dec 21, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate inputs
parent
223cacfb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
17 deletions
+30
-17
LoginPresenter.kt
...droid/authentication/login/presentation/LoginPresenter.kt
+30
-17
No files found.
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginPresenter.kt
View file @
a9d6efbc
package
chat.rocket.android.authentication.login.presentation
package
chat.rocket.android.authentication.login.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.RocketChatTwoFactorException
import
chat.rocket.common.RocketChatTwoFactorException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.common.util.PlatformLogger
...
@@ -19,7 +21,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
...
@@ -19,7 +21,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
private
val
okHttpClient
:
OkHttpClient
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
private
val
repository
:
AuthTokenRepository
)
{
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
...
@@ -28,27 +29,39 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
...
@@ -28,27 +29,39 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
platformLogger
=
logger
platformLogger
=
logger
}
}
fun
authenticate
(
username
:
String
,
password
:
String
)
{
fun
authenticate
(
usernameOrEmail
:
EditText
,
password
:
EditText
)
{
// TODO - validate input
val
user
=
usernameOrEmail
.
textContent
val
pass
=
password
.
textContent
if
(
user
.
isBlank
()
&&
pass
.
isEmpty
())
{
view
.
shakeView
(
usernameOrEmail
)
view
.
shakeView
(
password
)
}
else
if
(
user
.
isBlank
())
{
view
.
shakeView
(
usernameOrEmail
)
}
else
if
(
pass
.
isEmpty
())
{
view
.
shakeView
(
password
)
}
else
{
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
view
.
showLoading
()
view
.
showLoading
()
try
{
try
{
val
token
=
client
.
login
(
username
,
password
)
val
token
=
client
.
login
(
user
,
pass
)
navigator
.
toChatList
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
}
catch
(
ex
:
RocketChatException
)
{
when
(
ex
)
{
when
(
ex
)
{
is
RocketChatTwoFactorException
->
is
RocketChatTwoFactorException
->
navigator
.
toTwoFA
(
navigator
.
currentServer
!!
,
user
,
pass
)
navigator
.
toTwoFA
(
navigator
.
currentServer
!!
,
username
,
password
)
else
->
{
else
->
val
errorMessage
=
ex
.
message
view
.
onLoginError
(
ex
.
message
)
if
(
errorMessage
!=
null
)
{
view
.
showMessage
(
errorMessage
)
}
}
}
}
}
finally
{
}
finally
{
view
.
hideLoading
()
view
.
hideLoading
()
}
}
}
}
}
}
}
fun
signup
()
{
fun
signup
()
{
navigator
.
toSignUp
(
navigator
.
currentServer
!!
)
navigator
.
toSignUp
(
navigator
.
currentServer
!!
)
...
...
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