Sfoglia il codice sorgente

- 로그인결과값 이용해서 Authorization 정보를 생성하도록 수정
- Authorization 정보가 있을경우 WebSocekt의 ConnectionOpen시 Header에 Authorization정보를 항상 포함하도록 수정
- Authorization 정보가 있을경우 Rest Api의 Request시 Header에 Authorization정보를 항상 포함하도록 수정

KaRam Kim 8 anni fa
parent
commit
99f5c9294c

+ 1 - 0
OneCable/Classes/Categories/NSString-Addtions.h

@@ -26,5 +26,6 @@
 - (NSString *)stringByEncodingHTMLEntities;
 
 
+- (NSString *)base64Enc;
 
 @end

+ 9 - 0
OneCable/Classes/Categories/NSString-Addtions.m

@@ -215,4 +215,13 @@
 
 }
 
+
+- (NSString *)base64Enc
+{
+    NSData *plainData = [self dataUsingEncoding:NSUTF8StringEncoding];
+    NSString *base64enc = [plainData base64EncodedStringWithOptions:0];
+    
+    return base64enc;
+}
+
 @end

+ 6 - 4
OneCable/Classes/Definitions.h

@@ -34,11 +34,13 @@
 
 //static NSString *kAPIServer = @"http://61.40.220.132:5007";     //개발
 static NSString *kAPIServer = @"http://61.40.220.23:7791";      //운영
+//static NSString *kSocketServer = @"ws://%@61.40.220.23:7792";      //운영
 static NSString *kSocketServer = @"ws://61.40.220.23:7792";      //운영
 
 #else //운영모드
 
 static NSString *kAPIServer = @"http://61.40.220.23:7791";      //운영
+//static NSString *kSocketServer = @"ws://%@61.40.220.23:7792";      //운영
 static NSString *kSocketServer = @"ws://61.40.220.23:7792";      //운영
 
 #endif
@@ -63,7 +65,7 @@ static NSString *kSocketServer = @"ws://61.40.220.23:7792";      //운영
 #define API_POST_SIGN_UP                @"/customer/%@/group/%@/member"              //회원가입
 
 #define API_TEMP_CUST_ID                @"1001"
-#define API_TEMP_CUST_GROP_ID                @"1001"
+#define API_TEMP_CUST_GROP_ID           @"1001"
 
 //#define API_POST_MEMBER_UPDATE          @"/member/%@/%@"        //회원정보 수정
 #define API_POST_MEMBER_UPDATE          @"/member/%@"        //회원정보 수정
@@ -92,7 +94,7 @@ static NSString *kSocketServer = @"ws://61.40.220.23:7792";      //운영
 
 //12 - 초대
 #define API_GET_HOMEGROUP_MEMBERS           @"/homegrp_members"         //홈그룹 멤버 목록
-#define API_POST_HOMEGROUP_MEMBER_INVITE    @"/homegrp_members"         //홈멤버 초대
+#define API_POST_HOMEGROUP_MEMBER_INVITE    @"/customer/%@/group/%@/invite"         //홈멤버 초대
 //#define API_POST_HOMEGROUP_MEMBER_UPDATE    @"/homegrp_members/%@"      //홈멤버 업데이트 - 폐기
 //#define API_POST_HOMEGROUP_MEMBER_VALIDATE  @"/homegrp_members/email_validation"    //홈그룹 멤버 유효성체크 - 폐기
 #define API_DELETE_HOMEGROUP_MEMBERS        @"/homegrp_members"         //홈멤버 삭제 - 추가
@@ -235,8 +237,8 @@ typedef enum MorePopupBtnType {
 #define KNEET_DEVICE_WAITING    @"WAT"
 
 
-#define KNEET_MEMBER_MASTER     @"MAS"
-#define KNEET_MEMBER_SIMPLE     @"SIM"
+#define KNEET_MEMBER_MASTER     @"MAS"//@"MAS"
+#define KNEET_MEMBER_SIMPLE     @"SIM"//@"SIM"
 
 #define KNEET_MEMBER_TYPE_HOME  @"01"   //멤버
 #define KNEET_MEMBER_TYPE_INV   @"02"   //초대중

+ 7 - 0
OneCable/Classes/Handler/RequestHandler.m

@@ -108,6 +108,13 @@
 
         } error:&error];
     }
