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
73d78ad2
Commit
73d78ad2
authored
Dec 24, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove RC client creation and format the code.
parent
dff143c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
82 deletions
+66
-82
LoginPresenter.kt
...droid/authentication/login/presentation/LoginPresenter.kt
+31
-33
SignupPresenter.kt
...oid/authentication/signup/presentation/SignupPresenter.kt
+32
-36
TwoFAPresenter.kt
...d/authentication/twofactor/presentation/TwoFAPresenter.kt
+3
-13
No files found.
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginPresenter.kt
View file @
73d78ad2
package
chat.rocket.android.authentication.login.presentation
import
android.widget.EditText
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.util.launchUI
import
chat.rocket.android.util.textContent
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatTwoFactorException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.chatRooms
import
chat.rocket.core.internal.rest.getRoomFavoriteMessages
import
chat.rocket.core.internal.rest.login
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
chat.rocket.core.internal.rest.sendMessage
import
timber.log.Timber
import
javax.inject.Inject
class
LoginPresenter
@Inject
constructor
(
private
val
view
:
LoginView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
// TODO: Create a single entry point to RocketChatClient
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
websocketUrl
=
navigator
.
currentServer
!!
tokenRepository
=
repository
platformLogger
=
logger
}
private
val
navigator
:
AuthenticationNavigator
)
{
@Inject
lateinit
var
client
:
RocketChatClient
fun
authenticate
(
usernameOrEmailEditText
:
EditText
,
passwordEditText
:
EditText
)
{
val
usernameOrEmail
=
usernameOrEmailEditText
.
textContent
val
password
=
passwordEditText
.
textContent
when
{
usernameOrEmail
.
isBlank
()
->
view
.
shakeView
(
usernameOrEmailEditText
)
password
.
isEmpty
()
->
view
.
shakeView
(
passwordEditText
)
else
->
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
val
token
=
client
.
login
(
usernameOrEmail
,
password
)
// TODO: Salve token.
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
when
(
ex
)
{
is
RocketChatTwoFactorException
->
navigator
.
toTwoFA
(
navigator
.
currentServer
!!
,
usernameOrEmail
,
password
)
else
->
{
val
errorMessage
=
ex
.
message
if
(
errorMessage
!=
null
)
{
view
.
showMessage
(
errorMessage
)
usernameOrEmail
.
isBlank
()
->
{
view
.
shakeView
(
usernameOrEmailEditText
)
}
password
.
isEmpty
()
->
{
view
.
shakeView
(
passwordEditText
)
}
else
->
{
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
val
token
=
client
.
login
(
usernameOrEmail
,
password
)
Timber
.
d
(
"Created token: $token"
)
navigator
.
toChatList
()
}
catch
(
rocketChatException
:
RocketChatException
)
{
when
(
rocketChatException
)
{
is
RocketChatTwoFactorException
->
{
navigator
.
toTwoFA
(
navigator
.
currentServer
!!
,
usernameOrEmail
,
password
)
}
else
->
{
val
errorMessage
=
rocketChatException
.
message
if
(
errorMessage
!=
null
)
{
view
.
showMessage
(
errorMessage
)
}
}
}
}
finally
{
view
.
hideLoading
()
}
}
finally
{
view
.
hideLoading
()
}
}
}
...
...
app/src/main/java/chat/rocket/android/authentication/signup/presentation/SignupPresenter.kt
View file @
73d78ad2
package
chat.rocket.android.authentication.signup.presentation
import
android.widget.EditText
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.util.launchUI
import
chat.rocket.android.util.textContent
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.signup
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
timber.log.Timber
import
javax.inject.Inject
class
SignupPresenter
@Inject
constructor
(
private
val
view
:
SignupView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
// TODO: Create a single entry point to RocketChatClient
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
websocketUrl
=
navigator
.
currentServer
!!
tokenRepository
=
repository
platformLogger
=
logger
}
private
val
navigator
:
AuthenticationNavigator
)
{
@Inject
lateinit
var
client
:
RocketChatClient
fun
signup
(
nameEditText
:
EditText
,
emailEditText
:
EditText
,
usernameEditText
:
EditText
,
password
EditText
:
EditText
)
{
fun
signup
(
nameEditText
:
EditText
,
usernameEditText
:
EditText
,
passwordEditText
:
EditText
,
email
EditText
:
EditText
)
{
val
name
=
nameEditText
.
textContent
val
email
=
emailEditText
.
textContent
val
username
=
usernameEditText
.
textContent
val
password
=
passwordEditText
.
textContent
val
email
=
emailEditText
.
textContent
when
{
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
()
name
.
isBlank
()
->
{
view
.
shakeView
(
nameEditText
)
}
username
.
isBlank
()
->
{
view
.
shakeView
(
usernameEditText
)
}
password
.
isEmpty
()
->
{
view
.
shakeView
(
passwordEditText
)
}
email
.
isBlank
()
->
{
view
.
shakeView
(
emailEditText
)
}
else
->
{
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
val
user
=
client
.
signup
(
email
,
name
,
username
,
password
)
Timber
.
d
(
"Created user: $user"
)
try
{
val
user
=
client
.
signup
(
email
,
name
,
username
,
password
)
Timber
.
d
(
"Created user: $user"
)
val
token
=
client
.
login
(
username
,
password
)
Timber
.
d
(
"Logged in: $token"
)
val
token
=
client
.
login
(
username
,
password
)
Timber
.
d
(
"Logged in: $token"
)
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
val
errorMessage
=
ex
.
message
if
(
errorMessage
!=
null
)
{
view
.
showMessage
(
errorMessage
)
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
val
errorMessage
=
ex
.
message
if
(
errorMessage
!=
null
)
{
view
.
showMessage
(
errorMessage
)
}
}
finally
{
view
.
hideLoading
()
}
}
finally
{
view
.
hideLoading
()
}
}
}
...
...
app/src/main/java/chat/rocket/android/authentication/twofactor/presentation/TwoFAPresenter.kt
View file @
73d78ad2
...
...
@@ -16,22 +16,12 @@ import javax.inject.Inject
class
TwoFAPresenter
@Inject
constructor
(
private
val
view
:
TwoFAView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
// TODO: Create a single entry point to RocketChatClient
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
websocketUrl
=
navigator
.
currentServer
!!
tokenRepository
=
repository
platformLogger
=
logger
}
private
val
navigator
:
AuthenticationNavigator
)
{
@Inject
lateinit
var
client
:
RocketChatClient
// 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)
fun
authenticate
(
usernameOrEmail
:
String
,
password
:
String
,
pin
:
EditText
)
{
val
twoFACode
=
pin
.
textContent
val
twoFACode
=
pin
.
textContent
if
(
twoFACode
.
isBlank
())
{
view
.
shakeView
(
pin
)
}
else
{
...
...
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