From 310ecb9f38fc9ea0ac6ce153fb1c1b709fdefa4b Mon Sep 17 00:00:00 2001 From: akuleshov7 Date: Sat, 7 Sep 2024 23:33:59 +0300 Subject: [PATCH] Experiment with User data --- backend/build.gradle.kts | 4 +- .../ru/posidata/backend/BackendApplication.kt | 13 ---- .../controller/TelegramAuthController.kt | 36 --------- .../kotlin/ru/posidata/backend/entity/User.kt | 15 ---- .../backend/repository/UserRepository.kt | 10 --- .../backend/service/TelegramAuthService.kt | 43 ----------- .../posidata/backend/service/UserService.kt | 23 ------ backend/src/jvmMain/resources/application.yml | 8 -- .../controller/TelegramAuthController.kt | 29 ------- .../backend/controller/UserController.kt | 57 ++++++++++++++ .../kotlin/ru/posidata/backend/entity/User.kt | 13 +++- .../backend/repository/UserRepository.kt | 4 +- .../backend/service/TelegramAuthService.kt | 77 +++++++++++-------- .../posidata/backend/service/UserService.kt | 30 ++++---- .../ru/posidata/backend/UserControllerTest.kt | 17 ++++ .../kotlin/ru/posidata/common}/Enums.kt | 2 +- .../kotlin/ru/posidata/common}/Resources.kt | 7 +- .../ru/posidata/views/main/AnswerCard.kt | 14 ++-- .../kotlin/ru/posidata/views/main/MainView.kt | 10 +-- .../ru/posidata/views/main/ProgressBar.kt | 12 +-- .../ru/posidata/views/main/QuestionCard.kt | 16 ++-- .../ru/posidata/views/main/ResultCard.kt | 8 +- .../kotlin/ru/posidata/views/main/Welcome.kt | 3 +- 23 files changed, 190 insertions(+), 261 deletions(-) delete mode 100644 backend/src/jvmMain/kotlin/ru/posidata/backend/BackendApplication.kt delete mode 100644 backend/src/jvmMain/kotlin/ru/posidata/backend/controller/TelegramAuthController.kt delete mode 100644 backend/src/jvmMain/kotlin/ru/posidata/backend/entity/User.kt delete mode 100644 backend/src/jvmMain/kotlin/ru/posidata/backend/repository/UserRepository.kt delete mode 100644 backend/src/jvmMain/kotlin/ru/posidata/backend/service/TelegramAuthService.kt delete mode 100644 backend/src/jvmMain/kotlin/ru/posidata/backend/service/UserService.kt delete mode 100644 backend/src/jvmMain/resources/application.yml create mode 100644 backend/src/main/kotlin/ru/posidata/backend/controller/UserController.kt create mode 100644 backend/src/test/kotlin/ru/posidata/backend/UserControllerTest.kt rename {frontend/src/jsMain/kotlin/ru/posidata/views/utils/internals => common/src/commonMain/kotlin/ru/posidata/common}/Enums.kt (75%) rename {frontend/src/jsMain/kotlin/ru/posidata/views/components => common/src/commonMain/kotlin/ru/posidata/common}/Resources.kt (96%) diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 5e31ba5..60daebb 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -7,14 +7,16 @@ plugins { } dependencies { + api(project(":common")) implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-oauth2-client") + implementation("org.springframework.boot:spring-boot-starter-test") implementation("org.springframework.boot:spring-boot-starter-validation") implementation("org.springframework.boot:spring-boot-starter-web") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect") - implementation("io.jsonwebtoken:jjwt-api:0.11.5") implementation("com.h2database:h2:2.3.232") + implementation("commons-codec:commons-codec:1.17.1") runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5") runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5") testImplementation(kotlin("test")) diff --git a/backend/src/jvmMain/kotlin/ru/posidata/backend/BackendApplication.kt b/backend/src/jvmMain/kotlin/ru/posidata/backend/BackendApplication.kt deleted file mode 100644 index 9c789f4..0000000 --- a/backend/src/jvmMain/kotlin/ru/posidata/backend/BackendApplication.kt +++ /dev/null @@ -1,13 +0,0 @@ -package ru.posidata.backend - -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.runApplication -import org.springframework.context.annotation.ComponentScan - -@SpringBootApplication -@ComponentScan(basePackages = ["ru.posidata"]) -class BackendApplication - -fun main(args: Array) { - runApplication(*args) -} diff --git a/backend/src/jvmMain/kotlin/ru/posidata/backend/controller/TelegramAuthController.kt b/backend/src/jvmMain/kotlin/ru/posidata/backend/controller/TelegramAuthController.kt deleted file mode 100644 index e36ef0e..0000000 --- a/backend/src/jvmMain/kotlin/ru/posidata/backend/controller/TelegramAuthController.kt +++ /dev/null @@ -1,36 +0,0 @@ -package ru.posidata.backend.controller - -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.security.core.Authentication -import org.springframework.web.bind.annotation.* -import ru.posidata.backend.service.TelegramAuthService - - -@RestController -@RequestMapping(path = ["/api/v1/"]) -class TelegramAuthController(private val telegramAuthService: TelegramAuthService) { - @GetMapping("/user-info") - fun getSelfUserInfo(authentication: Authentication?): String { - return authentication?.principal.toString() - } - - @PostMapping("/test") - fun test(@RequestBody request: Map): String { - return "$request" - } - - @PostMapping("auth/telegram") - fun telegramAuth(@RequestBody request: Map): ResponseEntity { - return try { - val authResult = telegramAuthService.authenticate(request) - if (authResult.isAuthenticated) { - ResponseEntity.ok(authResult.token) - } else { - ResponseEntity.status(HttpStatus.FORBIDDEN).body("Login info hash mismatch") - } - } catch (e: Exception) { - ResponseEntity.status(HttpStatus.FORBIDDEN).body("Server error while authenticating") - } - } -} diff --git a/backend/src/jvmMain/kotlin/ru/posidata/backend/entity/User.kt b/backend/src/jvmMain/kotlin/ru/posidata/backend/entity/User.kt deleted file mode 100644 index 4cdabaa..0000000 --- a/backend/src/jvmMain/kotlin/ru/posidata/backend/entity/User.kt +++ /dev/null @@ -1,15 +0,0 @@ -package ru.posidata.backend.entity - -import jakarta.persistence.* - -@Entity -@Table(name = "users") -data class User( - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - val id: Long = 0, - @Column(unique = true) - val telegramId: Long, - val firstName: String, - val lastName: String?, - val username: String? -) diff --git a/backend/src/jvmMain/kotlin/ru/posidata/backend/repository/UserRepository.kt b/backend/src/jvmMain/kotlin/ru/posidata/backend/repository/UserRepository.kt deleted file mode 100644 index 459ad78..0000000 --- a/backend/src/jvmMain/kotlin/ru/posidata/backend/repository/UserRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package ru.posidata.backend.repository - -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.stereotype.Repository -import ru.posidata.backend.entity.User - -@Repository -interface UserRepository : JpaRepository { - fun findByTelegramId(telegramId: Long): User? -} \ No newline at end of file diff --git a/backend/src/jvmMain/kotlin/ru/posidata/backend/service/TelegramAuthService.kt b/backend/src/jvmMain/kotlin/ru/posidata/backend/service/TelegramAuthService.kt deleted file mode 100644 index 41c5eee..0000000 --- a/backend/src/jvmMain/kotlin/ru/posidata/backend/service/TelegramAuthService.kt +++ /dev/null @@ -1,43 +0,0 @@ -package ru.posidata.backend.service - -import org.springframework.beans.factory.annotation.Value -import org.springframework.stereotype.Service -import java.security.MessageDigest -import java.util.* -import javax.crypto.Mac -import javax.crypto.spec.SecretKeySpec - -@Service -class TelegramAuthService( - @Value("\${telegram.bot.token}") private val telegramToken: String, - private val userService: UserService -) { - fun authenticate(request: Map): AuthResult { - val hash = request["hash"] as String - val sortedRequest = request.toMutableMap().apply { remove("hash") } - - val dataCheckString = sortedRequest.entries - .sortedBy { it.key.lowercase(Locale.getDefault()) } - .joinToString("\n") { "${it.key}=${it.value}" } - - val secretKey = SecretKeySpec( - MessageDigest.getInstance("SHA-256").digest(telegramToken.toByteArray(Charsets.UTF_8)), - "HmacSHA256" - ) - val mac = Mac.getInstance("HmacSHA256") - mac.init(secretKey) - - val result = mac.doFinal(dataCheckString.toByteArray(Charsets.UTF_8)) - val calculatedHash = result.joinToString("") { "%02x".format(it) } - - return if (hash.equals(calculatedHash, ignoreCase = true)) { - val user = userService.findOrCreateUser(request) - println(user) - AuthResult(true, "token") - } else { - AuthResult(false, null) - } - } -} - -data class AuthResult(val isAuthenticated: Boolean, val token: String?) \ No newline at end of file diff --git a/backend/src/jvmMain/kotlin/ru/posidata/backend/service/UserService.kt b/backend/src/jvmMain/kotlin/ru/posidata/backend/service/UserService.kt deleted file mode 100644 index f89f7d6..0000000 --- a/backend/src/jvmMain/kotlin/ru/posidata/backend/service/UserService.kt +++ /dev/null @@ -1,23 +0,0 @@ -package ru.posidata.backend.service - -import org.springframework.stereotype.Service -import ru.posidata.backend.entity.User -import ru.posidata.backend.repository.UserRepository - -@Service -class UserService(private val userRepository: UserRepository) { - fun findOrCreateUser(telegramData: Map): User { - val telegramId = telegramData["id"] as Long - return userRepository.findByTelegramId(telegramId) ?: createUser(telegramData) - } - - private fun createUser(telegramData: Map): User { - val user = User( - telegramId = telegramData["id"] as Long, - firstName = telegramData["first_name"] as String, - lastName = telegramData["last_name"] as? String, - username = telegramData["username"] as? String - ) - return userRepository.save(user) - } -} \ No newline at end of file diff --git a/backend/src/jvmMain/resources/application.yml b/backend/src/jvmMain/resources/application.yml deleted file mode 100644 index 4a78e13..0000000 --- a/backend/src/jvmMain/resources/application.yml +++ /dev/null @@ -1,8 +0,0 @@ -spring: - application: - name: - backend - -telegram: - bot: - token: diff --git a/backend/src/main/kotlin/ru/posidata/backend/controller/TelegramAuthController.kt b/backend/src/main/kotlin/ru/posidata/backend/controller/TelegramAuthController.kt index 381fe75..f34f573 100644 --- a/backend/src/main/kotlin/ru/posidata/backend/controller/TelegramAuthController.kt +++ b/backend/src/main/kotlin/ru/posidata/backend/controller/TelegramAuthController.kt @@ -43,38 +43,9 @@ class TelegramAuthController(private val telegramAuthService: TelegramAuthServic // // // https://posidata.ru/api/test?id=221298772&first_name=Андрей&last_name=Кулешов&username=akuleshov7&photo_url=https%3A%2F%2Ft.me%2Fi%2Fuserpic%2F320%2Fd3fKyG306aXHDBCxZXfWTpGlii6fZqZMo1tBmMPEl_E.jpg&auth_date=1725656645&hash=742dda3a019e57821e1fb7acf9918aeb6f0d734cc5c8612913b6696aeab2c745 - @GetMapping("/test") - fun test( - @RequestParam id: String, - @RequestParam first_name: String, - @RequestParam last_name: String, - @RequestParam photo_url: String, - @RequestParam username: String, - @RequestParam auth_date: String, - @RequestParam hash: String - ): String { - println(username) - return username - } - @GetMapping("/get") fun get(): String { println("Hi!") return "Hi" } - - - @PostMapping("auth/telegram") - fun telegramAuth(@RequestBody request: Map): ResponseEntity { - return try { - val authResult = telegramAuthService.authenticate(request) - if (authResult.isAuthenticated) { - ResponseEntity.ok(authResult.token) - } else { - ResponseEntity.status(HttpStatus.FORBIDDEN).body("Login info hash mismatch") - } - } catch (e: Exception) { - ResponseEntity.status(HttpStatus.FORBIDDEN).body("Server error while authenticating") - } - } } diff --git a/backend/src/main/kotlin/ru/posidata/backend/controller/UserController.kt b/backend/src/main/kotlin/ru/posidata/backend/controller/UserController.kt new file mode 100644 index 0000000..6840dd1 --- /dev/null +++ b/backend/src/main/kotlin/ru/posidata/backend/controller/UserController.kt @@ -0,0 +1,57 @@ +package ru.posidata.backend.controller + +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.* +import ru.posidata.backend.service.TelegramAuthService +import ru.posidata.backend.service.UserService +import ru.posidata.common.ResourceType +import ru.posidata.common.Resources + + +@RestController +@RequestMapping("api") +class UserController( + private val telegramAuthService: TelegramAuthService, + private val userService: UserService +) { + @GetMapping("/get") + fun getResults( + @RequestParam username: String?, + @RequestParam telegramId: Long, + @RequestParam hash: String, + @RequestParam firstName: String?, + @RequestParam lastName: String?, + ): ResponseEntity { + println("Received a request to get results from $username, $telegramId, $hash, $firstName, $lastName") + userService.findOrCreateUser( + username = username, + telegramId = telegramId, + firstName = firstName, + lastName = lastName + ) + return ResponseEntity.status(HttpStatus.OK).body("") + } + + @GetMapping("/answer") + fun submitAnswer( + @RequestParam pokemonName: String, + @RequestParam resourceType: ResourceType, + // @RequestParam gameNumber: Int, + @RequestParam username: String, + @RequestParam hash: String, + ): ResponseEntity { + // user + println(pokemonName) + var count: Int = 0 + val pokemon = Resources.getByName(pokemonName) + ?: return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid pokemon name $pokemonName") + if (pokemon.type == resourceType) { + // correct answer + ++count + } else { + // incorrect answer + } + return ResponseEntity.status(HttpStatus.OK).body(resourceType) + } +} diff --git a/backend/src/main/kotlin/ru/posidata/backend/entity/User.kt b/backend/src/main/kotlin/ru/posidata/backend/entity/User.kt index 4cdabaa..8367d73 100644 --- a/backend/src/main/kotlin/ru/posidata/backend/entity/User.kt +++ b/backend/src/main/kotlin/ru/posidata/backend/entity/User.kt @@ -9,7 +9,16 @@ data class User( val id: Long = 0, @Column(unique = true) val telegramId: Long, - val firstName: String, + val firstName: String?, val lastName: String?, - val username: String? + val username: String?, + + @Column(nullable = true) + var firstGameScore: Int?, + + @Column(nullable = true) + var secondGameScore: Int?, + + @Column(nullable = true) + var thirdGameScore: Int?, ) diff --git a/backend/src/main/kotlin/ru/posidata/backend/repository/UserRepository.kt b/backend/src/main/kotlin/ru/posidata/backend/repository/UserRepository.kt index 459ad78..b6234a7 100644 --- a/backend/src/main/kotlin/ru/posidata/backend/repository/UserRepository.kt +++ b/backend/src/main/kotlin/ru/posidata/backend/repository/UserRepository.kt @@ -1,10 +1,10 @@ package ru.posidata.backend.repository -import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.repository.CrudRepository import org.springframework.stereotype.Repository import ru.posidata.backend.entity.User @Repository -interface UserRepository : JpaRepository { +interface UserRepository : CrudRepository { fun findByTelegramId(telegramId: Long): User? } \ No newline at end of file diff --git a/backend/src/main/kotlin/ru/posidata/backend/service/TelegramAuthService.kt b/backend/src/main/kotlin/ru/posidata/backend/service/TelegramAuthService.kt index 41c5eee..efe733c 100644 --- a/backend/src/main/kotlin/ru/posidata/backend/service/TelegramAuthService.kt +++ b/backend/src/main/kotlin/ru/posidata/backend/service/TelegramAuthService.kt @@ -1,43 +1,58 @@ package ru.posidata.backend.service +import org.apache.commons.codec.digest.HmacUtils import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service -import java.security.MessageDigest -import java.util.* -import javax.crypto.Mac -import javax.crypto.spec.SecretKeySpec + @Service class TelegramAuthService( @Value("\${telegram.bot.token}") private val telegramToken: String, - private val userService: UserService ) { - fun authenticate(request: Map): AuthResult { - val hash = request["hash"] as String - val sortedRequest = request.toMutableMap().apply { remove("hash") } - - val dataCheckString = sortedRequest.entries - .sortedBy { it.key.lowercase(Locale.getDefault()) } - .joinToString("\n") { "${it.key}=${it.value}" } - - val secretKey = SecretKeySpec( - MessageDigest.getInstance("SHA-256").digest(telegramToken.toByteArray(Charsets.UTF_8)), - "HmacSHA256" - ) - val mac = Mac.getInstance("HmacSHA256") - mac.init(secretKey) - - val result = mac.doFinal(dataCheckString.toByteArray(Charsets.UTF_8)) - val calculatedHash = result.joinToString("") { "%02x".format(it) } - - return if (hash.equals(calculatedHash, ignoreCase = true)) { - val user = userService.findOrCreateUser(request) - println(user) - AuthResult(true, "token") - } else { - AuthResult(false, null) - } + fun isValidHash(hash: String): Boolean { + val secreteKey = "1289756607:AAFYuBeHguJKYhDVzwSfYFLX4tF5YbkSU7M" + return true } + +} +/* + +fun main() { + println(isValidHash()) } -data class AuthResult(val isAuthenticated: Boolean, val token: String?) \ No newline at end of file +// Bot token +const val BOT_TOKEN = "7518590686:AAFCT7m70_ANfOZfIACr2C7bOy0igdLNOpg" + +// Function to validate hash +fun isValidHash(): Boolean { + val hash = "742dda3a019e57821e1fb7acf9918aeb6f0d734cc5c8612913b6696aeab2c745" + + val parsedData: Map = mapOf( + "id" to "221298772", + "first_name" to "Андрей", + "last_name" to "Кулешов", + "username" to "akuleshov7", + "photo_url" to "https%3A%2F%2Ft.me%2Fi%2Fuserpic%2F320%2Fd3fKyG306aXHDBCxZXfWTpGlii6fZqZMo1tBmMPEl_E.jpg", + "auth_date" to "1725656645", + "hash" to "742dda3a019e57821e1fb7acf9918aeb6f0d734cc5c8612913b6696aeab2c745" + ) + + // Remove 'hash' value & sort alphabetically + val dataKeys = parsedData.keys.filter { it != "hash" }.sorted() + + // Create line format key= + val items = dataKeys.map { key -> "$key=${parsedData[key]}" } + + // Create check string with '\n' as separator + val dataCheckString = items.joinToString("\n") + + val secretKey: ByteArray = HmacUtils("HmacSHA256", "WebAppData").hmac(BOT_TOKEN) + val initDataHash: String = HmacUtils("HmacSHA256", secretKey).hmacHex(dataCheckString) + + println(initDataHash) + println(hash) + // Return whether the generated hash matches the provided hash + return initDataHash == hash +} +*/ diff --git a/backend/src/main/kotlin/ru/posidata/backend/service/UserService.kt b/backend/src/main/kotlin/ru/posidata/backend/service/UserService.kt index f89f7d6..9d27a73 100644 --- a/backend/src/main/kotlin/ru/posidata/backend/service/UserService.kt +++ b/backend/src/main/kotlin/ru/posidata/backend/service/UserService.kt @@ -6,18 +6,22 @@ import ru.posidata.backend.repository.UserRepository @Service class UserService(private val userRepository: UserRepository) { - fun findOrCreateUser(telegramData: Map): User { - val telegramId = telegramData["id"] as Long - return userRepository.findByTelegramId(telegramId) ?: createUser(telegramData) - } - - private fun createUser(telegramData: Map): User { - val user = User( - telegramId = telegramData["id"] as Long, - firstName = telegramData["first_name"] as String, - lastName = telegramData["last_name"] as? String, - username = telegramData["username"] as? String + fun findOrCreateUser( + username: String?, + telegramId: Long, + firstName: String?, + lastName: String? + ): User { + return userRepository.findByTelegramId(telegramId) ?: userRepository.save( + User( + telegramId = telegramId, + username = username, + firstName = firstName, + lastName = lastName, + firstGameScore = 0, + secondGameScore = null, + thirdGameScore = null + ) ) - return userRepository.save(user) } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/ru/posidata/backend/UserControllerTest.kt b/backend/src/test/kotlin/ru/posidata/backend/UserControllerTest.kt new file mode 100644 index 0000000..2082cdd --- /dev/null +++ b/backend/src/test/kotlin/ru/posidata/backend/UserControllerTest.kt @@ -0,0 +1,17 @@ +package ru.posidata.backend + +import ru.posidata.backend.controller.UserController + +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.mockito.Mock +import org.mockito.MockitoAnnotations +import org.springframework.http.HttpStatus +import ru.posidata.backend.service.TelegramAuthService +import ru.posidata.common.ResourceType +import org.junit.jupiter.api.Assertions.* +import org.mockito.Mockito.verifyNoInteractions + +class UserControllerTest { + +} \ No newline at end of file diff --git a/frontend/src/jsMain/kotlin/ru/posidata/views/utils/internals/Enums.kt b/common/src/commonMain/kotlin/ru/posidata/common/Enums.kt similarity index 75% rename from frontend/src/jsMain/kotlin/ru/posidata/views/utils/internals/Enums.kt rename to common/src/commonMain/kotlin/ru/posidata/common/Enums.kt index f01fe1e..6b4186a 100644 --- a/frontend/src/jsMain/kotlin/ru/posidata/views/utils/internals/Enums.kt +++ b/common/src/commonMain/kotlin/ru/posidata/common/Enums.kt @@ -1,4 +1,4 @@ -package ru.posidata.views.utils.internals +package ru.posidata.common enum class Selection { ANSWER, diff --git a/frontend/src/jsMain/kotlin/ru/posidata/views/components/Resources.kt b/common/src/commonMain/kotlin/ru/posidata/common/Resources.kt similarity index 96% rename from frontend/src/jsMain/kotlin/ru/posidata/views/components/Resources.kt rename to common/src/commonMain/kotlin/ru/posidata/common/Resources.kt index 35bf07b..f07c5af 100644 --- a/frontend/src/jsMain/kotlin/ru/posidata/views/components/Resources.kt +++ b/common/src/commonMain/kotlin/ru/posidata/common/Resources.kt @@ -1,7 +1,7 @@ -package ru.posidata.views.components +package ru.posidata.common -import ru.posidata.views.components.ResourceType.POKEMON -import ru.posidata.views.components.ResourceType.BIG_DATA +import ru.posidata.common.ResourceType.POKEMON +import ru.posidata.common.ResourceType.BIG_DATA enum class ResourceType { POKEMON, @@ -64,6 +64,7 @@ enum class Resources( companion object { fun getById(i: Int): Resources = Resources.entries.find { it.id == i }!! + fun getByName(name: String): Resources? = Resources.entries.find { it.name.uppercase() == name } } fun getName(): String { diff --git a/frontend/src/jsMain/kotlin/ru/posidata/views/main/AnswerCard.kt b/frontend/src/jsMain/kotlin/ru/posidata/views/main/AnswerCard.kt index 081d3eb..d681fd2 100644 --- a/frontend/src/jsMain/kotlin/ru/posidata/views/main/AnswerCard.kt +++ b/frontend/src/jsMain/kotlin/ru/posidata/views/main/AnswerCard.kt @@ -10,13 +10,13 @@ import react.dom.html.ReactHTML.h2 import react.dom.html.ReactHTML.h6 import react.dom.html.ReactHTML.img import react.useState -import ru.posidata.views.components.ResourceType.BIG_DATA -import ru.posidata.views.components.ResourceType.POKEMON -import ru.posidata.views.components.Resources -import ru.posidata.views.utils.internals.Answer -import ru.posidata.views.utils.internals.Selection -import ru.posidata.views.utils.internals.Selection.QUESTION -import ru.posidata.views.utils.internals.Selection.RESULTS +import ru.posidata.common.ResourceType.BIG_DATA +import ru.posidata.common.ResourceType.POKEMON +import ru.posidata.common.Resources +import ru.posidata.common.Answer +import ru.posidata.common.Selection +import ru.posidata.common.Selection.QUESTION +import ru.posidata.common.Selection.RESULTS import web.cssom.* val answerCard = FC { props -> diff --git a/frontend/src/jsMain/kotlin/ru/posidata/views/main/MainView.kt b/frontend/src/jsMain/kotlin/ru/posidata/views/main/MainView.kt index b127331..bd4842e 100644 --- a/frontend/src/jsMain/kotlin/ru/posidata/views/main/MainView.kt +++ b/frontend/src/jsMain/kotlin/ru/posidata/views/main/MainView.kt @@ -3,11 +3,11 @@ package ru.posidata.views.main import js.objects.jso import react.* import react.dom.html.ReactHTML.div -import ru.posidata.views.utils.internals.Answer.NONE -import ru.posidata.views.utils.internals.Selection -import ru.posidata.views.utils.internals.Selection.QUESTION -import ru.posidata.views.utils.internals.Selection.ANSWER -import ru.posidata.views.utils.internals.Selection.RESULTS +import ru.posidata.common.Answer.NONE +import ru.posidata.common.Selection +import ru.posidata.common.Selection.QUESTION +import ru.posidata.common.Selection.ANSWER +import ru.posidata.common.Selection.RESULTS import ru.posidata.views.utils.externals.particles.Particles import ru.posidata.views.utils.externals.telegram.User import web.cssom.* diff --git a/frontend/src/jsMain/kotlin/ru/posidata/views/main/ProgressBar.kt b/frontend/src/jsMain/kotlin/ru/posidata/views/main/ProgressBar.kt index fdf5bb5..0f42144 100644 --- a/frontend/src/jsMain/kotlin/ru/posidata/views/main/ProgressBar.kt +++ b/frontend/src/jsMain/kotlin/ru/posidata/views/main/ProgressBar.kt @@ -7,12 +7,12 @@ import react.dom.html.ReactHTML.div import ru.posidata.views.utils.externals.fontawesome.faThumbsUp import ru.posidata.views.utils.externals.fontawesome.faXmark import ru.posidata.views.utils.externals.fontawesome.fontAwesomeIcon -import ru.posidata.views.utils.internals.Answer.NONE -import ru.posidata.views.utils.internals.Answer.WRONG -import ru.posidata.views.utils.internals.Answer.CORRECT -import ru.posidata.views.utils.internals.Selection.QUESTION -import ru.posidata.views.utils.internals.Answer -import ru.posidata.views.utils.internals.Selection +import ru.posidata.common.Answer.NONE +import ru.posidata.common.Answer.WRONG +import ru.posidata.common.Answer.CORRECT +import ru.posidata.common.Selection.QUESTION +import ru.posidata.common.Answer +import ru.posidata.common.Selection import web.cssom.* val progressBar = FC { props -> diff --git a/frontend/src/jsMain/kotlin/ru/posidata/views/main/QuestionCard.kt b/frontend/src/jsMain/kotlin/ru/posidata/views/main/QuestionCard.kt index 3d3a4e8..2f1d5b9 100644 --- a/frontend/src/jsMain/kotlin/ru/posidata/views/main/QuestionCard.kt +++ b/frontend/src/jsMain/kotlin/ru/posidata/views/main/QuestionCard.kt @@ -5,16 +5,16 @@ import react.* import react.dom.html.ReactHTML.div import react.dom.html.ReactHTML.h1 import react.dom.html.ReactHTML.img -import ru.posidata.views.utils.internals.Answer.WRONG -import ru.posidata.views.utils.internals.Answer.CORRECT -import ru.posidata.views.utils.internals.Selection.ANSWER -import ru.posidata.views.components.ResourceType.BIG_DATA -import ru.posidata.views.components.ResourceType.POKEMON -import ru.posidata.views.components.Resources +import ru.posidata.common.Answer.WRONG +import ru.posidata.common.Answer.CORRECT +import ru.posidata.common.Selection.ANSWER +import ru.posidata.common.ResourceType.BIG_DATA +import ru.posidata.common.ResourceType.POKEMON +import ru.posidata.common.Resources import ru.posidata.views.components.neonLightingText import ru.posidata.views.utils.externals.telegram.User -import ru.posidata.views.utils.internals.Answer -import ru.posidata.views.utils.internals.Selection +import ru.posidata.common.Answer +import ru.posidata.common.Selection import web.cssom.* import kotlin.random.Random diff --git a/frontend/src/jsMain/kotlin/ru/posidata/views/main/ResultCard.kt b/frontend/src/jsMain/kotlin/ru/posidata/views/main/ResultCard.kt index dbfc3c9..dea8087 100644 --- a/frontend/src/jsMain/kotlin/ru/posidata/views/main/ResultCard.kt +++ b/frontend/src/jsMain/kotlin/ru/posidata/views/main/ResultCard.kt @@ -6,7 +6,7 @@ import react.Props import react.StateSetter import react.dom.html.ReactHTML import react.dom.html.ReactHTML.a -import ru.posidata.views.utils.internals.Answer.CORRECT +import ru.posidata.common.Answer.CORRECT import react.dom.html.ReactHTML.div import react.dom.html.ReactHTML.h1 import react.dom.html.ReactHTML.h2 @@ -16,9 +16,9 @@ import react.useState import ru.posidata.views.utils.externals.fontawesome.faGithub import ru.posidata.views.utils.externals.fontawesome.fontAwesomeIcon import ru.posidata.views.utils.externals.telegram.User -import ru.posidata.views.utils.internals.Answer -import ru.posidata.views.utils.internals.Answer.NONE -import ru.posidata.views.utils.internals.Selection +import ru.posidata.common.Answer +import ru.posidata.common.Answer.NONE +import ru.posidata.common.Selection import web.cssom.* val resultCard = FC { props -> diff --git a/frontend/src/jsMain/kotlin/ru/posidata/views/main/Welcome.kt b/frontend/src/jsMain/kotlin/ru/posidata/views/main/Welcome.kt index 6a747c1..39bc4a3 100644 --- a/frontend/src/jsMain/kotlin/ru/posidata/views/main/Welcome.kt +++ b/frontend/src/jsMain/kotlin/ru/posidata/views/main/Welcome.kt @@ -9,7 +9,7 @@ import react.dom.html.ReactHTML.h6 import react.dom.html.ReactHTML.img import ru.posidata.views.utils.externals.telegram.TLoginButton import ru.posidata.views.utils.externals.telegram.User -import ru.posidata.views.utils.internals.Selection +import ru.posidata.common.Selection import web.cssom.* val welcomeCard = FC { props -> @@ -82,6 +82,7 @@ val welcomeCard = FC { props -> botName = "PosiDataBot" buttonSize = "large" onAuthCallback = { user -> + console.log(user) val feUser = User( authDate = user.auth_date, firstName = user.first_name,