+    
+    // !!!: Authorization정보가 있을 경우 모든 Request Header정보에 Authorization정보를 포함해서 요청하도록 수정
+    if([[JDFacade facade].loginUser authorization]!=nil)
+    {
+        [request setValue:[[JDFacade facade].loginUser authorization] forHTTPHeaderField:@"Authorization"];
+    }
+    NSLog(@"Request All Header Info : %@", request.allHTTPHeaderFields);
 
     AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
     op.responseSerializer = [AFJSONResponseSerializer serializer];

+ 1 - 1
OneCable/Classes/Handler/SocketServiceHandler.h

@@ -13,7 +13,7 @@
 
 @optional
 - (void) socketConnectComplete;
-- (void) socketDidReceiveMessage:(id)message;
+- (void) socketDidReceiveMessage:(id)message info:(NSDictionary *)info;
 - (void) didFailWithError:(NSError *)error;
 - (void) socketDidReceivePong:(NSData *)pongPayload;
 - (void) socketDidCloseWithCode:(NSInteger)code;

+ 24 - 44
OneCable/Classes/Handler/SocketServiceHandler.m

@@ -7,10 +7,10 @@
 //
 
 #import "SocketServiceHandler.h"
-
 #import "Definitions.h"
-
 #import "JDJSONModel.h"
+#import "JDObject.h"
+
 
 #define MAX_RETRY_CONNECT_COUNT 1
 
@@ -43,9 +43,6 @@
         
         _isConnected = NO;
 
-//        
-//        _socket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:_strSocketURL]];
-//        _socket.delegate = self;
         
         _messages = [[NSMutableArray alloc] init];
         
@@ -69,16 +66,25 @@
 - (void) socketOpen
 {
     NSLog(@"socketOpen");
+    
     _strSocketURL = [NSString stringWithFormat:@"%@%@", kSocketServer, API_ROOT_PATH];
     NSLog(@"socketURL : %@", _strSocketURL);
     
     if( _socket != nil )
+    {
         [_socket open];
+    }
     else
     {
-        _socket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:_strSocketURL]];
-        _socket.delegate = self;
+        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:_strSocketURL]];
+        if([[JDFacade facade].loginUser authorization]!=nil)
+        {
+            [request setValue:[[JDFacade facade].loginUser authorization] forHTTPHeaderField:@"Authorization"];
+        }
+        NSLog(@"All Header Info : %@", request.allHTTPHeaderFields);
+        _socket = [[SRWebSocket alloc] initWithURLRequest:request];
         
+        _socket.delegate = self;
         [_socket open];
     }
 }
@@ -196,53 +202,27 @@
     else
     {
         NSError* error = nil;
-//        NSString *JSONString = [[NSString alloc] initWithData:[message dataUsingEncoding:NSUTF8StringEncoding] encoding:NSUTF8StringEncoding];
         NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding]
                                                      options:NSJSONReadingAllowFragments
                                                        error:&error];
         
-        id JSONModel = nil;
+        
+        
+        if (error != nil) {
+            NSLog(@"NSJSONSerialization JSONObject error: %@", [error localizedDescription]);
+            return;
+        }
+
 
-//        if ([jsonObj isKindOfClass:[NSArray class]])
-//        {
-//            NSDictionary *JSONDic = @{@"list": jsonObj};
-//            
-//        }
-//        else
-//        {
-//            JSONModel = [[SocketModel alloc] initWithString:JSONString error:&error];
-//        }
+        id JSONModel = nil;
         JSONModel = [[SocketModel alloc] initWithDictionary:jsonObj error:&error];
         
-        if (self.delegate && [self.delegate respondsToSelector:@selector(socketDidReceiveMessage:)]) {
+        if (self.delegate && [self.delegate respondsToSelector:@selector(socketDidReceiveMessage:info:)]) {
             
-            [self.delegate socketDidReceiveMessage:JSONModel];
+            [self.delegate socketDidReceiveMessage:JSONModel info:jsonObj];
         }
         
-//        if( [message isKindOfClass:[NSString class]] )
-//        {
-//            NSError* error = nil;
-//            NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding]
-//                                                                    options:NSJSONReadingMutableContainers
-//                                                                      error:&error];
-//            
-//            if (error != nil) {
-//                NSLog(@"NSJSONSerialization JSONObject error: %@", [error localizedDescription]);
-//                return;
-//            }
-//            
-//            NSInteger msgType = [jsonObj[@"type"] integerValue];
-//            
-//            if ( msgType == 0 ) {
-//                
-//            }
-//
-//            else
-//            {
-//                NSLog(@"msgType : %i",(int)msgType);
-//                
-//            }
-//        }
+        // TODO : 전달받은 데이터로 자동으로 처리할 내용이 있으면 이곳에서 처리할것
     }
 }
 

