Skip to content

Commit

Permalink
Merge pull request #221 from cuappdev/kevin/auth-mobile
Browse files Browse the repository at this point in the history
Google Auth & FR Upvote bug
  • Loading branch information
kevinchan159 authored Oct 30, 2018
2 parents 7907601 + fe6ce79 commit f157b6e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Clicker/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if (error == nil) {
let idToken = user.authentication.idToken ?? ""
let userId = user.userID ?? "ID" // For client-side use only!
let fullName = user.profile.name ?? "First Last"
let givenName = user.profile.givenName ?? "First"
Expand All @@ -96,8 +97,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

let significantEvents: Int = UserDefaults.standard.integer(forKey: Identifiers.significantEventsIdentifier)
UserDefaults.standard.set(significantEvents + 2, forKey: Identifiers.significantEventsIdentifier)
UserAuthenticate(userId: userId, givenName: givenName, familyName: familyName, email: email).make()

UserAuthenticate(idToken: idToken).make()
.done { userSession in
print(userSession)
User.userSession = userSession
Expand Down
10 changes: 2 additions & 8 deletions Clicker/Quarks/UserQuark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,15 @@ struct GetMe: ClickerQuark {
struct UserAuthenticate: ClickerQuark {
typealias ResponseType = UserSession

let userId: String
let givenName: String
let familyName: String
let email: String
let idToken: String

// CHANGE THE ROUTE TO HAVE API VERSION
var route: String {
return "/auth/mobile"
}
var parameters: Parameters {
return [
"userId": userId,
"givenName": givenName,
"familyName": familyName,
"email": email
"idToken": idToken
]
}
let method: HTTPMethod = .post
Expand Down
6 changes: 3 additions & 3 deletions Clicker/Views/Cards/PollOptionsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class PollOptionsCell: UICollectionViewCell, UIScrollViewDelegate {
if let index = frOptionModels.firstIndex(where: { (frOptionModel) -> Bool in
return updatedFROptionModel.answerId == frOptionModel.answerId
}) {
// Have to do index + 1 because first model is SpaceModel
guard let sectionController = adapter.sectionController(forSection: index + 1) as? FROptionSectionController else { return }
// Don't have to do index + 1 because FR does not have topSpaceModel
guard let sectionController = adapter.sectionController(forSection: index) as? FROptionSectionController else { return }
sectionController.update(with: updatedFROptionModel)
frOptionModels[index].numUpvoted = updatedFROptionModel.numUpvoted
frOptionModels[index].didUpvote = updatedFROptionModel.didUpvote
Expand All @@ -188,10 +188,10 @@ class PollOptionsCell: UICollectionViewCell, UIScrollViewDelegate {
extension PollOptionsCell: ListAdapterDataSource {

func objects(for listAdapter: ListAdapter) -> [ListDiffable] {
guard let pollOptionsModel = pollOptionsModel else { return [] }
var models = [ListDiffable]()
let topSpaceModel = SpaceModel(space: LayoutConstants.pollOptionsPadding)
let bottomSpaceModel = SpaceModel(space: LayoutConstants.pollOptionsPadding + LayoutConstants.interItemPadding)
guard let pollOptionsModel = pollOptionsModel else { return [] }
switch pollOptionsModel.type {
case .mcResult(let mcResultModels):
models.append(topSpaceModel)
Expand Down

0 comments on commit f157b6e

Please sign in to comment.