Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAsterisco committed Apr 19, 2020
2 parents b7465b7 + a780c7d commit 74d19f9
Show file tree
Hide file tree
Showing 38 changed files with 398 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Example/RxFireAuth.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/* Begin PBXFileReference section */
0AED3E55FA40FCB4B6C8E661 /* Pods-RxFireAuth_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxFireAuth_Tests.release.xcconfig"; path = "Target Support Files/Pods-RxFireAuth_Tests/Pods-RxFireAuth_Tests.release.xcconfig"; sourceTree = "<group>"; };
2397EC64964095AD9D0AF655 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
37E0099370B6231F1473F284 /* RxFireAuth.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = RxFireAuth.podspec; path = ../RxFireAuth.podspec; sourceTree = "<group>"; };
37E0099370B6231F1473F284 /* RxFireAuth.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = RxFireAuth.podspec; path = ../RxFireAuth.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
3DBD179F238CA2B242FEE4F7 /* Pods-RxFireAuth_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxFireAuth_Tests.debug.xcconfig"; path = "Target Support Files/Pods-RxFireAuth_Tests/Pods-RxFireAuth_Tests.debug.xcconfig"; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* RxFireAuth_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RxFireAuth_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down
63 changes: 61 additions & 2 deletions Example/RxFireAuth/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,67 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Profile" id="LmC-Tr-bG8">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="7Pd-sI-QgH">
<rect key="frame" x="0.0" y="516.5" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="7Pd-sI-QgH" id="m7c-9O-tD0">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Display Name" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="xXd-3v-zRi">
<rect key="frame" x="20" y="0.0" width="335" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="d0Z-eT-AXj"/>
</constraints>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" keyboardType="emailAddress" textContentType="username"/>
</textField>
</subviews>
<constraints>
<constraint firstItem="xXd-3v-zRi" firstAttribute="leading" secondItem="m7c-9O-tD0" secondAttribute="leading" constant="20" symbolic="YES" id="FCP-Ln-4mR"/>
<constraint firstAttribute="bottom" secondItem="xXd-3v-zRi" secondAttribute="bottom" id="IRa-2S-XiV"/>
<constraint firstItem="xXd-3v-zRi" firstAttribute="top" secondItem="m7c-9O-tD0" secondAttribute="top" id="eEK-Ba-rDB"/>
<constraint firstAttribute="trailing" secondItem="xXd-3v-zRi" secondAttribute="trailing" constant="20" symbolic="YES" id="gN4-ex-Y5p"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="QW5-BY-9do">
<rect key="frame" x="0.0" y="560" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="QW5-BY-9do" id="U26-7b-cwC">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ZZe-YT-b6s">
<rect key="frame" x="20" y="0.0" width="335" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="A9Y-tz-oTf"/>
</constraints>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<state key="normal" title="Update Profile">
<color key="titleColor" systemColor="systemGreenColor" red="0.20392156859999999" green="0.78039215689999997" blue="0.34901960780000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="updateProfileWithSender:" destination="ctm-QS-frk" eventType="touchUpInside" id="Hvh-3Q-jG4"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="ZZe-YT-b6s" secondAttribute="bottom" id="Gpb-iD-v8q"/>
<constraint firstItem="ZZe-YT-b6s" firstAttribute="top" secondItem="U26-7b-cwC" secondAttribute="top" id="WK1-Vc-WWp"/>
<constraint firstAttribute="trailing" secondItem="ZZe-YT-b6s" secondAttribute="trailing" constant="20" symbolic="YES" id="h11-nz-9oD"/>
<constraint firstItem="ZZe-YT-b6s" firstAttribute="leading" secondItem="U26-7b-cwC" secondAttribute="leading" constant="20" symbolic="YES" id="kX5-F5-29M"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="4Xi-fE-FbV">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="6b1-ph-fGM">
<rect key="frame" x="0.0" y="496.5" width="375" height="43.5"/>
<rect key="frame" x="0.0" y="639.5" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="6b1-ph-fGM" id="Wgz-JJ-qeT">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
Expand All @@ -164,7 +221,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="aRd-y8-EFj">
<rect key="frame" x="0.0" y="540" width="375" height="43.5"/>
<rect key="frame" x="0.0" y="683" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="aRd-y8-EFj" id="Zg7-XD-CeA">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
Expand Down Expand Up @@ -203,10 +260,12 @@
<connections>
<outlet property="dataMigrationControl" destination="Clf-Hh-vgO" id="PPg-Uq-ziK"/>
<outlet property="loginField" destination="hRm-F9-3g3" id="HaC-Kz-FKX"/>
<outlet property="nameField" destination="xXd-3v-zRi" id="igw-fT-jDW"/>
<outlet property="passwordField" destination="FMT-pY-asG" id="7Ay-uj-9lj"/>
<outlet property="signInButton" destination="zK6-No-yaf" id="vsj-Ee-aWa"/>
<outlet property="signOutButton" destination="ftK-wu-fHt" id="ia4-38-0BB"/>
<outlet property="subtitleLabel" destination="8n1-U7-jzB" id="3NJ-4x-Yid"/>
<outlet property="updateProfileButton" destination="ZZe-YT-b6s" id="3Su-Pp-xtp"/>
<outlet property="welcomeLabel" destination="Or4-z4-FOf" id="UVH-gN-DtK"/>
</connections>
</tableViewController>
Expand Down
24 changes: 22 additions & 2 deletions Example/RxFireAuth/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class ViewController: UITableViewController {

@IBOutlet weak var dataMigrationControl: UISegmentedControl!

@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var updateProfileButton: UIButton!

private var userManager: UserManagerType = UserManager()
private var disposeBag = DisposeBag()

Expand All @@ -40,10 +43,15 @@ class ViewController: UITableViewController {
self.welcomeLabel.text = "Welcome, Anonymous!"
self.subtitleLabel.text = "You are logged-in with an anonymous account."
} else {
self.welcomeLabel.text = "Welcome!"
if let displayName = user.displayName, displayName.count > 0 {
self.welcomeLabel.text = "Welcome, \(displayName)!"
} else {
self.welcomeLabel.text = "Welcome!"
}
self.subtitleLabel.text = "You are logged-in with \(user.email ?? "unknown")."
}
self.signOutButton.isEnabled = true
self.nameField.text = user.displayName
} else {
self.welcomeLabel.text = "Welcome!"
self.subtitleLabel.text = "You are not logged-in."
Expand All @@ -59,7 +67,7 @@ class ViewController: UITableViewController {
} else if isLoggedIn && hasEmail {
return "Link"
} else if isLoggedIn && !hasEmail {
return "Insert an email address!"
return "Insert an email address to link it!"
}
return "Sign in"
}
Expand Down Expand Up @@ -122,6 +130,18 @@ class ViewController: UITableViewController {
.disposed(by: self.disposeBag)
}

@IBAction func updateProfile(sender: AnyObject) {
self.toggleProgress(true)
self.userManager.update { (userData) -> UserData in
var user = userData
user.displayName = self.nameField.text
return user
}.subscribe(onCompleted: {
self.toggleProgress(false)
}, onError: self.show(error:))
.disposed(by: self.disposeBag)
}

override func viewDidAppear(_ animated: Bool) {
self.loginField.becomeFirstResponder()
}
Expand Down
2 changes: 1 addition & 1 deletion RxFireAuth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'RxFireAuth'
s.version = '1.0.0'
s.version = '1.1.0'
s.summary = 'A smart Rx wrapper around Firebase Authentication SDK'

# This description is used to generate tags and improve search results.
Expand Down
4 changes: 3 additions & 1 deletion RxFireAuth/Classes/UserData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import UIKit
/// A User.
///
/// This class usually inherits data from a Firebase User.
/// You cannot instantiate this class directly. Use `UserManagerType`
/// implementations to get a user.
public struct UserData {

/// Get the ID.
Expand All @@ -26,7 +28,7 @@ public struct UserData {
/// Get the user display name.
///
/// Corresponds to `displayName` on the Firebase User object..
public let displayName: String?
public var displayName: String?

/// Get if this is an anonymous user.
///
Expand Down
12 changes: 12 additions & 0 deletions RxFireAuth/Classes/UserManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public class UserManager: UserManagerType {
if let error = error {
observer(.error(error))
} else {
self.forceRefreshAutoUpdatingUser.onNext(())
observer(.completed)
}
}
Expand All @@ -303,6 +304,17 @@ public class UserManager: UserManagerType {
}
}

public func update(userConfigurationHandler: @escaping (UserData) -> UserData) -> Completable {
guard Auth.auth().currentUser != nil else { return Completable.error(UserError.noUser) }

return self.autoupdatingUser
.take(1)
.filter { $0 != nil }.map { $0! }
.map(userConfigurationHandler)
.flatMap { self.update(user: $0) }
.asCompletable()
}

public func updateEmail(newEmail: String) -> Completable {
guard let user = Auth.auth().currentUser else { return Completable.error(UserError.noUser) }

Expand Down
18 changes: 18 additions & 0 deletions RxFireAuth/Classes/UserManagerType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,31 @@ public protocol UserManagerType {
/// Update the currently logged-in user taking new values from the
/// passed object.
///
/// You cannot instantiate a `UserData` instance directly. To pass the parameter to this function,
/// use a value retrieved from `self.user` or `self.autoupdatingUser`. To simplify this even
/// further, use `self.update(userConfigurationHandler:)`.
///
/// - note: This function will not update the user email address, even if it has changed.
///
/// - seealso: self.update(userConfigurationHandler:)
/// - parameters:
/// - user: A user to gather new values from.
/// - returns: A Completable action to observe.
func update(user: UserData) -> Completable

/// Retrieve the currently logged-in user and use the specified
/// configuration handler to update its properties.
///
/// - note: This function is only a wrapper that takes the first value of `self.autoupdatingUser`,
/// maps it by calling the `userConfigurationHandler` and passes it to `self.update(user:)`.
///
/// - since: version 1.1.0
///
/// - parameters:
/// - userConfigurationHandler: A function that takes a `UserData` instance and returns it with the required changes.
/// - returns: A Completable action to observe.
func update(userConfigurationHandler: @escaping (UserData) -> UserData) -> Completable

/// Update the email of the currently logged-in user.
///
/// - parameters:
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a title="Classes Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">RxFireAuth Docs</a> (94% documented)</p>
<p><a href="index.html">RxFireAuth Docs</a> (95% documented)</p>
</div>
</header>
<div class="content-wrapper">
Expand Down Expand Up @@ -165,7 +165,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2020 <a class="link" href="https://github.com/mrasterisco/RxFireAuth" target="_blank" rel="external">Alessio Moiso</a>. All rights reserved. (Last updated: 2020-04-18)</p>
<p>&copy; 2020 <a class="link" href="https://github.com/mrasterisco/RxFireAuth" target="_blank" rel="external">Alessio Moiso</a>. All rights reserved. (Last updated: 2020-04-19)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/SignInWithAppleHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a title="SignInWithAppleHandler Class Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">RxFireAuth Docs</a> (94% documented)</p>
<p><a href="../index.html">RxFireAuth Docs</a> (95% documented)</p>
</div>
</header>
<div class="content-wrapper">
Expand Down Expand Up @@ -236,7 +236,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2020 <a class="link" href="https://github.com/mrasterisco/RxFireAuth" target="_blank" rel="external">Alessio Moiso</a>. All rights reserved. (Last updated: 2020-04-18)</p>
<p>&copy; 2020 <a class="link" href="https://github.com/mrasterisco/RxFireAuth" target="_blank" rel="external">Alessio Moiso</a>. All rights reserved. (Last updated: 2020-04-19)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading

0 comments on commit 74d19f9

Please sign in to comment.