+ 4 - 0
OneCable/Classes/Model/DeviceModel.h

@@ -34,6 +34,9 @@
 @property (copy, nonatomic) NSString *deviceType;
 @property (copy, nonatomic) NSString *collectTime;
 
+@property (copy, nonatomic) NSString *deviceOnline;
+@property (copy, nonatomic) NSString *deviceOnlineLastDatetime;
+@property (copy, nonatomic) NSString *deviceConn;
 
 //detail
 @property (copy, nonatomic) NSString *prdName;
@@ -81,6 +84,7 @@
 @property (weak, nonatomic) DeviceModel *refDevice;
 @property (assign, nonatomic, readonly) BOOL isDeviceOnline;
 
+
 //@property (copy, nonatomic) NSString *deviceId;
 //@property (copy, nonatomic) NSString *nodeId;
 //@property (copy, nonatomic) NSString *nodeName;

+ 21 - 11
OneCable/Classes/Model/LoginModel.h

@@ -10,6 +10,7 @@
 #import <CoreLocation/CoreLocation.h>
 
 #import "JDJSONModel.h"
+#import "DeviceModel.h"
 
 @protocol InvitationModel;
 @interface InvitationModel : JDJSONModel
@@ -90,19 +91,23 @@
 @property (copy, nonatomic) NSString *memberId;
 @property (copy, nonatomic) NSString *emailId;
 @property (copy, nonatomic) NSString *serviceId;
-@property (copy, nonatomic) NSString *countryCode;
-@property (copy, nonatomic) NSString *timezoneId;
-@property (copy, nonatomic) NSString *timezone;
-@property (copy, nonatomic) NSString *lang;
-@property (copy, nonatomic) NSString *authToken;
+@property (copy, nonatomic) NSString *countryCode; //국가 코드 (ex : KR)
+@property (copy, nonatomic) NSString *timezoneId; //타임존 ID
+@property (copy, nonatomic) NSString *timezone; //타임존 시간 (ex : +09:00)
+@property (copy, nonatomic) NSString *lang; //언어 코드 (ex : en)
+@property (copy, nonatomic) NSString *authToken; //인증 토큰
+@property (copy, nonatomic) NSString *profileImage; //(회원) 이미지 파일 명
 @property (copy, nonatomic) NSString *member;
 @property (copy, nonatomic) NSString *imageFileName;
-@property (copy, nonatomic) NSString *nickname;
+@property (copy, nonatomic) NSString *nickname; //(회원) 닉네임
 @property (copy, nonatomic) NSString *key;
-@property (copy, nonatomic) NSString *tempPasswordYn;
-@property (copy, nonatomic) NSString *pushTypeModeChgYn;
+@property (copy, nonatomic) NSString *tempPasswordYn; //임시 비밀번호 여부 (Y : 임시 비밀번호, N : 기존 비밀번호)
+@property (copy, nonatomic) NSString *pushTypeModeChgYn; //모드가 바뀔 때 알림 설정 여부 (Y : 사용, N : 미사용)
 @property (copy, nonatomic) NSString *pushTypePrsncChgYn;
 
+@property (copy, nonatomic) NSString *custId; //고객 ID
+@property (copy, nonatomic) NSString *ctrtGrpId; //계약그룹ID(고객 ID와 동일)
+@property (copy, nonatomic) NSString *ctrt_grp_name; //(소속된) 계약그룹 명
 
 @property (copy, nonatomic) NSString *homegrpId;
 @property (copy, nonatomic) NSString *homegrpName;
@@ -118,9 +123,11 @@
 
 @property (copy, nonatomic) NSString *servicehubApplicationId;
 
-@property (copy, nonatomic) NSString *deviceOnline;
-@property (copy, nonatomic) NSString *deviceOnlineLastDatetime;
-@property (copy, nonatomic) NSString *deviceConn;
+@property (strong, nonatomic) NSMutableArray<DeviceModel> *deviceList; //디바이스 목록
+
+//@property (copy, nonatomic) NSString *deviceOnline;
+//@property (copy, nonatomic) NSString *deviceOnlineLastDatetime;
+//@property (copy, nonatomic) NSString *deviceConn;
 
 //local store
 @property (strong, nonatomic) NSMutableDictionary *localStorage;
