OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if !defined(__has_feature) || !__has_feature(objc_arc) | 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
6 #error "This file requires ARC support." | 6 #error "This file requires ARC support." |
7 #endif | 7 #endif |
8 | 8 |
9 #import "remoting/client/ios/domain/user_info.h" | 9 #import "remoting/client/ios/domain/user_info.h" |
10 | 10 |
11 @implementation UserInfo | 11 @implementation UserInfo |
12 | 12 |
13 @synthesize userId = _userId; | 13 @synthesize userId = _userId; |
14 @synthesize userFullName = _userFullName; | 14 @synthesize userFullName = _userFullName; |
15 @synthesize userEmail = _userEmail; | 15 @synthesize userEmail = _userEmail; |
| 16 @synthesize refreshToken = _refreshToken; |
16 | 17 |
17 // Parse jsonData into Host list. | 18 // Parse jsonData into Host list. |
18 + (UserInfo*)parseListFromJSON:(NSMutableData*)data { | 19 + (UserInfo*)parseListFromJSON:(NSMutableData*)data { |
19 NSError* error; | 20 NSError* error; |
20 | 21 |
21 NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data | 22 NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data |
22 options:kNilOptions | 23 options:kNilOptions |
23 error:&error]; | 24 error:&error]; |
24 | 25 |
25 UserInfo* user = [[UserInfo alloc] init]; | 26 UserInfo* user = [[UserInfo alloc] init]; |
26 user.userId = [json objectForKey:@"userId"]; | 27 user.userId = [json objectForKey:@"userId"]; |
27 user.userFullName = [json objectForKey:@"userFullName"]; | 28 user.userFullName = [json objectForKey:@"userFullName"]; |
28 user.userEmail = [json objectForKey:@"userEmail"]; | 29 user.userEmail = [json objectForKey:@"userEmail"]; |
| 30 user.refreshToken = [json objectForKey:@"refreshToken"]; |
29 | 31 |
30 return user; | 32 return user; |
31 } | 33 } |
32 | 34 |
| 35 - (BOOL)isAuthenticated { |
| 36 if (_userEmail && _userEmail.length > 0 && _refreshToken && |
| 37 _refreshToken.length > 0) { |
| 38 return YES; |
| 39 } |
| 40 return NO; |
| 41 } |
| 42 |
33 - (NSComparisonResult)compare:(UserInfo*)user { | 43 - (NSComparisonResult)compare:(UserInfo*)user { |
34 return [self.userId compare:user.userId]; | 44 return [self.userId compare:user.userId]; |
35 } | 45 } |
36 | 46 |
| 47 - (NSString*)description { |
| 48 return [NSString stringWithFormat:@"UserInfo: userEmail=%@ refreshToken=%@", |
| 49 _userEmail, _refreshToken]; |
| 50 } |
| 51 |
37 @end | 52 @end |
OLD | NEW |