73 lines
1.9 KiB
Kotlin
73 lines
1.9 KiB
Kotlin
|
import model.UserAuthorize
|
||
|
import model.Roles
|
||
|
import java.time.LocalDate
|
||
|
import java.util.zip.Checksum
|
||
|
|
||
|
val authorizeList = mutableListOf<UserAuthorize>()
|
||
|
|
||
|
fun main(){
|
||
|
authorizeList.add(registration())
|
||
|
authorizeList.forEach{ println(it)}
|
||
|
}
|
||
|
|
||
|
fun authorize():UserAuthorize{
|
||
|
println("Введите почту или телефон")
|
||
|
val phone = readlnOrNull()
|
||
|
val email = readlnOrNull()
|
||
|
val checkPhoneEmail = readlnOrNull()
|
||
|
checkNotNull(email)
|
||
|
checkNotNull(phone)
|
||
|
checkNotNull(checkPhoneEmail)
|
||
|
require(checkPhoneEmail == phone || checkPhoneEmail == email)
|
||
|
require("@" in email)
|
||
|
require("+" in phone && phone.length == 11)
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
fun registration():UserAuthorize{
|
||
|
println("Введите логин")
|
||
|
val userLogin = readlnOrNull()
|
||
|
checkNotNull(userLogin)
|
||
|
require(userLogin.length >= 4)
|
||
|
|
||
|
println("Введите пароль")
|
||
|
val password = readlnOrNull()
|
||
|
checkNotNull(password)
|
||
|
require(password.length>=8)
|
||
|
println("Введите пароль повторно")
|
||
|
val passwordAgain = password
|
||
|
require(password.length>=8 && password == passwordAgain)
|
||
|
password.forEach { it.isLetterOrDigit() }
|
||
|
|
||
|
while (passwordAgain != password){
|
||
|
|
||
|
println("Введите пароль повторно")
|
||
|
val passwordAgain = password
|
||
|
require(password.length>=8 && password == passwordAgain)
|
||
|
password.forEach { it.isLetterOrDigit() }
|
||
|
|
||
|
}
|
||
|
|
||
|
println("Введите email")
|
||
|
val email = readlnOrNull()
|
||
|
checkNotNull(email)
|
||
|
require("@" in email)
|
||
|
|
||
|
println("Введите телефон")
|
||
|
val phone = readlnOrNull()
|
||
|
checkNotNull(phone)
|
||
|
require("+" in phone && phone.length == 11)
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
return UserAuthorize(authorizeList.size +1,
|
||
|
password = password,
|
||
|
login = userLogin,
|
||
|
lastAuthorizeDate = LocalDate.now(),
|
||
|
email = email,
|
||
|
phone = phone)
|
||
|
}
|