ToolController: impl signup

This commit is contained in:
Andrew Glaze
2025-05-23 13:26:13 -04:00
parent 49cd62da1d
commit c29f454881
7 changed files with 56 additions and 20 deletions

View File

@@ -14,6 +14,10 @@ struct ToolController: RouteCollection {
func signup(req: Request) async throws -> Response {
let body = try req.content.decode(SignupReq.self, using: MsgPackDecoder())
guard let udid = req.headers["udid"].first else {
throw Abort(.badRequest)
}
guard
let session = try await Session.query(on: req.db).filter(\.$id == body.access_token).first(),
session.type == SessionType.ZAT
@@ -22,9 +26,7 @@ struct ToolController: RouteCollection {
}
let accountId = session.$account.id
if let player = try await Player.query(on: req.db).filter(\.$account.$id == accountId).first() {
} else {
if try await Player.query(on: req.db).filter(\.$account.$id == accountId).first() == nil {
guard let account = try await Account.query(on: req.db).filter(\.$id == accountId).first() else {
throw Abort(.forbidden, reason: "Account ID does not exist")
}
@@ -33,7 +35,28 @@ struct ToolController: RouteCollection {
try await player.save(on: req.db)
}
throw Abort(.notImplemented)
let viewerSession = try await Session.query(on: req.db)
.filter(\.$account.$id == accountId)
.filter(\.$type == .VIEWER)
.first() ?? Session(accountId: accountId, expires: Date.now, type: .VIEWER)
if (viewerSession.hasChanges) {
try await viewerSession.save(on: req.db)
}
let response = Response(status:.ok)
try response.content.encode(SignupRes(
data_headers: DataHeadersRes(
short_udid: 0,
viewer_id: Int(try viewerSession.requireID())!,
udid: udid,
servertime: Int(Date.now.timeIntervalSince1970 * 100),
result_code: 1
),
data: []
), using: MsgPackEncoder())
return response
}
}
@@ -46,3 +69,16 @@ struct SignupReq: Content {
let device_id: Double
let idp_code: String
}
struct DataHeadersRes: Content {
let short_udid: Int
let viewer_id: Int
let udid: String
let servertime: Int
let result_code: Int
}
struct SignupRes: Content {
let data_headers: DataHeadersRes
let data: [String]
}

View File

@@ -87,7 +87,6 @@ struct AuthController: RouteCollection {
guard let account = account else {
throw Abort(.badRequest)
}
print("got here")
if account.idpAlias != idpAlias {
account.idpAlias = idpAlias