ToolController: impl signup
This commit is contained in:
@@ -14,6 +14,10 @@ struct ToolController: RouteCollection {
|
|||||||
func signup(req: Request) async throws -> Response {
|
func signup(req: Request) async throws -> Response {
|
||||||
let body = try req.content.decode(SignupReq.self, using: MsgPackDecoder())
|
let body = try req.content.decode(SignupReq.self, using: MsgPackDecoder())
|
||||||
|
|
||||||
|
guard let udid = req.headers["udid"].first else {
|
||||||
|
throw Abort(.badRequest)
|
||||||
|
}
|
||||||
|
|
||||||
guard
|
guard
|
||||||
let session = try await Session.query(on: req.db).filter(\.$id == body.access_token).first(),
|
let session = try await Session.query(on: req.db).filter(\.$id == body.access_token).first(),
|
||||||
session.type == SessionType.ZAT
|
session.type == SessionType.ZAT
|
||||||
@@ -22,9 +26,7 @@ struct ToolController: RouteCollection {
|
|||||||
}
|
}
|
||||||
let accountId = session.$account.id
|
let accountId = session.$account.id
|
||||||
|
|
||||||
if let player = try await Player.query(on: req.db).filter(\.$account.$id == accountId).first() {
|
if try await Player.query(on: req.db).filter(\.$account.$id == accountId).first() == nil {
|
||||||
|
|
||||||
} else {
|
|
||||||
guard let account = try await Account.query(on: req.db).filter(\.$id == accountId).first() else {
|
guard let account = try await Account.query(on: req.db).filter(\.$id == accountId).first() else {
|
||||||
throw Abort(.forbidden, reason: "Account ID does not exist")
|
throw Abort(.forbidden, reason: "Account ID does not exist")
|
||||||
}
|
}
|
||||||
@@ -33,7 +35,28 @@ struct ToolController: RouteCollection {
|
|||||||
try await player.save(on: req.db)
|
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 device_id: Double
|
||||||
let idp_code: String
|
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]
|
||||||
|
}
|
||||||
|
@@ -87,7 +87,6 @@ struct AuthController: RouteCollection {
|
|||||||
guard let account = account else {
|
guard let account = account else {
|
||||||
throw Abort(.badRequest)
|
throw Abort(.badRequest)
|
||||||
}
|
}
|
||||||
print("got here")
|
|
||||||
|
|
||||||
if account.idpAlias != idpAlias {
|
if account.idpAlias != idpAlias {
|
||||||
account.idpAlias = idpAlias
|
account.idpAlias = idpAlias
|
||||||
|
@@ -5,6 +5,7 @@ extension MsgPackEncoder: @retroactive ContentEncoder, @retroactive @unchecked S
|
|||||||
public func encode<E>(_ encodable: E, to body: inout ByteBuffer, headers: inout HTTPHeaders) throws where E : Encodable {
|
public func encode<E>(_ encodable: E, to body: inout ByteBuffer, headers: inout HTTPHeaders) throws where E : Encodable {
|
||||||
let data = try self.encode(encodable)
|
let data = try self.encode(encodable)
|
||||||
body.writeString(data.base64EncodedString())
|
body.writeString(data.base64EncodedString())
|
||||||
|
headers.contentType = .init(type: "application", subType: "x-msgpack")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,8 +28,8 @@ struct CreatePlayers: AsyncMigration {
|
|||||||
.field("paid_mana", .int, .required)
|
.field("paid_mana", .int, .required)
|
||||||
.field("enable_auto_3x", .bool, .required)
|
.field("enable_auto_3x", .bool, .required)
|
||||||
.field("account_id", .int, .required, .references("accounts", "id"))
|
.field("account_id", .int, .required, .references("accounts", "id"))
|
||||||
.field("tutorial_step", .int, .required)
|
.field("tutorial_step", .int)
|
||||||
.field("tutorial_skip_flag", .int, .required)
|
.field("tutorial_skip_flag", .int)
|
||||||
.create()
|
.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,11 +17,19 @@ final class Session: Model, @unchecked Sendable {
|
|||||||
|
|
||||||
init() { }
|
init() { }
|
||||||
|
|
||||||
init(account: Account, expires: Date, type: SessionType) throws {
|
convenience init(account: Account, expires: Date, type: SessionType) throws {
|
||||||
self.id = UUID().uuidString
|
self.init(accountId: try account.requireID(), expires: expires, type: type)
|
||||||
self.$account.id = try account.requireID()
|
}
|
||||||
|
|
||||||
|
init(accountId: Int, expires: Date, type: SessionType) {
|
||||||
|
self.$account.id = accountId
|
||||||
self.expires = expires
|
self.expires = expires
|
||||||
self.type = type
|
self.type = type
|
||||||
|
if (type != .VIEWER) {
|
||||||
|
self.id = UUID().uuidString
|
||||||
|
} else {
|
||||||
|
self.id = String(Int.random())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,8 +15,8 @@ enum Entrypoint {
|
|||||||
// You can enable it if you'd like to reduce the amount of context switching between NIO and Swift Concurrency.
|
// You can enable it if you'd like to reduce the amount of context switching between NIO and Swift Concurrency.
|
||||||
// Note: this has caused issues with some libraries that use `.wait()` and cleanly shutting down.
|
// Note: this has caused issues with some libraries that use `.wait()` and cleanly shutting down.
|
||||||
// If enabled, you should be careful about calling async functions before this point as it can cause assertion failures.
|
// If enabled, you should be careful about calling async functions before this point as it can cause assertion failures.
|
||||||
let executorTakeoverSuccess = NIOSingletons.unsafeTryInstallSingletonPosixEventLoopGroupAsConcurrencyGlobalExecutor()
|
//let executorTakeoverSuccess = NIOSingletons.unsafeTryInstallSingletonPosixEventLoopGroupAsConcurrencyGlobalExecutor()
|
||||||
app.logger.debug("Tried to install SwiftNIO's EventLoopGroup as Swift's global concurrency executor", metadata: ["success": .stringConvertible(executorTakeoverSuccess)])
|
//app.logger.debug("Tried to install SwiftNIO's EventLoopGroup as Swift's global concurrency executor", metadata: ["success": .stringConvertible(executorTakeoverSuccess)])
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try await configure(app)
|
try await configure(app)
|
||||||
|
@@ -2,14 +2,6 @@ import Fluent
|
|||||||
import Vapor
|
import Vapor
|
||||||
|
|
||||||
func routes(_ app: Application) throws {
|
func routes(_ app: Application) throws {
|
||||||
app.get { req async in
|
|
||||||
"It works!"
|
|
||||||
}
|
|
||||||
|
|
||||||
app.get("hello") { req async -> String in
|
|
||||||
"Hello, world!"
|
|
||||||
}
|
|
||||||
|
|
||||||
try app.register(collection: InfodeskController())
|
try app.register(collection: InfodeskController())
|
||||||
try app.register(collection: OpenApiController())
|
try app.register(collection: OpenApiController())
|
||||||
try app.register(collection: ApiController())
|
try app.register(collection: ApiController())
|
||||||
|
Reference in New Issue
Block a user