103 lines
3.5 KiB
Kotlin
103 lines
3.5 KiB
Kotlin
import java.io.Console
|
||
import java.security.SecureRandom
|
||
import java.time.LocalDate
|
||
import javax.crypto.SecretKey
|
||
import javax.crypto.SecretKeyFactory
|
||
import javax.crypto.spec.PBEKeySpec
|
||
import javax.swing.text.PasswordView
|
||
import RepositoryImpl.hashing
|
||
import RepositoryImpl.registration
|
||
import RepositoryImpl.authorization
|
||
import model.User
|
||
|
||
val authorizeList = mutableListOf<User>()
|
||
fun main() {
|
||
authorizeList.add(registration())
|
||
authorizeList.add(User(
|
||
2, "Alex", hashing("Alex1234"), "alex@gmail.com", "89310010543",
|
||
lastAuthorizeDate = LocalDate.now(),
|
||
))
|
||
authorizeList.add(User(
|
||
3, "MegaBalbes", hashing("fjghk123j"), "sdfgtyghk@gmail.com", "89314230543",
|
||
lastAuthorizeDate = LocalDate.now(),
|
||
))
|
||
authorizeList.add(User(
|
||
4, "IVBan", hashing("d,lfmk123454sdjhy"), "dsfgxvds@gmail.com", "+79310864309",
|
||
lastAuthorizeDate = LocalDate.now(),
|
||
))
|
||
authorizeList.add(User(
|
||
5, "Vlad", hashing("dfghfgd7878"), "rthtre6@gmail.com", "89311054819",
|
||
lastAuthorizeDate = LocalDate.now(),
|
||
))
|
||
authorizeList.add(User(
|
||
6, "XDel", hashing("sadfhjh1235"), "kjhndfjhv@gmail.com", "89319654812",
|
||
lastAuthorizeDate = LocalDate.now(),
|
||
))
|
||
authorizeList.add(User(
|
||
7, "Amega", hashing("123dfgyt"), "lljseioev@gmail.com", "89313218457",
|
||
lastAuthorizeDate = LocalDate.now(),
|
||
))
|
||
authorizeList.add(User(
|
||
8, "Orbita", hashing("98547kxdbfg"), "mlkswgjb@gmail.com", "89319784561",
|
||
lastAuthorizeDate = LocalDate.now(),
|
||
))
|
||
|
||
|
||
authorization()
|
||
var check = true
|
||
while(check){
|
||
println("1. Войти в админ-панель")
|
||
println("2. Выход")
|
||
var answer= readln()
|
||
when(answer){
|
||
"1" -> admin()
|
||
"2" -> check = false
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
fun admin(){
|
||
while(true){
|
||
println("1. Вывести всех пользователей")
|
||
println("2. Поменять пароль пользователя")
|
||
println("3. Удалить пользователя")
|
||
println("4. Вывести всех пользователей с сортировкой по дате")
|
||
var answer = readln()
|
||
when(answer){
|
||
"1" -> authorizeList.forEach(){
|
||
println("ID: " + it.userId)
|
||
println("Ник: " + it.login)
|
||
println("Пароль: " + it.password?.encoded)
|
||
println("Email: " + it.email)
|
||
println("Телефон: " + it.phone)
|
||
println("Role: " + it.role)
|
||
println("Последняя авторизация: " + it.lastAuthorizeDate)
|
||
}
|
||
"2" -> println()
|
||
"3" -> println()
|
||
"4" -> println()
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
fun authorization(){
|
||
println()
|
||
println()
|
||
println()
|
||
var check =true
|
||
while(check) {
|
||
println("Введите почту или номер телефона для авторизации")
|
||
val readUserEmailOrNumber = readln()
|
||
println("Введите пароль")
|
||
val readUserPassword = readln()
|
||
authorizeList.forEach {
|
||
if ((readUserEmailOrNumber == it.email || readUserEmailOrNumber == it.phone) && hashing(readUserPassword) == it.password) {
|
||
it.lastAuthorizeDate = LocalDate.now()
|
||
check=false
|
||
return println(it.role + "\r\n" + it.lastAuthorizeDate)
|
||
}
|
||
}
|
||
}
|
||
} |