Сделал супер шутку "личного кабинета"
This commit is contained in:
parent
3e68677d23
commit
eb3bc2ea3d
@ -8,8 +8,8 @@ import androidx.room.PrimaryKey
|
||||
data class User(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val id: Int?,
|
||||
val name: String,
|
||||
val email: String,
|
||||
val password: String,
|
||||
var name: String,
|
||||
var email: String,
|
||||
var password: String,
|
||||
)
|
||||
|
||||
|
@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.IconButton
|
||||
@ -27,12 +28,16 @@ import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.labwork.R
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.models.Bicycle
|
||||
import com.example.labwork.models.User
|
||||
import com.example.labwork.ui.theme.LightBluePolitech
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
@ -42,105 +47,116 @@ fun LoginPage(navController: NavController, userDao: UserDao, navHostController:
|
||||
var email by remember { mutableStateOf("") }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var userPassword by remember { mutableStateOf("") }
|
||||
var user by remember { mutableStateOf<User?>(null) }
|
||||
var showPassword by remember { mutableStateOf(false) }
|
||||
var acceptLogin by remember { mutableStateOf(false) }
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.drawable.logo_ulstu),
|
||||
contentDescription = "Logo",
|
||||
modifier = Modifier.size(200.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = email,
|
||||
onValueChange = { email = it },
|
||||
label = { Text("Почта") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
textStyle = TextStyle(fontSize = 16.sp),
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
cursorColor = LightBluePolitech,
|
||||
backgroundColor = Color.White,
|
||||
textColor = LightBluePolitech,
|
||||
unfocusedLabelColor = LightBluePolitech,
|
||||
focusedIndicatorColor = LightBluePolitech,
|
||||
unfocusedIndicatorColor = LightBluePolitech,
|
||||
focusedLabelColor = LightBluePolitech
|
||||
),
|
||||
singleLine = true
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
TextField(
|
||||
value = password,
|
||||
onValueChange = { password = it },
|
||||
label = { Text("Пароль") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
textStyle = TextStyle(fontSize = 16.sp),
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
cursorColor = LightBluePolitech,
|
||||
backgroundColor = Color.White,
|
||||
textColor = LightBluePolitech,
|
||||
unfocusedLabelColor = LightBluePolitech,
|
||||
focusedIndicatorColor = LightBluePolitech,
|
||||
unfocusedIndicatorColor = LightBluePolitech,
|
||||
focusedLabelColor = LightBluePolitech
|
||||
),
|
||||
singleLine = true,
|
||||
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
||||
trailingIcon = {
|
||||
IconButton(
|
||||
onClick = { showPassword = !showPassword }
|
||||
) {
|
||||
Image(
|
||||
painter = if(showPassword) painterResource(R.drawable.baseline_visibility) else painterResource(
|
||||
R.drawable.baseline_visibility_off),
|
||||
contentDescription = "LogoVissable",
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
GlobalScope.launch {
|
||||
userPassword = userDao.getPasswordByEmail(email)
|
||||
}
|
||||
if(userPassword == password) {
|
||||
acceptLogin = true
|
||||
navHostController.navigate("Profile")
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech, ),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Text(text = "Авторизоваться", color = Color.White)
|
||||
if (acceptLogin == true) {
|
||||
user?.let { userProfile ->
|
||||
ProfileForm(item = userProfile, userDao = userDao, navHostController = navHostController)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Button(
|
||||
onClick = { navController.navigate("register") },
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||
}
|
||||
else {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp)
|
||||
.fillMaxSize()
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Регистрация", color = Color.White)
|
||||
Image(
|
||||
painter = painterResource(R.drawable.logo_ulstu),
|
||||
contentDescription = "Logo",
|
||||
modifier = Modifier.size(200.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = email,
|
||||
onValueChange = { email = it },
|
||||
label = { Text("Почта") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
textStyle = TextStyle(fontSize = 16.sp),
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
cursorColor = LightBluePolitech,
|
||||
backgroundColor = Color.White,
|
||||
textColor = LightBluePolitech,
|
||||
unfocusedLabelColor = LightBluePolitech,
|
||||
focusedIndicatorColor = LightBluePolitech,
|
||||
unfocusedIndicatorColor = LightBluePolitech,
|
||||
focusedLabelColor = LightBluePolitech
|
||||
),
|
||||
singleLine = true
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
TextField(
|
||||
value = password,
|
||||
onValueChange = { password = it },
|
||||
label = { Text("Пароль") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
textStyle = TextStyle(fontSize = 16.sp),
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
cursorColor = LightBluePolitech,
|
||||
backgroundColor = Color.White,
|
||||
textColor = LightBluePolitech,
|
||||
unfocusedLabelColor = LightBluePolitech,
|
||||
focusedIndicatorColor = LightBluePolitech,
|
||||
unfocusedIndicatorColor = LightBluePolitech,
|
||||
focusedLabelColor = LightBluePolitech
|
||||
),
|
||||
singleLine = true,
|
||||
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
||||
trailingIcon = {
|
||||
IconButton(
|
||||
onClick = { showPassword = !showPassword }
|
||||
) {
|
||||
Image(
|
||||
painter = if (showPassword) painterResource(R.drawable.baseline_visibility) else painterResource(
|
||||
R.drawable.baseline_visibility_off
|
||||
),
|
||||
contentDescription = "LogoVissable",
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
GlobalScope.launch {
|
||||
userPassword = userDao.getPasswordByEmail(email)
|
||||
user = userDao.getUserByEmail(email)
|
||||
|
||||
if (userPassword == password) {
|
||||
acceptLogin = true
|
||||
//navHostController.navigate("Profile")
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech,),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Text(text = "Авторизоваться", color = Color.White)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Button(
|
||||
onClick = { navController.navigate("register") },
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Text(text = "Регистрация", color = Color.White)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
121
app/src/main/java/com/example/labwork/pages/user/ProfileForm.kt
Normal file
121
app/src/main/java/com/example/labwork/pages/user/ProfileForm.kt
Normal file
@ -0,0 +1,121 @@
|
||||
package com.example.labwork.pages.user
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextField
|
||||
import androidx.compose.material.TextFieldDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.models.Bicycle
|
||||
import com.example.labwork.models.User
|
||||
import com.example.labwork.ui.theme.LightBluePolitech
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun ProfileForm(item: User, userDao: UserDao, navHostController: NavHostController) {
|
||||
val isFormVisible = remember { mutableStateOf(false) }
|
||||
var email by remember { mutableStateOf(item.email) }
|
||||
var name by remember { mutableStateOf(item.name) }
|
||||
var password by remember { mutableStateOf(item.password) }
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
// Поле ввода для бренда
|
||||
TextField(
|
||||
value = email,
|
||||
onValueChange = { email = it },
|
||||
placeholder = { Text("Почта") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
|
||||
)
|
||||
|
||||
// Поле ввода для модели
|
||||
TextField(
|
||||
value = name,
|
||||
onValueChange = { name = it },
|
||||
placeholder = { Text("Имя") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
|
||||
)
|
||||
|
||||
// Поле ввода для цвета
|
||||
TextField(
|
||||
value = password,
|
||||
onValueChange = { password = it },
|
||||
placeholder = { Text("Пароль") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
|
||||
)
|
||||
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(9.dp),
|
||||
onClick = {
|
||||
GlobalScope.launch {
|
||||
val newUser = userDao.getUserById(item.id!!)
|
||||
newUser.email = email
|
||||
newUser.name = name
|
||||
newUser.password = password
|
||||
|
||||
userDao.updateUser(newUser)
|
||||
}
|
||||
isFormVisible.value = false
|
||||
navHostController.navigate("ListProduct")
|
||||
},
|
||||
shape = RoundedCornerShape(15.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Принять",
|
||||
color = Color.White,
|
||||
fontSize = 10.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(9.dp),
|
||||
onClick = {
|
||||
isFormVisible.value = false
|
||||
navHostController.navigate("ListProduct")
|
||||
},
|
||||
shape = RoundedCornerShape(15.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Отменить",
|
||||
color = Color.White,
|
||||
fontSize = 10.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user