ICRLoginViewController.m 8.95 KB
Newer Older
mei's avatar
mei committed
1 2
//
//  ICRLoginViewController.m
mei's avatar
mei committed
3
//  XFFruit
mei's avatar
mei committed
4 5 6 7 8 9 10 11
//
//  Created by Xummer on 3/22/15.
//  Copyright (c) 2015 Xummer. All rights reserved.
//

#import "ICRLoginViewController.h"
#import "ICRLoginContentView.h"

12 13
#import "GXFFunctionDB.h"
#import "GXFFunctionDBHelper.h"
freecui's avatar
freecui committed
14
#import "APService.h"
zhu's avatar
zhu committed
15
#import "ICRAppDelegate.h"
16

mei's avatar
mei committed
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
#define LOGIN_CONTAINER_LEFT_MARGIN         (20)
#define LOGIN_CONTAINER_HEIGHT              (450)

@interface ICRLoginViewController ()
{
    CGFloat m_fDefaultContainerY;
}
@property (strong, nonatomic) ICRLoginContentView *m_containerView;
@end

@implementation ICRLoginViewController

#pragma mark - Life Cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupSubviews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    
    if (m_fDefaultContainerY == 0) {
        m_fDefaultContainerY = _m_containerView.y;
    }
}

mei's avatar
mei committed
49 50
- (void)viewWillAppear:(BOOL)animated {}

mei's avatar
mei committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
    [notiCenter addObserver:self
                   selector:@selector(inputTextEditChanged:)
                       name:UITextFieldTextDidChangeNotification
                     object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
    [notiCenter removeObserver:self];
}

#pragma mark - Private Method
- (void)setupSubviews {
    UIImageView *bg = [[UIImageView alloc] initWithFrame:self.view.bounds];
freecui's avatar
freecui committed
71
    bg.image = [UIImage imageWithColor:GXF_SAVE_COLOR];//
mei's avatar
mei committed
72
    [bg autoresizingWithStrechFullSize];
freecui's avatar
freecui committed
73
   
mei's avatar
mei committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    UITapGestureRecognizer *tapGesture =
    [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(onBGTapped:)];
    bg.userInteractionEnabled = YES;
    [bg addGestureRecognizer:tapGesture];
    
    [self.view addSubview:bg];
    
    self.m_containerView =
    [[ICRLoginContentView alloc] initWithFrame:(CGRect){
        .origin.x = LOGIN_CONTAINER_LEFT_MARGIN,
        .origin.y = (self.view.height - LOGIN_CONTAINER_HEIGHT) * .5f,
        .size.width = self.view.width - 2 * LOGIN_CONTAINER_LEFT_MARGIN,
        .size.height = LOGIN_CONTAINER_HEIGHT
    }
                                     showCCode:YES];
    [_m_containerView autoresizingWithVerticalCenter];
mei's avatar
mei committed
91
    
mei's avatar
mei committed
92 93 94 95 96 97
    [_m_containerView.m_loginBtn addTarget:self
                                    action:@selector(onLoginTapped:)
                          forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_m_containerView];
    
管鹏飞's avatar
管鹏飞 committed
98
//#if DEBUG
mei's avatar
mei committed
99 100 101
//    self.m_containerView.m_cCodeTextF.text = @"A93jie957lK";
//    self.m_containerView.m_userNameTextF.text = @"kevin";
//    self.m_containerView.m_passwordTextF.text = @"aaa";
freecui's avatar
freecui committed
102 103

    //@"http://218.244.151.129:7580/cruiser-server/rest"
104 105 106
    self.m_containerView.m_cCodeTextF.text = @"211534962";
    self.m_containerView.m_userNameTextF.text = @"admin";
    self.m_containerView.m_passwordTextF.text = @"thoradmin";
freecui's avatar
freecui committed
107 108
    
    
陈俊俊's avatar
陈俊俊 committed
109
//@"http://122.224.171.126:7280/cruiser-server/rest"
110 111 112
//        self.m_containerView.m_cCodeTextF.text = @"923";
//        self.m_containerView.m_userNameTextF.text = @"admin";
//        self.m_containerView.m_passwordTextF.text = @"thoradmin";
陈俊俊's avatar
陈俊俊 committed
113 114

    
陈俊俊's avatar
陈俊俊 committed
115 116 117 118
//现场正式环境登陆
//    self.m_containerView.m_cCodeTextF.text = @"211534968";
//    self.m_containerView.m_userNameTextF.text = @"admin";
//    self.m_containerView.m_passwordTextF.text = @"thoradmin";
陈俊俊's avatar
陈俊俊 committed
119
    
管鹏飞's avatar
管鹏飞 committed
120
    ICRUserUtil *userU = [ICRUserUtil sharedInstance];
mei's avatar
mei committed
121
    
管鹏飞's avatar
管鹏飞 committed
122 123
    self.m_containerView.m_cCodeTextF.text = userU.registerCode; //*registerCode;  //企业认证码
    self.m_containerView.m_userNameTextF.text =userU.userName;
管鹏飞's avatar
管鹏飞 committed
124 125 126 127 128 129
    if (userU.isLogout) {
        //self.m_containerView.m_passwordTextF.text = userU.password;
    } else {
       self.m_containerView.m_passwordTextF.text = userU.password;
    }

管鹏飞's avatar
管鹏飞 committed
130 131 132 133
    [self.m_containerView checkLoginEnable];
//#else
//    
//#endif
134
    
mei's avatar
mei committed
135 136 137 138 139 140 141 142 143 144 145
}

