Skip to content

Commit

Permalink
Fixed attendee login
Browse files Browse the repository at this point in the history
  • Loading branch information
s0phialiu committed Nov 23, 2023
1 parent 03a284d commit 914f708
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 41 deletions.
28 changes: 13 additions & 15 deletions HIAPI/Models/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,24 @@ public struct ProfileContainer: Decodable, APIReturnable {

public struct Profile: Codable, APIReturnable {
internal enum CodingKeys: String, CodingKey {
case id
case firstName
case lastName
case userId
case displayName
case points
case foodWave
case discord
//case foodWave
case discordTag
case avatarUrl
}

public let id: String
public let firstName: String
public let lastName: String
public let userId: String
public let displayName: String
public let points: Int
public let foodWave: Int
public let discord: String
//public let foodWave: Int
public let discordTag: String
public let avatarUrl: String
}

public struct ProfileFavorites: Codable, APIReturnable {
public let id: String
public let userId: String
public let profiles: Set<String>
}

Expand All @@ -60,13 +58,13 @@ public struct LeaderboardProfileContainer: Decodable, APIReturnable {

public struct LeaderboardProfile: Codable, APIReturnable {
internal enum CodingKeys: String, CodingKey {
case id
case discord
case userId
case discordTag
case points
}

public let id: String
public let discord: String
public let userId: String
public let discordTag: String
public let points: Int
}

Expand Down
8 changes: 4 additions & 4 deletions HackIllinois/DataSources/HIProfileDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ final class HIProfileDataSource {
}
coreDataProfilesToUpdate.forEach { (coreDataProfile, apiProfile) in
// Update CoreData profile.
coreDataProfile.id = apiProfile.id
coreDataProfile.discord = apiProfile.discord
coreDataProfile.id = apiProfile.userId
coreDataProfile.discord = apiProfile.discordTag
coreDataProfile.points = Int32(apiProfile.points)
}
apiProfilesToInsert.forEach { apiProfile in
// Create CoreData profile.
let coreDataProfile = LeaderboardProfile(context: context)
coreDataProfile.id = apiProfile.id
coreDataProfile.discord = apiProfile.discord
coreDataProfile.id = apiProfile.userId
coreDataProfile.discord = apiProfile.discordTag
coreDataProfile.points = Int32(apiProfile.points)
}

Expand Down
16 changes: 9 additions & 7 deletions HackIllinois/FlowControllers/HILoginFlowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ private extension HILoginFlowController {
user.roles = apiRolesContainer.roles
profile.roles = apiRolesContainer.roles
if user.provider == .github && user.roles.contains(.ATTENDEE) {
self?.populateRegistrationData(buildingUser: user, profile: profile, sender: sender)
DispatchQueue.main.async {
NotificationCenter.default.post(name: .loginUser, object: nil, userInfo: ["user": user])
}
self?.populateProfileData(buildingProfile: profile, sender: sender)
} else if user.provider == .google {
if user.roles.contains(.STAFF) {
DispatchQueue.main.async {
Expand All @@ -210,7 +213,7 @@ private extension HILoginFlowController {
.launch()
}

private func populateRegistrationData(buildingUser user: HIUser, profile: HIProfile, sender: HIBaseViewController) {
/*private func populateRegistrationData(buildingUser user: HIUser, profile: HIProfile, sender: HIBaseViewController) {
HIAPI.RegistrationService.getAttendee()
.onCompletion { [weak self] result in
do {
Expand All @@ -229,19 +232,18 @@ private extension HILoginFlowController {
}
.authorize(with: user)
.launch()
}
}*/

private func populateProfileData(buildingProfile profile: HIProfile, sender: HIBaseViewController) {
HIAPI.ProfileService.getUserProfile()
.onCompletion { [weak self] result in
do {
let (apiProfile, _) = try result.get()
var profile = profile
profile.id = apiProfile.id
profile.firstName = apiProfile.firstName
profile.lastName = apiProfile.lastName
profile.userId = apiProfile.userId
profile.displayName = apiProfile.displayName
profile.points = apiProfile.points
profile.discord = apiProfile.discord
profile.discordTag = apiProfile.discordTag
profile.avatarUrl = apiProfile.avatarUrl
DispatchQueue.main.async {
NotificationCenter.default.post(name: .loginProfile, object: nil, userInfo: ["profile": profile])
Expand Down
4 changes: 2 additions & 2 deletions HackIllinois/Misc/MixTypeComparable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ extension Project: MixTypeComparable {
}

extension HIAPI.Profile: MixTypeComparable {
var comparable: String { return id }
var comparable: String { return userId }
}

extension Profile: MixTypeComparable {
var comparable: String { return id }
}

extension HIAPI.LeaderboardProfile: MixTypeComparable {
var comparable: String { return id }
var comparable: String { return userId }
}

extension LeaderboardProfile: MixTypeComparable {
Expand Down
9 changes: 4 additions & 5 deletions HackIllinois/Models/HIProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ struct HIProfile: Codable {
var attendee: HIAPI.Attendee?
var token = ""
var oauthCode = ""
var id = ""
var firstName = ""
var lastName = ""
var userId = ""
var displayName = ""
var points = 0
var foodWave = 0
//var foodWave = 0
var timezone = ""
var discord = ""
var discordTag = ""
var avatarUrl = ""

init(provider: HIAPI.AuthService.OAuthProvider) {
Expand Down
15 changes: 7 additions & 8 deletions HackIllinois/ViewControllers/HIProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ extension HIProfileViewController {
view.willRemoveSubview(profileCardController!.view)
profileCardController?.removeFromParent()
}
profileCardController = UIHostingController(rootView: HIProfileCardView(firstName: profile.firstName,
lastName: profile.lastName,
profileCardController = UIHostingController(rootView: HIProfileCardView(firstName: profile.displayName,
lastName: profile.displayName,
dietaryRestrictions: dietaryRestrictions,
points: profile.points,
tier: profileTier,
foodWave: profile.foodWave,
id: profile.id
foodWave: 1,//profile.foodWave,
id: profile.userId
))

addChild(profileCardController!)
Expand Down Expand Up @@ -159,11 +159,10 @@ extension HIProfileViewController {
.onCompletion { [weak self] result in
do {
let (apiProfile, _) = try result.get()
self?.profile.id = apiProfile.id
self?.profile.firstName = apiProfile.firstName
self?.profile.lastName = apiProfile.lastName
self?.profile.userId = apiProfile.userId
self?.profile.displayName = apiProfile.discordTag
self?.profile.points = apiProfile.points
self?.profile.foodWave = apiProfile.foodWave
//self?.profile.foodWave = apiProfile.foodWave
DispatchQueue.main.async {
NotificationCenter.default.post(name: .loginProfile, object: nil, userInfo: ["profile": self?.profile])
self?.updateProfile()
Expand Down

0 comments on commit 914f708

Please sign in to comment.