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
43391e73
Commit
43391e73
authored
Dec 11, 2017
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Two Factor auth.
parent
b376f450
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
173 additions
and
6 deletions
+173
-6
TwoFAFragmentModule.kt
...t/rocket/android/authentication/di/TwoFAFragmentModule.kt
+16
-0
TwoFAFragmentProvider.kt
...rocket/android/authentication/di/TwoFAFragmentProvider.kt
+11
-0
AuthenticationNavigator.kt
...id/authentication/presentation/AuthenticationNavigator.kt
+9
-0
LoginPresenter.kt
...ket/android/authentication/presentation/LoginPresenter.kt
+7
-0
TwoFAPresenter.kt
...ket/android/authentication/presentation/TwoFAPresenter.kt
+57
-0
TwoFAView.kt
...t/rocket/android/authentication/presentation/TwoFAView.kt
+3
-0
TwoFAFragment.kt
...va/chat/rocket/android/authentication/ui/TwoFAFragment.kt
+67
-1
ActivityBuilder.kt
...java/chat/rocket/android/dagger/module/ActivityBuilder.kt
+3
-5
No files found.
app/src/main/java/chat/rocket/android/authentication/di/TwoFAFragmentModule.kt
0 → 100644
View file @
43391e73
package
chat.rocket.android.authentication.di
import
chat.rocket.android.authentication.presentation.LoginView
import
chat.rocket.android.authentication.presentation.TwoFAView
import
chat.rocket.android.authentication.ui.LoginFragment
import
chat.rocket.android.authentication.ui.TwoFAFragment
import
dagger.Module
import
dagger.Provides
@Module
class
TwoFAFragmentModule
{
@Provides
fun
loginView
(
frag
:
TwoFAFragment
):
TwoFAView
{
return
frag
}
}
app/src/main/java/chat/rocket/android/authentication/di/TwoFAFragmentProvider.kt
0 → 100644
View file @
43391e73
package
chat.rocket.android.authentication.di
import
chat.rocket.android.authentication.ui.TwoFAFragment
import
dagger.Module
import
dagger.android.ContributesAndroidInjector
@Module
abstract
class
TwoFAFragmentProvider
{
@ContributesAndroidInjector
(
modules
=
arrayOf
(
TwoFAFragmentModule
::
class
))
abstract
fun
provideTwoFAFragment
():
TwoFAFragment
}
app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt
View file @
43391e73
...
...
@@ -6,6 +6,7 @@ import chat.rocket.android.app.MainActivity
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.authentication.ui.LoginFragment
import
chat.rocket.android.authentication.ui.SignupFragment
import
chat.rocket.android.authentication.ui.TwoFAFragment
import
chat.rocket.android.util.addFragmentBackStack
class
AuthenticationNavigator
(
internal
val
activity
:
AuthenticationActivity
)
{
...
...
@@ -26,7 +27,15 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
activity
.
finish
()
}
fun
toTwoFA
(
server
:
String
,
username
:
String
,
password
:
String
)
{
currentServer
=
server
activity
.
addFragmentBackStack
(
"twoFAFragment"
,
R
.
id
.
fragment_container
)
{
TwoFAFragment
.
newInstance
(
server
,
username
,
password
)
}
}
fun
toSignUp
(
server
:
String
)
{
currentServer
=
server
activity
.
addFragmentBackStack
(
"signupFragment"
,
R
.
id
.
fragment_container
)
{
SignupFragment
.
newInstance
(
server
)
}
...
...
app/src/main/java/chat/rocket/android/authentication/presentation/LoginPresenter.kt
View file @
43391e73
package
chat.rocket.android.authentication.presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.common.RocketChatAuthException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
...
...
@@ -39,6 +40,12 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
view
.
hideProgress
()
when
(
ex
)
{
is
RocketChatAuthException
->
if
(
ex
.
error
?.
contentEquals
(
"totp-required"
)
==
true
)
{
navigator
.
toTwoFA
(
navigator
.
currentServer
!!
,
username
,
password
)
}
}
view
.
onLoginError
(
ex
.
message
)
}
}
...
...
app/src/main/java/chat/rocket/android/authentication/presentation/TwoFAPresenter.kt
0 → 100644
View file @
43391e73
package
chat.rocket.android.authentication.presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.launch
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
javax.inject.Inject
class
TwoFAPresenter
@Inject
constructor
(
private
val
view
:
TwoFAView
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
var
job
:
Job
?
=
null
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
websocketUrl
=
navigator
.
currentServer
!!
tokenRepository
=
repository
platformLogger
=
logger
}
fun
authenticate
(
username
:
String
,
password
:
String
,
pin
:
String
)
{
// TODO - validate input
job
=
launch
(
UI
)
{
view
.
showProgress
()
try
{
val
token
=
client
.
login
(
username
,
password
,
pin
)
view
.
hideProgress
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
view
.
hideProgress
()
view
.
onLoginError
(
ex
.
message
)
}
}
}
fun
unbind
()
{
job
?.
let
{
it
.
cancel
()
}.
also
{
null
}
}
fun
signup
()
{
navigator
.
toSignUp
(
navigator
.
currentServer
!!
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/presentation/TwoFAView.kt
0 → 100644
View file @
43391e73
package
chat.rocket.android.authentication.presentation
interface
TwoFAView
:
LoginView
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/ui/TwoFAFragment.kt
View file @
43391e73
package
chat.rocket.android.authentication.ui
import
DrawableHelper
import
android.app.ProgressDialog
import
android.os.Build
import
android.os.Bundle
import
android.support.v4.app.Fragment
...
...
@@ -8,10 +9,54 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.WindowManager
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.authentication.presentation.TwoFAPresenter
import
chat.rocket.android.authentication.presentation.TwoFAView
import
chat.rocket.android.util.content
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_two_fa.*
import
javax.inject.Inject
class
TwoFAFragment
:
Fragment
(),
TwoFAView
{
companion
object
{
private
const
val
SERVER_URL
=
"server_url"
private
const
val
USERNAME
=
"username"
private
const
val
PASSWORD
=
"password"
fun
newInstance
(
url
:
String
,
username
:
String
,
password
:
String
)
=
TwoFAFragment
().
apply
{
arguments
=
Bundle
(
1
).
apply
{
putString
(
SERVER_URL
,
url
)
putString
(
USERNAME
,
username
)
putString
(
PASSWORD
,
password
)
}
}
}
var
progress
:
ProgressDialog
?
=
null
lateinit
var
serverUrl
:
String
lateinit
var
username
:
String
lateinit
var
password
:
String
@Inject
lateinit
var
presenter
:
TwoFAPresenter
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
AndroidSupportInjection
.
inject
(
this
)
super
.
onCreate
(
savedInstanceState
)
// TODO - research a better way to initialize parameters on fragments.
serverUrl
=
arguments
?.
getString
(
SERVER_URL
)
?:
"https://open.rocket.chat"
username
=
arguments
?.
getString
(
USERNAME
)
?:
""
password
=
arguments
?.
getString
(
PASSWORD
)
?:
""
}
override
fun
onDestroy
()
{
presenter
.
unbind
()
super
.
onDestroy
()
}
class
TwoFAFragment
:
Fragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
=
inflater
.
inflate
(
R
.
layout
.
fragment_authentication_two_fa
,
container
,
false
)
...
...
@@ -23,6 +68,10 @@ class TwoFAFragment : Fragment() {
if
(
Build
.
VERSION
.
SDK_INT
<=
Build
.
VERSION_CODES
.
M
)
{
tintEditTextDrawableStart
()
}
button_log_in
.
setOnClickListener
{
presenter
.
authenticate
(
username
,
password
,
text_two_factor_auth
.
content
)
}
}
private
fun
tintEditTextDrawableStart
()
{
...
...
@@ -34,4 +83,21 @@ class TwoFAFragment : Fragment() {
DrawableHelper
.
compoundDrawable
(
text_two_factor_auth
,
lockDrawable
)
}
}
override
fun
showProgress
()
{
// TODO - change for a proper progress indicator
progress
=
ProgressDialog
.
show
(
activity
,
"Authenticating"
,
"Verifying user credentials"
)
}
override
fun
hideProgress
()
{
progress
?.
apply
{
cancel
()
}
progress
=
null
}
override
fun
onLoginError
(
message
:
String
?)
{
// TODO - show a proper error message
Toast
.
makeText
(
activity
,
message
,
Toast
.
LENGTH_LONG
).
show
()
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/dagger/module/ActivityBuilder.kt
View file @
43391e73
package
chat.rocket.android.dagger.module
import
chat.rocket.android.app.MainActivity
import
chat.rocket.android.authentication.di.AuthenticationModule
import
chat.rocket.android.authentication.di.LoginFragmentProvider
import
chat.rocket.android.authentication.di.ServerFragmentProvider
import
chat.rocket.android.authentication.di.SignupFragmentProvider
import
chat.rocket.android.authentication.di.*
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.dagger.scope.PerActivity
import
dagger.Module
...
...
@@ -18,7 +15,8 @@ abstract class ActivityBuilder {
AuthenticationModule
::
class
,
LoginFragmentProvider
::
class
,
ServerFragmentProvider
::
class
,
SignupFragmentProvider
::
class
SignupFragmentProvider
::
class
,
TwoFAFragmentProvider
::
class
))
abstract
fun
bindAuthenticationActivity
():
AuthenticationActivity
...
...
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