#pragma mark - Logic


#pragma mark - Actions
- (void)onBGTapped:(__unused id)sender {
    [self.view endEditing:YES];
}

- (void)onLoginTapped:(__unused id)sender {
146 147 148 149 150 151 152 153
    
#if 0
    ICRAppViewControllerManager *mgr =
    [ICRAppViewControllerManager getAppViewControllerManager];
    [mgr openMainFrame];
#else
    
    
陈俊俊's avatar
陈俊俊 committed
154 155
    NSString *nsRegisterCode = self.m_containerView.m_cCodeTextF.text;
    NSString *nsUserName = self.m_containerView.m_userNameTextF.text;
管鹏飞's avatar
管鹏飞 committed
156
    NSString *nsPassword = self.m_containerView.m_passwordTextF.text;
157

陈俊俊's avatar
陈俊俊 committed
158
    void(^succ)(id) = ^(id data) {
159 160
        [IBTLoadingView hideHUDWithText:nil];

陈俊俊's avatar
陈俊俊 committed
161 162
        ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
        userUtil.bAutoLogin = @( [_m_containerView isAutoLogin] );
管鹏飞's avatar
管鹏飞 committed
163

陈俊俊's avatar
陈俊俊 committed
164 165 166 167 168
        [userUtil saveArchive];
        
        ICRAppViewControllerManager *mgr =
        [ICRAppViewControllerManager getAppViewControllerManager];
        [mgr openMainFrame];
169 170 171 172
        
        
#pragma 可以开新线程 ,待优化
        //当登陆成功时就建立功能数据表
173
//        [[GXFFunctionDB sharedInstance] deleteTables];
174 175
        [[GXFFunctionDB sharedInstance]createTables];
        
176
        
177
        //完成对初始化数据书库的操作
freecui's avatar
freecui committed
178 179 180 181 182 183 184
        if (![[GXFFunctionDBHelper sharedInstance] successInsertOriginFunctions]) {
            [[GXFFunctionDBHelper sharedInstance] insertAllOriginFunctions];
        }
        if (![[GXFFunctionDBHelper sharedInstance] sucessInsertOriginDisplayFunctions]) {
            [[GXFFunctionDBHelper sharedInstance] insertAllOriginDisplayFunctions];
        }
        
freecui's avatar
freecui committed
185

freecui's avatar
freecui committed
186 187 188 189 190 191 192 193 194 195
        
        //更改功能权限
        for (int count = 0; count < userUtil.permissions.count; count ++) {
            GXFFunction *function = [[GXFFunctionDB sharedInstance]functionSelectWithId:[userUtil.permissions[count] integerValue]];
            if (function.Id) {
                function.hasPermission = 1;
                [[GXFFunctionDB sharedInstance] updateFunctionHasPermissionWithId:function];
            }
        }
        
freecui's avatar
freecui committed
196 197 198 199
        //配置功能 不是默认配置
        NSUserDefaults *f_default = [NSUserDefaults standardUserDefaults];
        BOOL noDefault = [[f_default objectForKey:@"noDefault"] integerValue] > 0 ? YES : NO;
        if (!noDefault) {
freecui's avatar
freecui committed
200 201
            [[GXFFunctionDB sharedInstance]defaultdisplayFunctions];
        }
freecui's avatar
freecui committed
202
        
203
        
freecui's avatar
freecui committed
204 205 206
        //极光别名
        NSSet *setTags = [NSSet setWithArray:@[@""]];
        [APService setTags:setTags
freecui's avatar
freecui committed
207
                     alias:userUtil.userId
freecui's avatar
freecui committed
208 209
          callbackSelector:nil object:nil];
        
陈俊俊's avatar
陈俊俊 committed
210
    };
mei's avatar
mei committed
211
    
陈俊俊's avatar
陈俊俊 committed
212
    void(^fail)(id) = ^(id data) {
freecui's avatar
freecui committed
213
        CLog(@"error =%@",data);
214 215 216
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];//@"输入的信息不正确,请重新输入"
//        [IBTLoadingView showTextOnly: data inView:self.view];
陈俊俊's avatar
陈俊俊 committed
217
    };
218
    [IBTLoadingView showProgressLabel:@"正在加载..."];
陈俊俊's avatar
陈俊俊 committed
219 220 221 222 223 224
    ICRHTTPController *httpCtrl = [ICRHTTPController sharedController];
    [httpCtrl doLoginWithUserName:nsUserName
                         password:nsPassword
                     registerCode:nsRegisterCode
                          success:succ
                          failure:fail];
225
#endif
mei's avatar
mei committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
}

#pragma mark - TextObserver
- (void)inputTextEditChanged:(NSNotification *)obj {
    [self.m_containerView checkLoginEnable];
}

#pragma mark - Keyboard
- (void)keyboardWillShow:(NSNotification *)note {
    // get keyboard size and loctaion
    CGRect keyboardBounds;
    [[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
    NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
    
    // Need to translate the bounds to account for rotation.
    keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];
    
    // animations settings
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:[duration doubleValue]];
    [UIView setAnimationCurve:[curve intValue]];
    
    // set views with new info
    self.m_containerView.y = - 50.0f;
    
    // commit animations
    [UIView commitAnimations];
}

- (void)keyboardWillHide:(NSNotification *)note {
    NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
    
    // animations settings
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:[duration doubleValue]];
    [UIView setAnimationCurve:[curve intValue]];
    
    // set views with new info
    self.m_containerView.y = m_fDefaultContainerY;
    
    // commit animations
    [UIView commitAnimations];
}

@end