-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathLBUser.h
139 lines (122 loc) · 4.41 KB
/
LBUser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* @file LBUser.h
*
* @author Stephen Hess
* @copyright (c) 2014 StrongLoop. All rights reserved.
*/
#import "LBPersistedModel.h"
@class LBAccessToken;
/**
* A local representative of a user instance on the server.
*/
@interface LBUser : LBPersistedModel
@property (nonatomic, copy) NSString *email;
@property (nonatomic, copy) NSString *password;
@property (nonatomic, copy) NSString *realm;
@property (nonatomic, strong) NSNumber *emailVerified;
@property (nonatomic, copy) NSString *status;
@end
/**
* A local representative of the User type on the server, encapsulating
* all User properties.
*/
@interface LBUserRepository : LBPersistedModelRepository
@property (nonatomic, readonly) NSString *currentUserId;
@property (nonatomic, readonly) LBUser *cachedCurrentUser;
+ (instancetype)repository;
/**
* Creates a user with the given credentials and additional data.
*
* @param email The user email.
* @param password The user password.
* @param dictionary Any additional data to encapsulate.
*/
- (LBUser *)createUserWithEmail:(NSString*)email
password:(NSString*)password
dictionary:(NSDictionary *)dictionary;
/**
* Creates a user with the given credentials.
*
* @param email The user email.
* @param password The user password.
*/
- (LBUser *)createUserWithEmail:(NSString*)email
password:(NSString*)password;
/**
* Blocks of this type are executed when
* LBUserRepository::loginWithEmail:password:success:failure: is successful.
*/
typedef void (^LBUserLoginSuccessBlock)(LBAccessToken* token);
/**
* Attempts to log in with the given credentials. The returned access
* token will be passed for all subsequent server interaction.
*
* @param email The user email.
* @param password The user password.
* @param success The block to be executed when the login is successful.
* @param failure The block to be executed when the login fails.
*/
- (void)loginWithEmail:(NSString*)email
password:(NSString*)password
success:(LBUserLoginSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBUserRepository::userByLoginWithEmail:password:success:failure: is successful.
*/
typedef void (^LBUserLoginFindUserSuccessBlock)(LBUser *user);
/**
* Attempts to log in with the given credentials and return the LBUser.
*
* @param email The user email.
* @param password The user password.
* @param success The block to be executed when the login is successful.
* @param failure The block to be executed when the login fails.
*/
- (void)userByLoginWithEmail:(NSString*)email
password:(NSString*)password
success:(LBUserLoginFindUserSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBUserRepository::findCurrentUserWithSuccess:failure: is successful.
*/
typedef void (^LBUserFindUserSuccessBlock)(LBUser *user);
/**
* Fetch the user model of the currently logged in user.
* Invokes {@code success(nil)} when no user is logged in.
*
* @param success The block to be executed when the fetch is successful.
* @param failure The block to be executed when the fetch fails.
*/
- (void)findCurrentUserWithSuccess:(LBUserFindUserSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when LBUserRepository::logoutWithSuccess:success:failure: is
* successful.
*/
typedef void (^LBUserLogoutSuccessBlock)();
/**
* Clears the current access token for this session.
*
* @param success The block to be executed when the logout is successful.
* @param failure The block to be executed when the logout fails.
*/
- (void)logoutWithSuccess:(LBUserLogoutSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBUserRepository::resetPasswordWithEmail:success:failure: is successful.
*/
typedef void (^LBUserResetSuccessBlock)();
/**
* Triggers reset password for a user with email.
*
* @param email The user email.
* @param success The block to be executed when the reset is successful.
* @param failure The block to be executed when the reset fails.
*/
- (void)resetPasswordWithEmail:(NSString*)email
success:(LBUserResetSuccessBlock)success
failure:(SLFailureBlock)failure;
@end