@@ -137,5 +144,8 @@
 @property (assign, nonatomic, readonly) BOOL isHomehubOnline;
 @property (assign, nonatomic, readonly) BOOL hasHomeHub;
 
+@property (assign, nonatomic, readonly) NSString *authorization;
+
+
 @end
 

+ 15 - 0
OneCable/Classes/Model/LoginModel.m

@@ -8,6 +8,8 @@
 #import "JDObject.h"
 #import "LoginModel.h"
 #import "CypherUtil.h"
+#import "NSData+AESCrypt.h"
+#import "NSString-Addtions.h"
 
 @implementation InvitationModel
 
@@ -178,6 +180,7 @@
     return _level;
 }
 
+// TODO: 홈그룹 온라인 / 보유 여부 로직 변경하기
 - (BOOL)isHomehubOnline {
     return _homehubOnlineState && ![_homehubOnlineState isEmptyString] && [_homehubOnlineState isEqualToString:@"ON"];
 }
@@ -187,6 +190,18 @@
     return _homehubDeviceId && ![_homehubDeviceId isEmptyString];
 }
 
+-(NSString *)authorization
+{
+//    NSString *result = @"asura77:1f6bafe0801d52b557fc7b5277cb878bc36e54987b6eec036e713b1229096117";
+    NSString *result = nil;
+    if(_memberId !=nil && _authToken != nil)
+    {
+        result= [NSString stringWithFormat:@"%@:%@", _memberId, _authToken];
+    }
+
+    return [result base64Enc];
+}
+
 
 #pragma mark - about Location Settings
 //로컬 저장소

+ 22 - 25
OneCable/Classes/ViewControllers/MainScreens/LoginViewController.m

@@ -118,10 +118,7 @@
 - (void)requestLogin {
     NSDictionary *param = @{@"member_id": _txtEmail.text,
                             @"password": _txtPasswd.text,
-//                            @"service_id": MOBILE_SERVICE_ID,
                             @"os_type": MOBILE_DEVICE_TYPE,
-//                            @"device_sn": [JDFacade facade].deviceUUID,
-//                            @"device_name": [CommonUtil deviceName],
                             @"device_token": [JDFacade facade].APNSToken ? [JDFacade facade].APNSToken : ksEmptyString,
                             @"message_type": @"auth"};
     
@@ -221,8 +218,8 @@
     if (loginInfo) {//API 성공함
         [JDFacade facade].loginUser = loginInfo;
         
-        [JDFacade facade].loginUser.gradeCode = KNEET_MEMBER_MASTER;
-        [JDFacade facade].loginUser.level = 90;
+//        [JDFacade facade].loginUser.gradeCode = KNEET_MEMBER_MASTER;
+//        [JDFacade facade].loginUser.level = 90;
         
         NSLog(@"%@", [JDFacade facade].loginUser);
         
@@ -401,28 +398,28 @@
 }
 
 #pragma mark - SocketService
-- (void) socketDidReceiveMessage:(id)message
+- (void) socketDidReceiveMessage:(id)message info:(NSDictionary *)info
 {
 //    NSLog(@"이쪽으로 들어옴?!!!");
-    LoginModel *loginInfo = (LoginModel *)message;
-    NSLog(@"Socket Info :%@", loginInfo);
-//    SWITCH(info.messageType)
-//    {
-//        CASE (@"auth")
-//        {
-//            // TODO : 로그인 처리
-//            LoginModel *loginInfo = (LoginModel *)message;
-//            if (loginInfo) {//API 성공 ,함
-//                [self actionForLoginSucceed:loginInfo];
-//                
-//            }
-//            break;
-//        }
-//        DEFAULT
-//        {
-//            break;
-//        }
-//    }
+    SocketModel *result = (SocketModel *)message;
+    NSLog(@"Socket Info :%@", result);
+    SWITCH(result.messageType)
+    {
+        CASE (@"auth")
+        {
+            // TODO : 로그인 처리
+            LoginModel *loginInfo = [[LoginModel alloc] initWithDictionary:info error:nil];;
+            if (loginInfo) {//API 성공 ,함
+                [self actionForLoginSucceed:loginInfo];
+                
+            }
+            break;
+        }
+        DEFAULT
+        {
+            break;
+        }
+    }
 }
 
 #pragma mark - MemoryWarning