mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 01:39:22 +02:00
Restrict key managment to the user itself
This commit is contained in:
parent
b557f58083
commit
050da14087
4 changed files with 54 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
|
||||
* TimeLimit Copyright <C> 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -46,17 +46,25 @@ object ManageUserKeyView {
|
|||
|
||||
view.addKeyButton.setOnClickListener {
|
||||
if (auth.requestAuthenticationOrReturnTrue()) {
|
||||
if (auth.authenticatedUser.value?.second?.id == userId) {
|
||||
AddUserKeyDialogFragment.newInstance(userId).show(fragmentManager)
|
||||
} else {
|
||||
ParentKeyWrongUserDialogFragment.newInstance().show(fragmentManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view.removeKeyButton.setOnClickListener {
|
||||
if (auth.requestAuthenticationOrReturnTrue()) {
|
||||
if (auth.authenticatedUser.value?.second?.id == userId) {
|
||||
val database = auth.database
|
||||
|
||||
Threads.database.execute {
|
||||
database.userKey().deleteUserKeySync(userId)
|
||||
}
|
||||
} else {
|
||||
ParentKeyWrongUserDialogFragment.newInstance().show(fragmentManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.timelimit.android.ui.manage.parent.key
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import io.timelimit.android.R
|
||||
import io.timelimit.android.extensions.showSafe
|
||||
|
||||
class ParentKeyWrongUserDialogFragment: DialogFragment() {
|
||||
companion object {
|
||||
private const val DIALOG_TAG = "ParentKeyWrongUserDialogFragment"
|
||||
|
||||
fun newInstance() = ParentKeyWrongUserDialogFragment()
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = AlertDialog.Builder(requireContext(), theme)
|
||||
.setMessage(R.string.manage_user_key_wrong_user)
|
||||
.setPositiveButton(R.string.generic_ok, null)
|
||||
.create()
|
||||
|
||||
fun show(fragmentManager: FragmentManager) = showSafe(fragmentManager, DIALOG_TAG)
|
||||
}
|
|
@ -1086,6 +1086,7 @@
|
|||
<string name="manage_user_key_added">Der Schlüssel wurde hinzugefügt</string>
|
||||
<string name="manage_user_key_invalid">Dies ist kein gültiger TimeLimit-Schlüssel</string>
|
||||
<string name="manage_user_key_other_user">Dieser Schlüssel ist schon bei einem anderen Benutzer hinterlegt</string>
|
||||
<string name="manage_user_key_wrong_user">Nur der Benutzer selbst kann seine Schlüssel verwalten</string>
|
||||
|
||||
<string name="manage_parent_link_mail_title">E-Mail-Adresse verknüpfen</string>
|
||||
<string name="manage_parent_link_mail_status_disabled">Es wurde keine E-Mail-Adresse verknüpft</string>
|
||||
|
|
|
@ -1134,6 +1134,7 @@
|
|||
<string name="manage_user_key_added">The key was added</string>
|
||||
<string name="manage_user_key_invalid">This was no valid TimeLimit key</string>
|
||||
<string name="manage_user_key_other_user">This key is already linked to an other user</string>
|
||||
<string name="manage_user_key_wrong_user">Only the user itself can manage his keys</string>
|
||||
|
||||
<string name="manage_parent_link_mail_title">Link mail address</string>
|
||||
<string name="manage_parent_link_mail_status_disabled">No mail address was linked</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue