init commit
This commit is contained in:
parent
6a920f8507
commit
de9ddfd0bb
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
src/main/kotlin/Interface/AdminService.kt
Normal file
8
src/main/kotlin/Interface/AdminService.kt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package Interface
|
||||||
|
|
||||||
|
import model.User
|
||||||
|
|
||||||
|
interface AdminService {
|
||||||
|
fun removeUserById(userId: Int): Boolean
|
||||||
|
fun getAllUsers(): List<User>
|
||||||
|
}
|
9
src/main/kotlin/Interface/AuthorizeService.kt
Normal file
9
src/main/kotlin/Interface/AuthorizeService.kt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package Interface
|
||||||
|
|
||||||
|
import model.User
|
||||||
|
|
||||||
|
/*
|
||||||
|
Interface AuthorizeService {
|
||||||
|
fun registration(user: User):Boolean
|
||||||
|
fun
|
||||||
|
}*/
|
6
src/main/kotlin/Interface/PasswordService.kt
Normal file
6
src/main/kotlin/Interface/PasswordService.kt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package Interface
|
||||||
|
|
||||||
|
interface PasswordService{
|
||||||
|
fun hashPassword(password:String, salt:ByteArray):String
|
||||||
|
fun matches(password:String, salt:ByteArray, hashedPassword:String):Boolean
|
||||||
|
}
|
25
src/main/kotlin/RepositoryImpl/AdminServiceImpl.kt
Normal file
25
src/main/kotlin/RepositoryImpl/AdminServiceImpl.kt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package RepositoryImpl
|
||||||
|
|
||||||
|
import Interface.AdminService
|
||||||
|
import model.User
|
||||||
|
|
||||||
|
class AdminServiceImpl : AdminService {
|
||||||
|
private val users = mutableListOf<User>()
|
||||||
|
|
||||||
|
override fun removeUserById(userId: Int): Boolean {
|
||||||
|
val user = users.find { it.userId == userId }
|
||||||
|
return if (user != null) {
|
||||||
|
users.remove(user)
|
||||||
|
true }
|
||||||
|
else
|
||||||
|
{ false }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllUsers(): List<User> {
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
11
src/main/kotlin/RepositoryImpl/AuthorizeServiceImpl.kt
Normal file
11
src/main/kotlin/RepositoryImpl/AuthorizeServiceImpl.kt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
package RepositoryImpl
|
||||||
|
|
||||||
|
import Interface.AuthorizeService
|
||||||
|
import model.User
|
||||||
|
|
||||||
|
class AuthorizeServiceImpl: AuthorizeService{
|
||||||
|
override fun registration(user: User): Boolean {
|
||||||
|
adminService.addUser(user
|
||||||
|
}
|
||||||
|
}*/
|
20
src/main/kotlin/RepositoryImpl/PasswordServiceImpl.kt
Normal file
20
src/main/kotlin/RepositoryImpl/PasswordServiceImpl.kt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package RepositoryImpl
|
||||||
|
|
||||||
|
import Interface.PasswordService
|
||||||
|
import javax.crypto.SecretKeyFactory
|
||||||
|
import javax.crypto.spec.PBEKeySpec
|
||||||
|
|
||||||
|
class PasswordServiceImpl : PasswordService {
|
||||||
|
override fun hashPassword(password: String, salt: ByteArray): String {
|
||||||
|
val spec = PBEKeySpec(password.toCharArray(), salt, 10000, 256)
|
||||||
|
val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
|
||||||
|
val hash = factory.generateSecret(spec).encoded
|
||||||
|
return salt.joinToString("") { "%02x".format(it) } + ":" + hash.joinToString("") { "%02x".format(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun matches(password: String, salt: ByteArray, hashedPassword: String): Boolean {
|
||||||
|
val generatedHash = hashPassword(password, salt)
|
||||||
|
return generatedHash == hashedPassword
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
14
src/main/kotlin/model/AdminUser.kt
Normal file
14
src/main/kotlin/model/AdminUser.kt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
class AdminUser(
|
||||||
|
userId: Int,
|
||||||
|
login: String,
|
||||||
|
password: String,
|
||||||
|
lastAuthorizeDate: LocalDate,
|
||||||
|
email: String,
|
||||||
|
phone: String
|
||||||
|
) : User(userId, login, password, lastAuthorizeDate, email, phone) {
|
||||||
|
override val role: String = "администратор"
|
||||||
|
}
|
14
src/main/kotlin/model/DefaultUser.kt
Normal file
14
src/main/kotlin/model/DefaultUser.kt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
class DefaultUser(
|
||||||
|
userId: Int,
|
||||||
|
login: String,
|
||||||
|
password: String,
|
||||||
|
lastAuthorizeDate: LocalDate,
|
||||||
|
email: String,
|
||||||
|
phone: String
|
||||||
|
) : User(userId, login, password, lastAuthorizeDate, email, phone) {
|
||||||
|
override val role: String = "пользователь"
|
||||||
|
}
|
14
src/main/kotlin/model/ManagerUser.kt
Normal file
14
src/main/kotlin/model/ManagerUser.kt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
class ManagerUser(
|
||||||
|
userId: Int,
|
||||||
|
login: String,
|
||||||
|
password: String,
|
||||||
|
lastAuthorizeDate: LocalDate,
|
||||||
|
email: String,
|
||||||
|
phone: String
|
||||||
|
) : User(userId, login, password, lastAuthorizeDate, email, phone) {
|
||||||
|
override val role: String = "менеджер"
|
||||||
|
}
|
16
src/main/kotlin/model/User.kt
Normal file
16
src/main/kotlin/model/User.kt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
open class User(
|
||||||
|
val userId: Int,
|
||||||
|
val login: String,
|
||||||
|
var password: String,
|
||||||
|
var lastAuthorizeDate: LocalDate,
|
||||||
|
var email: String,
|
||||||
|
var phone: String
|
||||||
|
) { open val role: String = "пользователь" }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user