impl Account Table

This commit is contained in:
Andrew Glaze
2025-05-15 22:14:00 -04:00
parent 04c5660f7d
commit cada630298
14 changed files with 268 additions and 211 deletions

View File

@@ -0,0 +1,160 @@
import Vapor
import Fluent
struct AuthController: RouteCollection {
func boot(routes: any RoutesBuilder) throws {
routes.post("v4", "device", "accessToken", "create", use: self.createAccessToken)
routes.post("v3", "agreement", "getForLogin", use: self.loginAgreement)
routes.post("v4", "auth", "loginDevice", use: self.loginDevice)
}
@Sendable
func createAccessToken(req: Request) async throws -> AccessTokenRes {
AccessTokenRes(
accessToken: "fwPla7fQ8ty9+DZT/lD//uWZD4uD6C4lD6gGIIZTLKRTQ52/SLCRmk/370jcWGs+e+1iSoZtL7lj8ov9B0/jHmijH4nsHPQT6pchaQM1M9mtwYNQq0BWhVr9hF0jjCK/a5LIVd1kBac/Gemv29WKEDKSrUS9HxxUigoPRwtOy8m+oDj9FmDJZ+rzqWCc0QjES4Ky0fTpXZ7ESoguDzNmRtW3FYr+OFexw8wBPlwiC4w=",
expiryTime: Int(Date.init(timeIntervalSinceNow: .init(0)).timeIntervalSince1970)
)
}
@Sendable
func loginAgreement(req: Request) async throws -> String {
let body = try req.content.decode(LoginAgreementReq.self, as: .json)
return #"""
{
"adAgreementStatus": "n",
"agreement": {
"E001": "n",
"E002": "n",
"E006": "n",
"N002": "n",
"N003": "n",
"timestamp": "\#(Int(Date().timeIntervalSince1970) * 1000)"
},
"agreementPopup": "n",
"appId": "\#(body.appId)",
"appName": "World Flipper (NA)",
"context": "login",
"country": "\#(body.country)",
"firstAgreement": "n",
"idpCode": "\#(body.idpCode)",
"idpId": "6076008646",
"informationSecurityCountry": "kr",
"kakaoSyncAgreementGetSet": "n",
"kakaoSyncStatus": "off",
"kakaogameSdkVer": "3.0",
"lang": "\#(body.lang)",
"partnerId": 825,
"partnerName": " ",
"plusFriendStatusInfo": null,
"policyApplyTime": 1630854000000
}
"""#
}
@Sendable
func loginDevice(req: Request) async throws -> Response {
let body = try req.content.decode(LoginDeviceReq.self, as: .json)
let idpAlias = generateIdpAlias(appId: body.appId, deviceId: body.deviceId, serialNo: body.serialNo)
let idpId = body.whiteKey
var account: Account? = nil
if let rawAccountId = req.headers["playerId"].first, let accountId = Int(rawAccountId) {
if let existingAccount = try await Account.query(on: req.db).filter(\.$id == accountId).first() {
account = existingAccount
}
} else if let existingAccount = try await Account.query(on: req.db).filter(\.$idpId == idpId).first() {
account = existingAccount
} else {
let account = Account(appId: body.appId, idpAlias: idpAlias, idpCode: "zd3", idpId: idpId, status: "normal")
try await account.create(on: req.db)
}
guard let account = account else {
return Response(status: .badRequest, body: "{\"error\": \"Bad Request\", \"message\": \"Invalid playerId provided.\"}")
}
return Response(status: .notImplemented)
}
}
struct AccessTokenRes: Content {
let accessToken: String
let expiryTime: Int
}
struct LoginAgreementReq: Content {
let deviceId: String
let os: String
let country: String
let lang: String
let appId: String
let idpCode: String
let serialNo: String
let idpId: String
}
struct LoginDeviceReq: Content {
let lang: String
let clientTime: Int
let deviceId: String
let serialNo: String
let country: String
let whiteKey: String
let market: String
let appSecret: String
let deviceAppKey: String
let sdkVer: String
let appVer: String
let os: String
let loginType: String
let accessToken: String
let resume: Bool
let osVer: String
let appId: String
let deviceModel: String
let network: String
let isIosAppOnMac: Bool
let adid: String
let timezoneOffset: Int
let fields: [String]
let telecom: String
}
struct LoginDeviceRes: Content {
let zatExpiryTime: Int
let zrtExpiryTime: Int
let firstLogin: Bool
let externalToken: String
let zat: String
let zrt: String
let player: Player
}
struct Player: Content {
let idpId: String
let appId: String
let lang: String
let playerId: String
let agreement: AgreementResponse
let pushOption: PushOptionResponse
let lastLoginTime: Int
let regTime: Int
let idpAlias: String
let firstLoginTime: Int
let status: String
}
struct AgreementResponse: Content {
let E001: String
let E002: String
let E006: String
let N002: String
let N003: String
let timestamp: String
}
struct PushOptionResponse: Content {
let night: String
let player: String
}

View File

@@ -0,0 +1,14 @@
import Vapor
struct UtilController: RouteCollection {
func boot(routes: any RoutesBuilder) throws {
let group = routes.grouped("v3", "util")
group.post("country", "get", use: self.getCountry)
}
@Sendable
func getCountry(req: Request) async throws -> String {
"{\"country\": \"us\"}"
}
}