Skip to content

Commit

Permalink
Update App UI
Browse files Browse the repository at this point in the history
  • Loading branch information
lhwdev committed Oct 26, 2020
1 parent ba8d14a commit 21018a0
Show file tree
Hide file tree
Showing 19 changed files with 442 additions and 165 deletions.
7 changes: 2 additions & 5 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
plugins {
id "java-library"
id "kotlin"
id "kotlinx-serialization"
}

dependencies {
implementation "org.bouncycastle:bcpkix-jdk15to18:1.66"

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.4.0-M1"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0"

// platform-specific
implementation "com.eclipsesource.j2v8:j2v8_win32_x86_64:2.2.1"
}
11 changes: 10 additions & 1 deletion api/src/main/kotlin/com/lhwdev/selfTestMacro/api/findUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.io.IOException
import java.math.BigInteger
import java.security.KeyFactory
import java.security.Security
import java.security.spec.RSAPublicKeySpec
import javax.crypto.Cipher

Expand Down Expand Up @@ -66,10 +68,17 @@ suspend fun findUser(schoolInfo: SchoolInfo, request: GetUserTokenRequestBody) =

lateinit var encodeBase64: (ByteArray) -> String

private val sProvider = run {
Security.removeProvider("BC")
val provider = BouncyCastleProvider()
Security.addProvider(provider)
provider
}


