Разграничение ролей
This commit is contained in:
parent
ef72894515
commit
ef4140f273
@ -18,7 +18,7 @@
|
||||
"id": 3,
|
||||
"login": "User2",
|
||||
"password": "123",
|
||||
"email": "user2@gmail.ru",
|
||||
"email": "user2@mail.ru",
|
||||
"role": "USER"
|
||||
}
|
||||
],
|
||||
|
@ -117,7 +117,7 @@ interface ServerService{
|
||||
@Path("id") id: Int,
|
||||
): UserRemote
|
||||
companion object {
|
||||
private const val BASE_URL = "http://89.239.174.67:8079/"
|
||||
private const val BASE_URL = "http://100.74.118.221:8079/"
|
||||
|
||||
@Volatile
|
||||
private var INSTANCE: ServerService? = null
|
||||
|
@ -59,8 +59,14 @@ fun AuthorCell(navController: NavController?, author: Author, viewModel: AuthorL
|
||||
modifier = Modifier
|
||||
.padding(all = 5.dp),
|
||||
onClick = {
|
||||
if(LiveStore.getRole() == "ADMIN") {
|
||||
val route = Screen.AuthorEdit.route.replace("{id}", author.id.toString())
|
||||
navController!!.navigate(route)
|
||||
}
|
||||
else{
|
||||
val toast = Toast.makeText(MainActivity.appContext, "У вас нет соответствующих прав", Toast.LENGTH_SHORT)
|
||||
toast.show()
|
||||
}
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
@ -73,9 +79,15 @@ fun AuthorCell(navController: NavController?, author: Author, viewModel: AuthorL
|
||||
modifier = Modifier
|
||||
.padding(all = 5.dp),
|
||||
onClick = {
|
||||
if(LiveStore.getRole() == "ADMIN") {
|
||||
scope.launch {
|
||||
viewModel.deleteAuthor(author)
|
||||
}
|
||||
}
|
||||
else{
|
||||
val toast = Toast.makeText(MainActivity.appContext, "У вас нет соответствующих прав", Toast.LENGTH_SHORT)
|
||||
toast.show()
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color.Red),
|
||||
) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.example.myapplication.composeui
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
@ -29,9 +30,11 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.MainActivity
|
||||
import com.example.myapplication.composeui.ViewModel.BookListViewModel
|
||||
import com.example.myapplication.composeui.navigation.Screen
|
||||
import com.example.myapplication.db.model.Book
|
||||
import com.example.myapplication.store.LiveStore
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
@ -79,8 +82,14 @@ fun BookCell(navController: NavController?, book: Book, viewModel: BookListViewM
|
||||
modifier = Modifier
|
||||
.padding(all = 5.dp),
|
||||
onClick = {
|
||||
if((LiveStore.getUserId() == book.userId) || (LiveStore.getRole() == "ADMIN")) {
|
||||
val route = Screen.BookEdit.route.replace("{id}", book.id.toString())
|
||||
navController!!.navigate(route)
|
||||
}
|
||||
else{
|
||||
val toast = Toast.makeText(MainActivity.appContext, "У вас нет соответствующих прав", Toast.LENGTH_SHORT)
|
||||
toast.show()
|
||||
}
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
@ -93,9 +102,15 @@ fun BookCell(navController: NavController?, book: Book, viewModel: BookListViewM
|
||||
modifier = Modifier
|
||||
.padding(all = 5.dp),
|
||||
onClick = {
|
||||
if((LiveStore.getUserId() == book.userId) || (LiveStore.getRole() == "ADMIN")) {
|
||||
scope.launch {
|
||||
viewModel.deleteBook(book)
|
||||
}
|
||||
}
|
||||
else{
|
||||
val toast = Toast.makeText(MainActivity.appContext, "У вас нет соответствующих прав", Toast.LENGTH_SHORT)
|
||||
toast.show()
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color.Red),
|
||||
) {
|
||||
|
@ -8,12 +8,16 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
@ -24,10 +28,15 @@ import androidx.navigation.compose.rememberNavController
|
||||
import com.example.myapplication.composeui.navigation.Screen
|
||||
import com.example.myapplication.R
|
||||
import com.example.myapplication.store.LiveStore
|
||||
import com.example.myapplication.store.PreferencesStore
|
||||
import com.example.myapplication.ui.theme.MyApplicationTheme
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun Profile(navController: NavController) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
val store = PreferencesStore(context)
|
||||
Column(Modifier.padding(all = 40.dp)) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.user),
|
||||
@ -53,6 +62,21 @@ fun Profile(navController: NavController) {
|
||||
}) {
|
||||
Text(stringResource(id = R.string.my_books))
|
||||
}
|
||||
Spacer(Modifier.padding(bottom = 10.dp))
|
||||
Button(
|
||||
onClick = {
|
||||
scope.launch {
|
||||
store.setUid("")
|
||||
}
|
||||
navController?.navigate(Screen.Main.route)
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(all = 10.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color.LightGray, contentColor = Color.Black))
|
||||
{
|
||||
Text(stringResource(id = R.string.exit))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,12 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.R
|
||||
import com.example.myapplication.composeui.ViewModel.UserDetails
|
||||
import com.example.myapplication.composeui.ViewModel.UserEditViewModel
|
||||
import com.example.myapplication.composeui.ViewModel.UserUiState
|
||||
@ -52,7 +54,7 @@ private fun ProfileEdit(
|
||||
value = userUiState.userDetails.email,
|
||||
onValueChange = { onUpdate(userUiState.userDetails.copy(email = it)) },
|
||||
singleLine = true,
|
||||
label = { Text("Почта", fontSize = 20.sp) },
|
||||
label = { Text(stringResource(id = R.string.email), fontSize = 20.sp) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp, 5.dp)
|
||||
@ -60,7 +62,7 @@ private fun ProfileEdit(
|
||||
OutlinedTextField(
|
||||
value = userUiState.userDetails.login,
|
||||
onValueChange = { onUpdate(userUiState.userDetails.copy(login = it)) },
|
||||
label = { Text("Логин", fontSize = 20.sp) },
|
||||
label = { Text(stringResource(id = R.string.login), fontSize = 20.sp) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp, 5.dp)
|
||||
@ -69,7 +71,7 @@ private fun ProfileEdit(
|
||||
value = userUiState.userDetails.password,
|
||||
onValueChange = { onUpdate(userUiState.userDetails.copy(password = it)) },
|
||||
singleLine = true,
|
||||
label = { Text("Пароль", fontSize = 20.sp) },
|
||||
label = { Text(stringResource(id = R.string.password), fontSize = 20.sp) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp, 5.dp)
|
||||
@ -89,9 +91,8 @@ private fun ProfileEdit(
|
||||
.padding(10.dp, 0.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color.LightGray, contentColor = Color.Black))
|
||||
{
|
||||
Text("Назад")
|
||||
Text(stringResource(id = R.string.back))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,8 @@
|
||||
<string name="my_books">Мои книги</string>
|
||||
<string name="authors_books">Книги автора</string>
|
||||
<string name="enter">Войти</string>
|
||||
<string name="exit">Выйти</string>
|
||||
<string name="delete_acc">Удалить аккаунт</string>
|
||||
<string name="create_acc">Создать аккаунт</string>
|
||||
<string name="email">Почта</string>
|
||||
<string name="login">Логин</string>
|
||||
@ -30,4 +32,6 @@
|
||||
<string name="load_book">Загрузить</string>
|
||||
<string name="add_book">Добавить</string>
|
||||
<string name="read_book">Читать</string>
|
||||
<string name="edit">Изменить</string>
|
||||
<string name="back">Назад</string>
|
||||
</resources>
|
@ -3,6 +3,6 @@
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="true">100.87.48.148</domain>
|
||||
<domain includeSubdomains="true">192.168.43.198</domain>
|
||||
<domain includeSubdomains="true">89.239.174.67</domain>
|
||||
<domain includeSubdomains="true">100.74.118.221</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
Loading…
Reference in New Issue
Block a user