logging out on user data changes

This commit is contained in:
leca 2024-11-15 11:36:44 +03:00
parent 58a7ea7357
commit abe2a850d6
3 changed files with 22 additions and 2 deletions

View File

@ -1,11 +1,13 @@
package org.foxarmy.barcodescannerforemployees.activities
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys
import org.foxarmy.barcodescannerforemployees.Net
import org.foxarmy.barcodescannerforemployees.R
import org.foxarmy.barcodescannerforemployees.databinding.ActivityAccountSettingsBinding
class AccountSettingsActivity : AppCompatActivity() {
@ -37,12 +39,26 @@ class AccountSettingsActivity : AppCompatActivity() {
binding.saveUsernameButton.setOnClickListener {
val response = net.changeUsername(binding.newUsernameTextEdit.text.toString())
Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
if (response.code == 200) {
Toast.makeText(this, getString(R.string.username_changed), Toast.LENGTH_LONG).show()
val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
finish()
} else {
Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
}
}
binding.savePasswordButton.setOnClickListener {
val response = net.changePassword(binding.newPasswordTextEdit.text.toString())
Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
if (response.code == 200) {
Toast.makeText(this, getString(R.string.password_changed), Toast.LENGTH_LONG).show()
val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
finish()
} else {
Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
}
}
}
}

View File

@ -118,6 +118,8 @@
<string name="ok">Ок</string>
<string name="logout">Выйти</string>
<string name="online_only_feature">Эта возможность доступна только с онлайн аккаунтом</string>
<string name="username_changed">Имя пользователя изменено. Пожалуйста, перезайдите</string>
<string name="password_changed">Пароль изменён. Пожалуйста, перезайдите</string>
<string-array name="languages">
<item>en-US</item>
<item>ru-RU</item>

View File

@ -116,6 +116,8 @@
<string name="ok">OK</string>
<string name="logout">Log out</string>
<string name="online_only_feature">This feature is online only</string>
<string name="username_changed">Your username has been changed. Please, relogin</string>
<string name="password_changed">You password was changed. Please, relogin</string>
<string-array name="languages">
<item>en-US</item>
<item>ru-RU</item>