suspend fun encrypt(string: String): String = ioTask {
val key = RSAPublicKeySpec(BigInteger("30718937712611605689191751047964347711554702318809238360089112453166217803395521606458190795722565177328746277011809492198037993902927400109154434682159584719442248913593972742086295960255192532052628569970645316811605886842040898815578676961759671712587342568414746446165948582657737331468733813122567503321355924190641302039446055143553127897636698729043365414410208454947672037202818029336707554263659582522814775377559532575089915217472518288660143323212695978110773753720635850393399040827859210693969622113812618481428838504301698541638186158736040620420633114291426890790215359085924554848097772407366395041461"), BigInteger("65537"))
val cipher = Cipher.getInstance("RSA")
val cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", sProvider)
cipher.init(Cipher.PUBLIC_KEY, KeyFactory.getInstance("RSA").generatePublic(key))
encodeBase64(cipher.doFinal(string.toByteArray()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ private data class GetDetailedUserInfoRequestBody(

@Serializable
data class DetailedUserInfo(
@SerialName("userInfo") val userName: String,
@SerialName("registerYmd") val lastRegisterDate: String,
@SerialName("registerDtm") val lastRegisterAt: String,
@SerialName("userName") val userName: String,
@SerialName("orgCode") val schoolCode: String,
@SerialName("orgName") val schoolName: String,
@SerialName("registerYmd") val lastRegisterDate: String?,
@SerialName("registerDtm") val lastRegisterAt: String?,
@SerialName("isHealthy") val isHealthy: Boolean,
@SerialName("deviceUuid") val deviceUuid: String?,
)
) {
fun toUserInfoString() = "$userName($schoolName)"
fun toLastRegisterInfoString() =
"최근 자가진단: ${if(lastRegisterAt == null) "미참여" else ((if(isHealthy) "정상" else "유증상") + "($lastRegisterAt)")}"
}


/*
Expand All @@ -46,12 +52,18 @@ data class DetailedUserInfo(
* userPNo: "..."
* wrongPassCnt: 0
*/
suspend fun getDetailedUserInfo(schoolInfo: SchoolInfo, userInfo: UserInfo): DetailedUserInfo = ioTask {
fetch(
schoolInfo.requestUrl.child("getUserInfo"),
method = HttpMethod.post,
headers = sDefaultFakeHeader + mapOf("Content-Type" to ContentTypes.json, "Authorization" to userInfo.token.token),
body = Json.encodeToString(GetDetailedUserInfoRequestBody.serializer(),
GetDetailedUserInfoRequestBody(schoolInfo.code, userInfo.userId))
).toJsonLoose()
}
suspend fun getDetailedUserInfo(schoolInfo: SchoolInfo, userInfo: UserInfo): DetailedUserInfo =
ioTask {
fetch(
schoolInfo.requestUrl.child("getUserInfo"),
method = HttpMethod.post,
headers = sDefaultFakeHeader + mapOf(
"Content-Type" to ContentTypes.json,
"Authorization" to userInfo.token.token
),
body = Json.encodeToString(
GetDetailedUserInfoRequestBody.serializer(),
GetDetailedUserInfoRequestBody(schoolInfo.code, userInfo.userId)
)
).toJsonLoose()
}
13 changes: 11 additions & 2 deletions api/src/main/kotlin/com/lhwdev/selfTestMacro/api/registerServey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ data class SurveyData(
@SerialName("upperUserNameEncpt") val userName: String
)

@Serializable
data class SurveyResult(
@SerialName("registerDtm") val registerAt: String
// what is 'inveYmd'?
)

suspend fun registerSurvey(schoolInfo: SchoolInfo, token: UserToken, surveyData: SurveyData) = ioTask {
suspend fun registerSurvey(
schoolInfo: SchoolInfo,
token: UserToken,
surveyData: SurveyData
): SurveyResult = ioTask {
fetch(
schoolInfo.requestUrlBase.child("registerServey"),
method = HttpMethod.post,
Expand All @@ -64,5 +73,5 @@ suspend fun registerSurvey(schoolInfo: SchoolInfo, token: UserToken, surveyData:
"Authorization" to token.token
),
body = Json { encodeDefaults = true }.encodeToString(SurveyData.serializer(), surveyData)
).requireOk()
).toJsonLoose()
}
13 changes: 0 additions & 13 deletions api/src/main/kotlin/com/lhwdev/selfTestMacro/httpFetch.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
@file:OptIn(ExperimentalCoroutinesApi::class)

package com.lhwdev.selfTestMacro

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.debug.DebugProbes
import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
Expand All @@ -15,13 +11,6 @@ import java.net.URL
import java.net.URLDecoder


@Suppress("unused")
val dummy: Unit = run {
DebugProbes.install()
DebugProbes.enableCreationStackTraces = true
}


enum class HttpMethod(val requestName: String) {
get("GET"),
head("HEAD"),
Expand Down Expand Up @@ -96,8 +85,6 @@ suspend fun DisposeScope.fetch( // for debug
// open
val connection = url.openConnection() as HttpURLConnection
println("\u001b[1;91m<- send HTTP \u001B[93m${HttpMethod.post}\u001b[0m: ${readableUrl(url.toString())}")
// println(" * called from: ")
// println(DebugProbes.scopeToString(this))
if(body != null) connection.doOutput = true

connection.requestMethod = method.requestName
Expand Down
4 changes: 3 additions & 1 deletion api/src/main/kotlin/com/lhwdev/selfTestMacro/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.lhwdev.selfTestMacro

import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
Expand All @@ -14,20 +15,21 @@ import java.net.URLEncoder
fun URL.child(childPath: String) = URL(this, path.removeSuffix("/") + "/" + childPath)

// our project is too small to use form like 'major.minor.bugFixes'
@Serializable
data class Version(val major: Int, val minor: Int) : Comparable<Version> {
override fun compareTo(other: Version) =
if(major == other.major) minor - other.minor
else major - other.major
}



fun Version(string: String): Version {
val split = string.split('.').map { it.toInt() }
require(split.size == 2)
return Version(split[0], split[1])
}

@Serializable
data class VersionSpec(val from: Version, val to: Version) {
operator fun contains(version: Version) = version in from..to
}
Expand Down
1 change: 0 additions & 1 deletion api/src/main/resources/jsencrypt.min.js

This file was deleted.

17 changes: 10 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ plugins {
}

android {
compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.lhwdev.selfTestMacro"
minSdkVersion 19
targetSdkVersion 29
versionCode 5
versionName "1.4"
targetSdkVersion 30
versionCode 1000
versionName "2.0"

multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
Expand All @@ -39,14 +41,15 @@ android {

kotlinOptions {
jvmTarget = "1.8"

}

}


dependencies {
implementation project(":api")

implementation "androidx.multidex:multidex:2.0.1"

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

<application
android:name=".MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:windowSoftInputMode="stateHidden|adjustResize"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
Expand Down Expand Up @@ -41,4 +43,4 @@
</receiver>
</application>

</manifest>
</manifest>
Loading

0 comments on commit 21018a0

Please sign in to comment.