Handle 2FA for instance user (#48)

This commit is contained in:
Schoumi 2024-05-16 21:21:40 +02:00
parent c56f33b7ab
commit 693c6088d1
7 changed files with 169 additions and 86 deletions

View File

@ -126,7 +126,7 @@ class CreateLiveActivity : AppCompatActivity() {
updateView(null)
}
override fun onError(error: String?) {
override fun onError(code: String?, error: String?) {
inError = true
updateView(error)
}
@ -150,7 +150,7 @@ class CreateLiveActivity : AppCompatActivity() {
updateView(null)
}
override fun onError(error: String?) {
override fun onError(code: String?, error: String?) {
inError = true
updateView(error)
}
@ -166,7 +166,7 @@ class CreateLiveActivity : AppCompatActivity() {
updateView(null)
}
override fun onError(error: String?) {
override fun onError(code: String?, error: String?) {
inError = true
updateView(error)
}
@ -190,7 +190,7 @@ class CreateLiveActivity : AppCompatActivity() {
updateView(null)
}
override fun onError(error: String?) {
override fun onError(code: String?, error: String?) {
inError = true
updateView(error)
}
@ -214,7 +214,7 @@ class CreateLiveActivity : AppCompatActivity() {
updateView(null)
}
override fun onError(error: String?) {
override fun onError(code: String?, error: String?) {
inError = true
updateView(error)
}
@ -238,7 +238,7 @@ class CreateLiveActivity : AppCompatActivity() {
updateView(null)
}
override fun onError(error: String?) {
override fun onError(code: String?, error: String?) {
inError = true
updateView(error)
}
@ -338,7 +338,7 @@ class CreateLiveActivity : AppCompatActivity() {
}
}
override fun onError(error: String?) {
override fun onError(code: String?, error: String?) {
runOnUiThread {
binding.error.text = error
binding.error.visibility = View.VISIBLE

View File

@ -20,6 +20,7 @@ import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import fr.mobdev.peertubelive.R
@ -45,11 +46,15 @@ class AddInstanceDialog : DialogFragment() {
builder.setPositiveButton(R.string.connect, null)
builder.setNegativeButton(R.string.cancel) { dialog,_ -> dialog.dismiss() }
builder.setView(binding.root)
isCancelable = false
binding.errorUsername.visibility = View.GONE
binding.errorInstance.visibility = View.GONE
binding.errorPassword.visibility = View.GONE
binding.tryConnect.visibility = View.GONE
binding.tryConnectMsg.visibility = View.GONE
binding.twoFaTitle.visibility = View.GONE
binding.twoFa.visibility = View.GONE
binding.errorTwoFa.visibility = View.GONE
if (this::oAuthData.isInitialized)
{
@ -67,9 +72,11 @@ class AddInstanceDialog : DialogFragment() {
val username = binding.username.text.toString()
val password = binding.password.text.toString()
var instance = binding.instance.text.toString()
var twoFaToken = binding.twoFa.text.toString()
binding.errorUsername.visibility = View.GONE
binding.errorInstance.visibility = View.GONE
binding.errorPassword.visibility = View.GONE
binding.errorTwoFa.visibility = View.GONE
binding.error.visibility = View.GONE
var inError = false
if(username.isEmpty())
@ -100,6 +107,13 @@ class AddInstanceDialog : DialogFragment() {
inError = true
}
}
if(twoFaToken.isEmpty() && binding.twoFa.isVisible)
{
binding.errorTwoFa.visibility = View.VISIBLE
inError = true
}
if (!this::oAuthData.isInitialized && DatabaseManager.existsCredential(requireContext(),instance,username)) {
inError = true
binding.error.visibility = View.VISIBLE
@ -109,13 +123,16 @@ class AddInstanceDialog : DialogFragment() {
binding.errorUsername.visibility = View.GONE
binding.errorInstance.visibility = View.GONE
binding.errorPassword.visibility = View.GONE
binding.errorTwoFa.visibility = View.GONE
binding.error.visibility = View.GONE
binding.username.visibility = View.GONE
binding.password.visibility = View.GONE
binding.instance.visibility = View.GONE
binding.twoFa.visibility = View.GONE
binding.usernameTitle.visibility = View.GONE
binding.passwordTitle.visibility = View.GONE
binding.instanceTitle.visibility = View.GONE
binding.twoFaTitle.visibility = View.GONE
binding.tryConnect.visibility = View.VISIBLE
binding.tryConnectMsg.visibility = View.VISIBLE
@ -135,20 +152,54 @@ class AddInstanceDialog : DialogFragment() {
}
}
override fun onError(error: String?) {
override fun onError(code: String?, error: String?) {
Handler(Looper.getMainLooper()).post {
binding.error.visibility = View.VISIBLE
binding.tryConnect.visibility = View.GONE
binding.tryConnectMsg.visibility = View.GONE
binding.username.visibility = View.VISIBLE
binding.password.visibility = View.VISIBLE
binding.instance.visibility = View.VISIBLE
binding.usernameTitle.visibility = View.VISIBLE
binding.passwordTitle.visibility = View.VISIBLE
binding.instanceTitle.visibility = View.VISIBLE
binding.error.text = error
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = true
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).isEnabled = true
if (code.equals("missing_two_factor") || code.equals("invalid_two_factor")) {
binding.error.visibility = View.GONE
binding.tryConnect.visibility = View.GONE
binding.tryConnectMsg.visibility = View.GONE
binding.username.visibility = View.GONE
binding.password.visibility = View.GONE
binding.instance.visibility = View.GONE
binding.usernameTitle.visibility = View.GONE
binding.passwordTitle.visibility = View.GONE
binding.instanceTitle.visibility = View.GONE
binding.username.isEnabled = false
binding.password.isEnabled = false
binding.instance.isEnabled = false
binding.twoFa.setText("")
binding.twoFa.visibility = View.VISIBLE
binding.twoFaTitle.visibility = View.VISIBLE
binding.errorTwoFa.visibility = View.GONE
if (code.equals("invalid_two_factor")) {
binding.error.setText(R.string.invalid_two_fa_token)
binding.error.visibility = View.VISIBLE
}
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = true
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).isEnabled = true
} else {
binding.error.visibility = View.VISIBLE
binding.tryConnect.visibility = View.GONE
binding.tryConnectMsg.visibility = View.GONE
binding.username.visibility = View.VISIBLE
binding.password.visibility = View.VISIBLE
binding.instance.visibility = View.VISIBLE
binding.twoFa.visibility = View.GONE
binding.usernameTitle.visibility = View.VISIBLE
binding.passwordTitle.visibility = View.VISIBLE
binding.instanceTitle.visibility = View.VISIBLE
binding.twoFaTitle.visibility = View.GONE
binding.username.isEnabled = true
binding.password.isEnabled = true
binding.instance.isEnabled = true
binding.twoFa.setText("")
binding.error.text = error
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = true
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).isEnabled = true
}
}
}
@ -158,9 +209,9 @@ class AddInstanceDialog : DialogFragment() {
};
if (this::oAuthData.isInitialized) {
InstanceManager.getUserToken(requireContext(), instance, username, password, oAuthData, listener)
InstanceManager.getUserToken(requireContext(), instance, username, password, twoFaToken, oAuthData, listener)
} else {
InstanceManager.registerAccount(requireContext(), instance, username, password,listener)
InstanceManager.registerAccount(requireContext(), instance, username, password, twoFaToken,listener)
}
}
}

View File

@ -52,21 +52,22 @@ object InstanceManager {
private const val CONFIG_LIVE: String = "live"
private const val CONFIG_LIVE_ENABLED: String = "enabled"
private const val CONFIG_LIVE_SAVE_REPLAY: String = "allowReplay"
public const val INTERNAL_ERROR: String = "INTERNAL_ERROR"
fun registerAccount(context: Context, url: String, username: String, password: String, listener: InstanceListener) {
fun registerAccount(context: Context, url: String, username: String, password: String, twoFa: String, listener: InstanceListener) {
val registerUrl = url + BASE_API_ENDPOINT+ REGISTER_CLIENT_ENDPOINT
val internalListener: InstanceListener = object : InstanceListener {
override fun onSuccess(args: Bundle?) {
val oauthData: OAuthData? = args?.getParcelable(EXTRA_DATA)
oauthData?.baseUrl = url
if (oauthData != null)
getUserToken(context, url, username, password,oauthData, listener)
getUserToken(context, url, username, password, twoFa, oauthData, listener)
else
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -77,9 +78,9 @@ object InstanceManager {
oauthManager.register(context,registerUrl,internalListener)
}
fun getUserToken(context: Context, url: String, username: String, password: String, oauthData: OAuthData, listener: InstanceListener) {
fun getUserToken(context: Context, url: String, username: String, password: String, twoFa: String, oauthData: OAuthData, listener: InstanceListener) {
val userAccess = url + BASE_API_ENDPOINT + GET_USER_CLIENT_ENDPOINT
oauthManager.getUserToken(context, userAccess, username, password, oauthData, listener)
oauthManager.getUserToken(context, userAccess, username, password, twoFa, oauthData, listener)
}
private fun refreshToken(context: Context, url: String, oauthData: OAuthData, listener: InstanceListener) {
@ -99,8 +100,8 @@ object InstanceManager {
}
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -119,12 +120,12 @@ object InstanceManager {
override fun onSuccess(args: Bundle?) {
val response = args?.getString(EXTRA_DATA, null)
if (response == null) {
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
return
}
val streamData = extractStreamData(response)
if (streamData == null) {
listener.onError(context.getString(R.string.json_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.json_error))
return
}
val results = Bundle()
@ -132,8 +133,8 @@ object InstanceManager {
listener.onSuccess(results)
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -178,20 +179,20 @@ object InstanceManager {
override fun onSuccess(args: Bundle?) {
val response = args?.getString(EXTRA_DATA, null)
if (response == null) {
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
return
}
val liveId = extractLiveId(response)
if (liveId == null) {
listener.onError(context.getString(R.string.json_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.json_error))
return
}
getStreamKey(context,url,oauthData,liveId,listener)
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -214,8 +215,8 @@ object InstanceManager {
}
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -234,21 +235,21 @@ object InstanceManager {
override fun onSuccess(args: Bundle?) {
val response = args?.getString(EXTRA_DATA, null)
if (response == null) {
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
return
}
val channelList = extractChannelData(response)
if (channelList == null) {
listener.onError(context.getString(R.string.json_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.json_error))
return
}
args.putParcelableArrayList(EXTRA_DATA, channelList)
listener.onSuccess(args)
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -265,13 +266,13 @@ object InstanceManager {
override fun onSuccess(args: Bundle?) {
val response = args?.getString(EXTRA_DATA, null)
if (response == null) {
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
return
}
val categoryList = extractMapData<Int>(response,0)
if (categoryList == null) {
listener.onError(context.getString(R.string.json_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.json_error))
return
}
categoryList[""]=0
@ -279,8 +280,8 @@ object InstanceManager {
listener.onSuccess(args)
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -298,21 +299,21 @@ object InstanceManager {
override fun onSuccess(args: Bundle?) {
val response = args?.getString(EXTRA_DATA, null)
if (response == null) {
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
return
}
val privacyList = extractMapData<Int>(response,0)
if (privacyList == null) {
listener.onError(context.getString(R.string.json_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.json_error))
return
}
args.putSerializable(EXTRA_DATA, privacyList)
listener.onSuccess(args)
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -329,13 +330,13 @@ object InstanceManager {
override fun onSuccess(args: Bundle?) {
val response = args?.getString(EXTRA_DATA, null)
if (response == null) {
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
return
}
val licencesList = extractMapData<Int>(response,0)
if (licencesList == null) {
listener.onError(context.getString(R.string.json_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.json_error))
return
}
licencesList[""]=0
@ -343,8 +344,8 @@ object InstanceManager {
listener.onSuccess(args)
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -361,13 +362,13 @@ object InstanceManager {
override fun onSuccess(args: Bundle?) {
val response = args?.getString(EXTRA_DATA, null)
if (response == null) {
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
return
}
val languageList = extractMapData<String>(response,"")
if (languageList == null) {
listener.onError(context.getString(R.string.json_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.json_error))
return
}
languageList[""]=""
@ -375,8 +376,8 @@ object InstanceManager {
listener.onSuccess(args)
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -393,20 +394,20 @@ object InstanceManager {
override fun onSuccess(args: Bundle?) {
val response = args?.getString(EXTRA_DATA, null)
if (response == null) {
listener.onError(context.getString(R.string.unknwon_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.unknwon_error))
return
}
val configData = extractConfigData(response)
if (configData == null) {
listener.onError(context.getString(R.string.json_error))
listener.onError(INTERNAL_ERROR,context.getString(R.string.json_error))
return
}
args.putParcelable(EXTRA_DATA, configData)
listener.onSuccess(args)
}
override fun onError(error: String?) {
listener.onError(error)
override fun onError(code: String?, error: String?) {
listener.onError(code,error)
}
override fun onUpdateOAuthData(oauthData: OAuthData) {
@ -527,7 +528,7 @@ object InstanceManager {
interface InstanceListener{
fun onSuccess(args: Bundle?)
fun onError(error: String?)
fun onError(code: String?, error: String?)
fun onUpdateOAuthData(oauthData: OAuthData)
}
}

View File

@ -53,12 +53,13 @@ class OAuthManager {
addMessage(message)
}
fun getUserToken(context: Context, url: String, username: String, password: String, oauthData: OAuthData, listener: InstanceManager.InstanceListener) {
fun getUserToken(context: Context, url: String, username: String, password: String, twoFa: String, oauthData: OAuthData, listener: InstanceManager.InstanceListener) {
val args = Bundle()
args.putString(URL, url)
args.putParcelable(OAUTH_DATA, oauthData)
args.putString(USERNAME, username)
args.putString(PASSWORD, password)
args.putString(TWO_FA,twoFa)
val message = Message()
message.type = Message.Message_Type.GET_USER_TOKEN
@ -119,11 +120,13 @@ class OAuthManager {
private const val URL: String = "URL"
private const val USERNAME: String = "USERNAME"
private const val PASSWORD: String = "PASSWORD"
private const val TWO_FA: String = "TWO_FA"
private const val OAUTH_DATA: String = "OAUTH_DATA"
private const val DATA: String = "DATA"
private const val EXTRA_DATA: String = "EXTRA_DATA"
private const val CONTENT_TYPE: String = "CONTENT_TYPE"
private const val CONTENT_DATA: String = "CONTENT_DATA"
fun addMessage(message: Message)
{
@ -153,7 +156,7 @@ class OAuthManager {
fun register(message: Message) {
if (!isConnectedToInternet(message.context)) {
message.listener?.onError(message.context.getString(R.string.network_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.network_error))
return
}
val url: String = message.args.getString(URL,"")
@ -170,7 +173,7 @@ class OAuthManager {
try {
inputStream = connection.inputStream
} catch (e: UnknownHostException) {
message.listener?.onError(message.context.getString(R.string.unknown_host))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknown_host))
return
} catch (e : Exception) {
e.printStackTrace()
@ -192,7 +195,7 @@ class OAuthManager {
message.listener?.onSuccess(result)
} else {
message.listener?.onError(message.context.getString(R.string.unknwon_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR, message.context.getString(R.string.unknwon_error))
}
} else {
handleError(message,response)
@ -201,7 +204,7 @@ class OAuthManager {
fun getUserToken(message: Message) {
if (!isConnectedToInternet(message.context)) {
message.listener?.onError(message.context.getString(R.string.network_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.network_error))
return
}
val url: String = message.args.getString(URL, "")
@ -220,6 +223,10 @@ class OAuthManager {
}
var username: String = message.args.getString(USERNAME,"")
var password: String = message.args.getString(PASSWORD,"")
var twoFa: String = message.args.getString(TWO_FA,"")
if (twoFa.isNotEmpty()) {
connection.setRequestProperty("x-peertube-otp", twoFa)
}
username = URLEncoder.encode(username,"UTF-8")
password = URLEncoder.encode(password,"UTF-8")
@ -241,7 +248,7 @@ class OAuthManager {
try {
inputStream = connection.inputStream
} catch (e: UnknownHostException) {
message.listener?.onError(message.context.getString(R.string.unknown_host))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknown_host))
return
} catch (e : Exception) {
e.printStackTrace()
@ -270,7 +277,7 @@ class OAuthManager {
message.listener?.onSuccess(result)
} else {
message.listener?.onError(message.context.getString(R.string.unknwon_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknwon_error))
}
} else {
handleError(message,response)
@ -280,7 +287,7 @@ class OAuthManager {
fun refreshToken(message: Message) {
if (!isConnectedToInternet(message.context)) {
message.listener?.onError(message.context.getString(R.string.network_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.network_error))
return
}
val url: String = message.args.getString(URL, "")
@ -313,7 +320,7 @@ class OAuthManager {
try {
inputStream = connection.inputStream
} catch (e: UnknownHostException) {
message.listener?.onError(message.context.getString(R.string.unknown_host))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknown_host))
return
} catch (e : Exception) {
e.printStackTrace()
@ -341,7 +348,7 @@ class OAuthManager {
message.listener?.onSuccess(result)
} else {
message.listener?.onError(message.context.getString(R.string.unknwon_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR, message.context.getString(R.string.unknwon_error))
}
} else {
handleError(message,response)
@ -351,7 +358,7 @@ class OAuthManager {
fun post(message: Message) {
if (!isConnectedToInternet(message.context)) {
message.listener?.onError(message.context.getString(R.string.network_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.network_error))
return
}
val url: String = message.args.getString(URL, "")
@ -381,7 +388,7 @@ class OAuthManager {
outputStream.flush()
outputStream.close()
} catch (e: UnknownHostException) {
message.listener?.onError(message.context.getString(R.string.unknown_host))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknown_host))
return
} catch (e : Exception) {
e.printStackTrace()
@ -394,7 +401,7 @@ class OAuthManager {
try {
inputStream = connection.inputStream
} catch (e: UnknownHostException) {
message.listener?.onError(message.context.getString(R.string.unknown_host))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknown_host))
return
} catch (e: Exception) {
e.printStackTrace()
@ -410,7 +417,7 @@ class OAuthManager {
result.putString(EXTRA_DATA, response)
message.listener?.onSuccess(result)
} else {
message.listener?.onError(message.context.getString(R.string.unknwon_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknwon_error))
}
} else {
handleError(message,response)
@ -420,7 +427,7 @@ class OAuthManager {
fun get(message: Message) {
if (!isConnectedToInternet(message.context)) {
message.listener?.onError(message.context.getString(R.string.network_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.network_error))
return
}
val url: String = message.args.getString(URL, "")
@ -443,7 +450,7 @@ class OAuthManager {
try {
inputStream = connection.inputStream
} catch (e: UnknownHostException) {
message.listener?.onError(message.context.getString(R.string.unknown_host))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknown_host))
return
} catch (e : Exception) {
e.printStackTrace()
@ -458,7 +465,7 @@ class OAuthManager {
result.putString(EXTRA_DATA, response)
message.listener?.onSuccess(result)
} else {
message.listener?.onError(message.context.getString(R.string.unknwon_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknwon_error))
}
} else {
handleError(message,response)
@ -470,12 +477,13 @@ class OAuthManager {
try {
val rootObj = JSONObject(response)
val error = rootObj.getString("error")
message.listener?.onError(error)
val code = rootObj.getString("code")
message.listener?.onError(code,error)
} catch (e: Exception) {
message.listener?.onError(message.context.getString(R.string.json_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.json_error))
}
} else {
message.listener?.onError(message.context.getString(R.string.unknwon_error))
message.listener?.onError(InstanceManager.INTERNAL_ERROR,message.context.getString(R.string.unknwon_error))
}
}

View File

@ -75,6 +75,23 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/password_error"/>
<TextView
android:id="@+id/two_fa_title"
android:text="@string/two_fa"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/two_fa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
<TextView
android:id="@+id/error_two_fa"
android:textColor="#FF0000"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/two_fa_error"/>
</LinearLayout>
</layout>

View File

@ -10,6 +10,8 @@
<string name="instance_error">L\'instance ne peut pas être vide</string>
<string name="username_error">Le nom d\'utilisateur ne peut pas être vide</string>
<string name="password_error">Le mot de passe ne peut pas être vide</string>
<string name="two_fa_error">Le jeton d\'authentification à deux facteurs ne peut pas être vide</string>
<string name="invalid_two_fa_token">Le jeton d\'authentification à deux facteurs n\'est pas valide</string>
<string name="malformed_instance_error">L\'instance doit avoir une URL valide</string>
<string name="account_exist">Ce compte existe déjà</string>
<!-- messages -->
@ -48,6 +50,7 @@
<string name="username">Nom d\'utilisateur</string>
<string name="password">Mot de passe</string>
<string name="instance">Instance</string>
<string name="two_fa">Jeton d\'authentification à deux facteurs</string>
<string name="delete_account_title">Supprimer ce compte</string>
<string name="comments_enabled">Activer les commentaires</string>
<string name="download_enabled">Activer le téléchargement</string>

View File

@ -10,6 +10,8 @@
<string name="instance_error">Instance cannot be empty</string>
<string name="username_error">Username cannot be empty</string>
<string name="password_error">Password cannot be empty</string>
<string name="two_fa_error">Two-factor authentication token cannot be empty</string>
<string name="invalid_two_fa_token">Two-factor authentication token is not valid</string>
<string name="malformed_instance_error">The instance must have a valid URL</string>
<string name="account_exist">This account already exist</string>
<!-- messages -->
@ -48,6 +50,7 @@
<string name="username">Username</string>
<string name="password">Password</string>
<string name="instance">Instance</string>
<string name="two_fa">Two-factor Authentication Token</string>
<string name="delete_account_title">Delete this account</string>
<string name="comments_enabled">Enable video comments</string>
<string name="download_enabled">Enable download</string>