Artsy-Authentication
Artsy-Authentication copied to clipboard
Create a UserManager of sorts
Ideally something that can store / retrieve an existing user, and support all the different types of sign up / sign in flows we have.
This is the old one. Open to removing / editing / composing etc etc
@interface ARUserManager : NSObject
+ (ARUserManager *)sharedManager;
+ (void)identifyAnalyticsUser;
- (User *)currentUser;
- (void)storeUserData;
@property (nonatomic, strong) NSString *trialUserName;
@property (nonatomic, strong) NSString *trialUserEmail;
@property (nonatomic, strong, readonly) NSString *trialUserUUID;
- (void)resetTrialUserUUID;
- (BOOL)hasExistingAccount;
- (BOOL)hasValidAuthenticationToken;
- (BOOL)hasValidXAppToken;
- (void)logout;
- (void)startTrial:(void(^)())callback failure:(void (^)(NSError *error))failure;
- (void)loginWithUsername:(NSString *)username
password:(NSString *)password
successWithCredentials:(void(^)(NSString *accessToken, NSDate *expirationDate))credentials
gotUser:(void(^)(User *currentUser))gotUser
authenticationFailure:(void (^)(NSError *error))authenticationFailure
networkFailure:(void (^)(NSError *error))networkFailure;
- (void)loginWithFacebookToken:(NSString *)token
successWithCredentials:(void(^)(NSString *accessToken, NSDate *expirationDate))credentials
gotUser:(void(^)(User *currentUser))gotUser
authenticationFailure:(void (^)(NSError *error))authenticationFailure
networkFailure:(void (^)(NSError *error))networkFailure;
- (void)loginWithTwitterToken:(NSString *)token
secret:(NSString *)secret
successWithCredentials:(void(^)(NSString *accessToken, NSDate *expirationDate))credentials
gotUser:(void(^)(User *currentUser))gotUser
authenticationFailure:(void (^)(NSError *error))authenticationFailure
networkFailure:(void (^)(NSError *error))networkFailure;
- (void)createUserWithName:(NSString *)name email:(NSString *)email password:(NSString *)password success:(void(^)(User *user))success failure:(void (^)(NSError *error, id JSON))failure;
- (void)createUserViaFacebookWithToken:(NSString *)token email:(NSString *)email name:(NSString *)name success:(void(^)(User *user))success failure:(void (^)(NSError *error, id JSON))failure;
- (void)createUserViaTwitterWithToken:(NSString *)token secret:(NSString *)secret email:(NSString *)email name:(NSString *)name success:(void(^)(User *user))success failure:(void (^)(NSError *error, id JSON))failure;
- (void)sendPasswordResetForEmail:(NSString *)email success:(void(^)(void))success failure:(void (^)(NSError *error))failure;
@end
We shouldn't be creating a User model here, which kinda makes it a bit tricky.
The model is really the responsibility of the app, so it should deal entirely with dictionaries, e.g. gotUserDictionary:(NSDictionary *)userDict.
Might be interesting to allow for simple method chaining because for all of the methods you're really saying "do something" then you care about got token, got user dict, auth fail and network fail but maybe you don't care about got token?
Could login return a AuthenticationProcess (really a promise, I guess) object that you could then hook up to any those methods
AuthenticationProcess *process = [auth loginWithArtsyEmail:@"sfsdf" password:@"sdaddsa"];
process.gotCredentials = ^(NSString *accessToken, NSDate *expirationDate) {
};
process.gotUserDictionary = ^(NSDictionary *userDict) {
};
... etc
?