| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328 |
- //
- // LoginViewController.m
- // TabBar
- //
- // Created by 黄玉林 on 15/7/5.
- // Copyright (c) 2015年 黄玉林. All rights reserved.first commit~~~!!!
- //
- #import "LoginViewController.h"
- #import "MyComBox.h"
- #import "XGPush.h"
- #import "AppDelegate.h"
- #import <Foundation/Foundation.h>
- #import "GTMBase64.h"
- #include <CommonCrypto/CommonDigest.h>
- #include <CommonCrypto/CommonHMAC.h>
- #import "SSCheckBoxView.h"
- #import "UASUserInfo.h"
- #import "UASWorkManager.h"
- #import "NSString+secri.h"
- #define kAlphaNum @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
- //@interface MyLoginText
- //@end
- static LoginViewController *uas_LoginManager;
- @interface LoginViewController()
- {
- UIView *myView;
- BOOL needSetComBox;
- MyComBox *dd1;
- NSMutableArray* doubleMasterArray;
- UASNetworkManager *loginSeverManager;
- NSMutableArray *masterArray;
- UITextField *masterText;
- UITextField *nameText;
- UITextField *passText;
- UITextField *duankou;
- NSDictionary *tempMasterDic;
- NSString *tempIp;
- UILabel* label;
- UIButton *btn0;
- NSMutableArray *ipAndPortArray;
- BOOL isNoFirstLogin;
- BOOL isAutoLogin;
- UIAlertView *remoteAlertView;
-
- UIAlertController *alertController;
-
- AppDelegate *myDelegate;
-
- NSArray *_erpArray;
- NSMutableArray *_erpNameAndIpArray;
- BOOL isInB2B;
- BOOL isInERP;
- BOOL isInSaas;
-
- SSCheckBoxView *remerberPass;
-
- BOOL erpIsLoginChecked;
- BOOL b2bIsLoginChecked;
-
- BOOL isForDayToGetData;
-
- }
- @end
- #define My_Y 300;
- #define My_X 100;
- @implementation LoginViewController
- -(void)remoteAnimation:(NSString *)message
- {
- if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending) {
- UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125.0, 45, 30.0, 30.0)];
- aiView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
- alertController= [UIAlertController alertControllerWithTitle:message message:@"" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"关闭" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- [aiView stopAnimating];
- }];
- [alertController addAction:cancelAction];
- [alertController.view addSubview:aiView];
- [aiView startAnimating];
- //[self presentViewController:alertController animated:YES completion:nil];
- }else
- {
- remoteAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil, nil ];
- UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125.0, 80.0, 30.0, 30.0)];
- aiView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
- //check if os version is 7 or above. ios7.0及以上UIAlertView弃用了addSubview方法
- if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending) {
- [remoteAlertView setValue:aiView forKey:@"accessoryView"];
- }else{
- [remoteAlertView addSubview:aiView];
- }
- [remoteAlertView show];
- [aiView startAnimating];
- }
- }
- -(void)dismissAlert
- {
-
- if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending) {
- [alertController dismissViewControllerAnimated:YES completion:nil];
- }else
- {
- [remoteAlertView dismissWithClickedButtonIndex:0 animated:YES];
- }
- }
- -(void)checkBoxViewChangedState:(SSCheckBoxView *)cbv
- {
- // DLog(@"复选框状态: %@",cbv.checked ? @"选中" : @"没选中");
- NSUserDefaults *userDefault=[NSUserDefaults standardUserDefaults];
- if (cbv.checked) {
- [userDefault setBool:YES forKey:@"isRemerberPass"];
- }else
- [userDefault setBool:NO forKey:@"isRemerberPass"];
- }
- -(void)chooseMaster
- {
-
- //masterText.userInteractionEnabled=NO;
- DXAlertView *alert = [[DXAlertView alloc] initWithTitle:@"请选择master" contentText:nil leftButtonTitle:nil rightButtonTitle:@"确定" isTurnLeft:NO];
- alert.pickerView.delegate=self;
- alert.pickerView.dataSource=self;
- alert.topVC=self;
- [alert show];
- [alert.pickerView selectRow:0 inComponent:0 animated:NO];
- alert.rightBlock=^(){
- //if (!self.master.text) {
- //self.master.text=[[doubleMasterArray objectAtIndex:defaultPickerRow_MASTER] objectForKey:@"ma_function"];
- //tempMasterDic=[doubleMasterArray objectAtIndex:defaultPickerRow_MASTER];
-
- //}
-
- };
- alert.dismissBlock=^(){
- [masterText resignFirstResponder];
- };
- }
- -(void)hadIp
- {
- [self clickBackGround:nil];
- [self getMasterDatas];
- }
- -(void)startAmation
- {
- // //动画
- // if (needSetComBox) {
- // [UIView beginAnimations:nil context:nil];
- // [UIView setAnimationDuration:1];
- // [myView setFrame:CGRectMake(0, 150,myView.bounds.size.width,myView.bounds.size.height)];
- // dd1.alpha=0;
- // duankou.alpha=0;
- // label.alpha=0;
- // btn0.alpha=0;
- // [UIView commitAnimations];
- // //把dropdownList放到前面,防止下拉框被别的控件遮住
- // [self.view.superview bringSubviewToFront:myView];
- // //dd1.hidden=YES;
- // needSetComBox=NO;
- // }else
- // {
- // //dd1.hidden=NO;
- // needSetComBox=YES;
- // [UIView beginAnimations:nil context:nil];
- // [UIView setAnimationDuration:1];
- // [myView setFrame:CGRectMake(0, self.view.bounds.size.height,myView.bounds.size.width,myView.bounds.size.height)];
- // dd1.alpha=1;
- // duankou.alpha=1;
- // label.alpha=1;
- // btn0.alpha=1;
- // [UIView commitAnimations];
- // }
-
- }
- -(void)getMasterDatas
- {
- tempIp=[dd1.textField.text stringByAppendingFormat:@":%@",duankou.text];
- NSString *urlStr=[@"http://" stringByAppendingFormat:@"%@/ERP/mobile/getAllMasters.action",tempIp];
- [loginSeverManager request:urlStr method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- //请求成功
- DLog(@"成功!");
- [self startAmation];
- NSDictionary *dicAlet=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
-
- @try {
- doubleMasterArray=[[NSMutableArray alloc] initWithCapacity:2];
- masterArray=[[NSMutableArray alloc] initWithCapacity:2];
- for (int i=0 ;i<[[dicAlet objectForKey:@"masters"] count];i++) {
- DLog(@"user=%@",[[[dicAlet objectForKey:@"masters"] objectAtIndex:i] objectForKey:@"ma_user"]);
- [masterArray addObject:[[[dicAlet objectForKey:@"masters"] objectAtIndex:i] objectForKey:@"ma_user"]];
- NSString *masterUser=[[[dicAlet objectForKey:@"masters"] objectAtIndex:i] objectForKey:@"ma_user"];
- NSString *masterUserName=[[[dicAlet objectForKey:@"masters"] objectAtIndex:i] objectForKey:@"ma_function"];
- //存入字典
- id tempDic=[NSDictionary dictionaryWithObjectsAndKeys:masterUserName,@"ma_function",masterUser,@"ma_user",nil];
- //加入数组
- [doubleMasterArray addObject:tempDic];
- }
- // DLog(@"tempMasterDic");
- tempMasterDic=[doubleMasterArray objectAtIndex:0];
- masterText.text=[tempMasterDic objectForKey:@"ma_function"];
- }
- @catch (NSException *exception) {
-
- [UASAlertView showWithTitle:nil content:@"请求的数据有误,请更换IP地址或端口!" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- }
- @finally {
- }
- //DLog(@"获取到的数据为:%@",masterArray);
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- DLog(@"失败!!!");
- [UASAlertView showWithTitle:nil content:@"网络请求失败,IP或者端口错误" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- }];
-
- }
- -(void)newGetMasterDatas
- {
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- tempIp=[userDefaults stringForKey:@"erpPort"];
- NSString *urlStr=[@"" stringByAppendingFormat:@"%@mobile/getAllMasters.action",tempIp];
- UASNetworkManager *loginSeverManager = [UASNetworkManager shareManager];
- loginSeverManager.responseSerializer = [AFHTTPResponseSerializer serializer];
-
- [loginSeverManager request:urlStr method:POST
- parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- //请求成功
- // DLog(@"成功!");
- [self startAmation];
- NSDictionary *dicAlet=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
- DLog(@"mster DIc=%@",dicAlet);
-
- if ([[dicAlet objectForKey:@"masters"] count]==0) {//针对于sass平台
-
- if (self.loginCompleted) {
-
- self.loginCompleted(nil);
-
- }
-
- DLog(@"in sass 平台 master 处理");
- doubleMasterArray=[[NSMutableArray alloc] initWithCapacity:1];
- id tempDic=[NSDictionary dictionaryWithObjectsAndKeys:[userDefaults objectForKey:@"erpMaster"],@"ma_function",[userDefaults objectForKey:@"erpMaster"],@"ma_user",nil];
- [doubleMasterArray addObject:tempDic];
- tempMasterDic=[doubleMasterArray objectAtIndex:0];
- [self saveUserData];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"platformSignal"object:nil];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- }else
- {
-
- NSException *expect = nil;
-
- @try {
- doubleMasterArray=[[NSMutableArray alloc]init];
- for (int i=0 ;i<[[dicAlet objectForKey:@"masters"] count];i++) {
- NSDictionary *tempDic = [[dicAlet objectForKey:@"masters"] objectAtIndex:i];
- tempDic = [NSDictionary changeType:tempDic];
- //加入数组
- [doubleMasterArray addObject:tempDic];
- }
-
- for (int i=0; i<[doubleMasterArray count]; i++) {
- id dic=[doubleMasterArray objectAtIndex:i];
- NSString *master=[dic objectForKey:@"ma_user"];
- if ([master isEqualToString:[userDefaults objectForKey:@"erpMaster"] ]) {
- tempMasterDic=dic;
- break;
- }
- }
- DLog(@"tempMasterDic=%@",tempMasterDic);
- [self saveUserData];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"platformSignal"object:nil];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- }
- @catch (NSException *exception) {
-
- expect = exception;
-
- [UASAlertView showWithTitle:nil content:@"请求的数据有误,master请求失败" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"platformSignal"object:nil];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- }
- @finally {
-
- if (expect) {
-
- NSError *error = [NSError new];
-
- if (self.loginCompleted) {
-
- self.loginCompleted(error);
-
- }
-
-
- }else{
-
- if (self.loginCompleted) {
-
- self.loginCompleted(nil);
-
- }
-
- }
-
-
- }
-
- }
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- //请求失败
- DLog(@"失败!!!");
-
- [UASAlertView showWithTitle:nil content:@"网络请求失败,master请求失败" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- }];
-
- }
- -(void)insertIpAndPort:(NSString*)ipAndPort
- {
- // if ([ipAndPortArray count]==5)
- // [ipAndPortArray removeObjectAtIndex:4];
- //DLog(@"insert string=%@",ipAndPort);
- BOOL hadTheSameIp=NO;
- for (int i=0; i<[ipAndPortArray count]; i++) {
- if ([[ipAndPortArray objectAtIndex:i] isEqualToString:ipAndPort]) {
- DLog(@"%@ ==== %@",[ipAndPortArray objectAtIndex:i],ipAndPort);
- hadTheSameIp=YES;
- break;
- }
- }
-
- if (!hadTheSameIp) {
- [ipAndPortArray addObject:tempIp];
- }
-
- }
- //登录请求,以及保存数据及状态 --没用
- -(void)loginCheck
- {
- [self remoteAnimation:Localized(@"UU_login_loading")];
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- //[self saveUserData];
- //参数
- //DLog(@"dic=%@,name=%@",[[userDefaults objectForKey:@"ipDic"] objectForKey:@"host_name"],[[userDefaults objectForKey:@"ipDic"] objectForKey:@"host_name"]);
- //NSString *ip=[tempIpDic objectForKey:@"ip"];//[[userDefaults objectForKey:@"ipDic"] objectForKey:@"ip"];//self.ipCombox.textField.text;
- NSString *userName=nameText.text;
- NSString *passWord=passText.text;
- NSString *master=[tempMasterDic objectForKey:@"ma_user"];//self.masterCombox.textField.text;
- // DLog(@"ip=%@,master=%@,name=%@,pass=%@",tempIp,master,userName,passWord);
- NSString *url=@"http://";
- url=[url stringByAppendingFormat:@"%@/%@",tempIp,@"ERP/mobile/login.action"];
-
- //初始化 网络manager
- loginSeverManager=[UASNetworkManager shareManager];
- loginSeverManager.responseSerializer=[AFHTTPResponseSerializer serializer];
-
- [loginSeverManager.securityPolicy setAllowInvalidCertificates:YES];
-
- NSString *urlStr=@"http://";
- urlStr=[urlStr stringByAppendingFormat:@"%@/%@?username=%@&password=%@&master=%@",tempIp,@"ERP/mobile/login.action",userName,passWord,master];
- // DLog(@"URL=%@",urlStr);
- NSString *param=@"";
- //param=[param stringByAppendingFormat:@"username=%@&password=%@&master=%@",@"LYH",@"676912",@"DataCenter"];
-
- //执行网络请求
- // DLog(@"开始登录请求!!!!");
- [loginSeverManager request:urlStr method:POST parameters:param progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- //请求成功
-
- [self dismissAlert];
- NSData *data=responseObject;
- NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
- [self insertIpAndPort:tempIp];
- NSString* isSuccess=[dic objectForKey:@"success"];
- // DLog(@"dic>>>>>>>>>>>>>>>>>>>>>>>>>=%@",dic);
- //保存sessionId
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- [userDefaults setObject:[dic objectForKey:@"sessionId"] forKey:@"sessionId"];
- if (dic.count>0&&isSuccess.boolValue) {
- [userDefaults setBool:YES forKey:@"loginState"];
- isNoFirstLogin=YES;
- isAutoLogin=YES;
- [self saveUserData];
- //设置别名
- NSString *indexName=[@"" stringByAppendingFormat:@"%@%@",master,userName];
- [XGPush setAccount:indexName];
-
- // UITabBarController *tabBarController=[self.storyboard instantiateViewControllerWithIdentifier:@"mainTabBarController"];
- // [self.navigationController pushViewController:tabBarController
- // animated:YES];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- }else
- {
-
- [UASAlertView showWithTitle:nil content:@"账号或密码错误,master请求失败" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- }
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- DLog(@"失败!!!");
- [self dismissAlert];
-
- [UASAlertView showWithTitle:nil content:@"网络请求失败,服务器未连接!master请求失败" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- }];
-
- }
- #pragma mark --- 管理平台登录
- -(void)newLoginCheckWithUserName:(NSString *)userName withPass:(NSString *)userPass
- {
-
-
- UASNetworkManager *loginSeverManager = [UASNetworkManager shareManager];
- loginSeverManager.responseSerializer = [AFHTTPResponseSerializer serializer];
-
- /**旧版管理平台的登录
- //获取当前时间戳
- NSDate *localDate = [NSDate date];
- NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[localDate timeIntervalSince1970]];
-
- NSString *urlStr = @"http://manage.ubtob.com/public/account";
- urlStr = [urlStr stringByAppendingFormat:@"?_timestamp=%@&user=%@&password=%@",timeSp,userName,userPass];
-
- //对urlStr进行 HmacSHA256 算法加密 key=@"http://www.ubtob.com/erp/sale/orders?something"
- NSString *secretUrl = [(AppDelegate*)[UIApplication sharedApplication].delegate hmacSHA256:@"http://www.ubtob.com/erp/sale/orders?something" text:urlStr];
- urlStr = [urlStr stringByAppendingFormat:@"&_signature=%@",secretUrl];
- */
-
- //新版账户中心的登录
- NSString *url = @"https://sso.ubtob.com/sso/login/mobile";
- NSDictionary *dic = @{@"mobile":userName,@"password":userPass};
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- if ([self checkStringByNumberOrStr:userName]) {
- [loginSeverManager request:url method:POST parameters:dic progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- NSData *data = responseObject;
- NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
-
- SLog(@"管理平台登录数据:%@",dic);
-
- [UASUserInfo shareManager].userInfo = dic;
-
- //保存新账户中心token
- [[NSUserDefaults standardUserDefaults] setObject:FORMAT(@"%@",[dic objectForKey:@"token"]) forKey:@"accountToken"];
-
- NSArray *tempArray = [dic objectForKey:@"datalist"];
- for (int i = 0; i<tempArray.count; i++) {
-
- NSDictionary *dic = tempArray[i];
-
- dic = [NSDictionary changeType:dic];
-
- if([dic[@"spaces"] isKindOfClass:[NSArray class]]){
-
- [UASUserInfo shareManager].b2bDic = dic;
-
-
- }
-
- }
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"platformSignal"object:nil];
-
-
- if (dic.count>0) {
-
- [userDefaults setObject:userName forKey:@"userName"];
-
- NSString *pwdStr = [NSString codeSeciWithStr:userPass];
- [userDefaults setObject:pwdStr forKey:@"userPass"];
- [userDefaults setBool:YES forKey:@"loginState"];
- isNoFirstLogin = YES;
- isAutoLogin = YES;
- //保存登录数据
- [self saveUserData];
-
- int erpcount = 0;
- for (int i = 0; i < tempArray.count; i++) {
- NSDictionary *dic = tempArray[i];
- NSString *platformStr = [NSString stringWithFormat:@"%@",[dic objectForKey:@"platform"]];
- if ([platformStr isEqualToString:@"ERP"]) {
- erpcount ++;
- }
- }
-
- /*
- platform
- 1.有EPR 和 B2B 账户的默认为ERP账户
- 2.只有B2B的账户 才为 B2B账户 或者 个人账户
- */
- if (erpcount == 0) {
-
- NSArray *userData = [tempArray[0] objectForKey:@"spaces"];
-
- /*此时分 个人用户 和 B2B用户*///没有spaces即无绑公司的为个人用户
- if (userData.count == 0)
- {
- //默认个人用户
- [[NSUserDefaults standardUserDefaults] setObject:@"PersonalUser" forKey:@"ERPUserOrB2BUser"];
-
- //保存个人emcode
- NSString *account = [NSString stringWithFormat:@"%@",[tempArray[0] objectForKey:@"account"]];
- [[NSUserDefaults standardUserDefaults] setObject:account forKey:@"erpUserName"];
- [[NSUserDefaults standardUserDefaults] setObject:account forKey:@"erpaccount"];
-
- //保存人名
- NSString *username = [NSString stringWithFormat:@"%@",[tempArray[0] objectForKey:@"userName"]];
- [[NSUserDefaults standardUserDefaults] setObject:username forKey:@"personName"];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"mytest" object:nil];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"platformSignal" object:nil];
- }
- else
- {
- //默认为B2B用户
- [[NSUserDefaults standardUserDefaults] setObject:@"B2BUser" forKey:@"ERPUserOrB2BUser"];
-
- //保存IP和名字
- NSMutableArray *b2bNameAndIpArray = [[NSMutableArray alloc]init];
- //保存公司数据,做成与ERP统一格式
- NSMutableArray *b2bPlatItems = [[NSMutableArray alloc]init];
- for (int i = 0; i < userData.count; i++) {
- NSDictionary *nameDic = userData[i];
-
- NSDictionary *nameAndIpDic = @{
- @"name":[NSString stringWithFormat:@"%@",[nameDic objectForKey:@"name"]],
- @"ipAndPort":@"http://b2b.usoftchina.com/"
- };
- [b2bNameAndIpArray addObject:nameAndIpDic];
-
- NSDictionary *dic = @{@"account":[tempArray[0] objectForKey:@"account"],
- @"imid":[tempArray[0] objectForKey:@"imid"],
- @"platform":@"B2B",
- @"enuu":[nameDic objectForKey:@"enuu"],
- @"name":[nameDic objectForKey:@"name"],
- @"master":@"",
- @"masterId":@"",
- @"userName":[tempArray[0] objectForKey:@"userName"],
- @"website":@"http://b2b.usoftchina.com/",
- @"businessCode":FORMAT(@"%@",[nameDic objectForKey:@"businessCode"]),
- };
- [b2bPlatItems addObject:dic];
-
- }
-
- [[NSUserDefaults standardUserDefaults] setObject:b2bPlatItems forKey:@"erpPlatItems"];
- [[NSUserDefaults standardUserDefaults] setObject:b2bNameAndIpArray forKey:@"erpNameAndIpArray"];
-
- //保存个人emcode
- NSString *account = [NSString stringWithFormat:@"%@",[tempArray[0] objectForKey:@"account"]];
- [[NSUserDefaults standardUserDefaults] setObject:account forKey:@"erpUserName"];
- [[NSUserDefaults standardUserDefaults] setObject:account forKey:@"erpaccount"];
-
- //保存个人中文名字
- NSString *userNameStr = [NSString stringWithFormat:@"%@",[tempArray[0] objectForKey:@"userName"]];
- [[NSUserDefaults standardUserDefaults] setObject:userNameStr forKey:@"personName"];
-
- //登录B2B
- [self selectB2BCompany:userData];
- }
- }
- else{
-
- //默认为ERP用户
- [[NSUserDefaults standardUserDefaults] setObject:@"ERPUser" forKey:@"ERPUserOrB2BUser"];
-
- //设置登录的平台标记
- [self checkPlatform:tempArray];
- }
- [(AppDelegate *)[UIApplication sharedApplication].delegate isAdmin];
- }else
- {
- [UASAlertView showWithTitle:nil content:@"该账号无所属公司" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- [self dismissAlert];
-
- }
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- //请求失败
- [UASUserInfo shareManager].b2bDic = @{};
- [[NSUserDefaults standardUserDefaults] setObject:@{} forKey:@"B2BplatformData"];
- [alertController dismissViewControllerAnimated:YES completion:nil];
- }];
- }
- }
- #pragma mark --- 新的B2B登录
- -(void)loginB2BwithUserData:(NSString *)userName withPass:(NSString *)userPass withAll:(NSArray *)allData withSpaceUU:(NSString *)spaceUU
- {
- //设置为B2B用户
- [[NSUserDefaults standardUserDefaults] setObject:@"B2BUser" forKey:@"ERPUserOrB2BUser"];
-
- // NSString *url = @"https://b2b.usoftchina.com/sso/login";
- NSString *url = @"https://sso.ubtob.com/sso/login";
- // NSString *url = @"http://113.105.74.135:8001/sso/login?appId=b2b";
-
- NSDictionary *params = @{
- @"appId":@"b2b",
- @"username":userName,
- @"password":userPass,
- //@"spaceId":@"76035"
- @"spaceUU":spaceUU
- };
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- // DLog(@"进来请求:%@ -- %@",userName,userPass);
-
- AFHTTPSessionManager *manager = [UASNetworkManager manager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
-
- // manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
- //加上这句话
- [manager.securityPolicy setAllowInvalidCertificates:YES];
-
- [manager POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
- NSDictionary *allHeaders = response.allHeaderFields;
- SLog(@"B2B登录的返回的请求头是什么:?:?:%@",allHeaders);
-
- NSString *cookieString = [allHeaders valueForKey:@"Set-Cookie"];
- DLog(@"B2B登录的返回的cookies是什么:?:?:%@",cookieString);
-
- //检验cookies是否过期
- [self testCookiesIsTrue:cookieString];
-
- [[UASWorkManager shareManager] loadAllPunchData];
-
- //保存数据
- [self saveDataWithsessionId:cookieString andAllData:allData];
-
- if (self.loginCompleted) {
-
- self.loginCompleted(nil);
-
- }
-
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- DLog(@"B2B登录请求失败1:%ld",(long)error.code);
- DLog(@"B2B登录请求失败3:%@",error);
-
- if (self.loginCompleted) {
-
- self.loginCompleted(error);
-
- }
-
- NSData *returnData = [[error userInfo] objectForKey:@"com.alamofire.serialization.response.error.data"];
- if (returnData) {
- NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
-
- NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
-
- SLog(@"B2B登录请求失败2:%@",errorStr);
- }
-
- //B2B独立版特殊登录
- // NSHTTPURLResponse * responses = (NSHTTPURLResponse *)task.response;
- // if (responses.statusCode == 200) {
- //
- // NSString *cookieString = [[responses allHeaderFields] valueForKey:@"Set-Cookie"];
- // //保存数据
- // [self saveDataWithsessionId:cookieString andAllData:allData];
- // }
- }];
-
- }
- -(void)testCookiesIsTrue:(NSString *)cookies //测试cookies是否正确
- {
- NSString *url = @"http://b2b.usoftchina.com/authentication";
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
-
- NSString *test = [cookies stringByReplacingOccurrencesOfString:@"," withString:@";"];
- //设置cookie
- [manager.requestSerializer setValue:test forHTTPHeaderField:@"Cookie"];
- [manager request:url method:GET parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
-
- DLog(@"验证Cookies成功:%@",responseObject);
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
-
- DLog(@"验证Cookies失败:%@",error);
- }];
- }
- #pragma mark --- B2B用户保存信息
- -(void)saveDataWithsessionId:(NSString *)sessionID andAllData:(NSArray *)dataDic
- {
- //保存sessionID --- B2B的为cookies
- sessionID = [sessionID stringByReplacingOccurrencesOfString:@"," withString:@";"];
- [[NSUserDefaults standardUserDefaults] setObject:sessionID forKey:@"sessionId"];
-
- NSMutableArray *b2bNameAndIpArray = [[NSMutableArray alloc]init];
-
- for (int i = 0; i < dataDic.count; i++) {
- NSDictionary *nameDic = dataDic[i];
-
- NSDictionary *nameAndIpDic = @{
- @"name":[NSString stringWithFormat:@"%@",[nameDic objectForKey:@"name"]],
- // @"ipAndPort":@"http://192.168.253.60:9090/platform-b2b/"
- //@"ipAndPort":@"http://192.168.253.192:8088/platform-b2b/"
- @"ipAndPort":@"http://b2b.usoftchina.com/"
- };
- [b2bNameAndIpArray addObject:nameAndIpDic];
- }
-
- [[NSUserDefaults standardUserDefaults] setObject:dataDic forKey:@"erpPlatItems"];
- // [[NSUserDefaults standardUserDefaults] setObject:b2bNameAndIpArray forKey:@"erpNameAndIpArray"];
-
- // [[NSUserDefaults standardUserDefaults] setObject:@"http://192.168.253.60:9090/platform-b2b/" forKey:@"ipAndPort"];
- //[[NSUserDefaults standardUserDefaults] setObject:@"http://192.168.253.192:8088/platform-b2b/" forKey:@"ipAndPort"];
- [[NSUserDefaults standardUserDefaults] setObject:@"http://b2b.usoftchina.com/" forKey:@"ipAndPort"];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"platformSignal" object:nil];
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"msgCount"object:nil];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"changeCompany" object:nil];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"mytest" object:nil];
-
- //OA权限设置
- [[NSNotificationCenter defaultCenter] postNotificationName:@"OAAdminJurisdiction" object:nil];
-
- //OA首页加载数据库
-
- }
- #pragma mark --- B2B登录后选择企业
- -(void)selectB2BCompany:(NSArray *)b2bArr
- {
- DLog(@"dengluxuanze:%@",b2bArr);
- _erpArray = b2bArr;
-
- if (_erpArray.count == 1) {
-
- NSString *enuu = [NSString stringWithFormat:@"%@",[_erpArray[0] objectForKey:@"enuu"]];
-
- NSDictionary *erpTempNameAndIpDic = [[[NSUserDefaults standardUserDefaults] objectForKey:@"erpNameAndIpArray"] objectAtIndex:0];
- [[NSUserDefaults standardUserDefaults] setObject:erpTempNameAndIpDic forKey:@"erpTempNameAndIpDic"];
-
- NSDictionary *b2b = [[[NSUserDefaults standardUserDefaults] objectForKey:@"erpPlatItems"] objectAtIndex:0];
- [[NSUserDefaults standardUserDefaults] setObject:b2b forKey:@"masterDic"];
-
- [[NSUserDefaults standardUserDefaults] setObject:enuu forKey:@"erpUuId"];
-
- [[NSUserDefaults standardUserDefaults] setObject:[_erpArray[0] objectForKey:@"account"] forKey:@"erpaccount"];
-
- NSString *pwdStr = [NSString encodeSeciWithStr:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"userPass"]]];
-
- [self loginB2BwithUserData:[[NSUserDefaults standardUserDefaults] objectForKey:@"userName"] withPass:pwdStr withAll:_erpArray withSpaceUU:enuu];
-
- }
- else{
- CGFloat xWidth = SCREEN_WIDTH- 20.0f;
- CGFloat yHeight = 300.0f;
- CGFloat yOffset = (SCREEN_HEIGHT - yHeight)/2.0f;
- UIPopoverListView * companyPopList = [[UIPopoverListView alloc] initWithFrame:CGRectMake(10, yOffset, xWidth, yHeight) isDateView:NO];
- companyPopList.isCannotClickBackGround = YES;
- companyPopList.delegate = self;
- companyPopList.datasource = self;
- companyPopList.isCannotClickBackGround = NO;
- [companyPopList setTitle:@"请选择公司"];
- companyPopList.BackBlock=^(){
-
- };
- [companyPopList show];
- }
- }
- #pragma mark --- ERP登录
- -(void)checkPlatform:(NSArray *)platArray
- {
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- [userDefaults setBool:NO forKey:@"b2bOpen"];
- [userDefaults setBool:NO forKey:@"erpOpen"];
-
- NSArray *erpArray = [self checkErpAccountCount:platArray];
-
-
- for (int i = 0; i < [platArray count]; i++) {
- id platForm = platArray[i];
- NSString *formName = [platForm objectForKey:@"platform"];
- if ([formName isEqualToString:@"B2B"]) {
- [userDefaults setObject:[platForm objectForKey:@"account"] forKey:@"b2bUserName"];
-
- }
- else if([formName isEqualToString:@"ERP"])
- {
- if ([erpArray count]==1) {
- isInERP=YES;
-
- id erpPlatItem=[erpArray objectAtIndex:0];
- NSString *webStrPort=[erpPlatItem objectForKey:@"website"];
-
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- NSDictionary *erpTempNameAndIpDic=[[userDefaults objectForKey:@"erpNameAndIpArray"] objectAtIndex:0];
- [userDefaults setObject:erpTempNameAndIpDic forKey:@"erpTempNameAndIpDic"];
- [userDefaults setObject:[@"" stringByAppendingFormat:@"%@",[erpPlatItem objectForKey:@"enuu"]] forKey:@"erpUuId"];
- [userDefaults setObject:[erpPlatItem objectForKey:@"website"] forKey:@"erpPort"];
- [userDefaults setObject:webStrPort forKey:@"ipAndPort"];
- [userDefaults setObject:[erpPlatItem objectForKey:@"account"] forKey:@"erpUserName"];
- [userDefaults setObject:[erpPlatItem objectForKey:@"master"] forKey:@"erpMaster"];
-
- //保存登录数据
- [self newLoginExtend];
- }
- }
- else if([formName isEqualToString:@"SaaS"])
- {
- isInSaas=YES;
- }
- }
-
-
-
- if ([erpArray count]>1) {
- _erpArray = erpArray;
- CGFloat xWidth = SCREEN_WIDTH- 20.0f;
- CGFloat yHeight = 300.0f;
- CGFloat yOffset = (SCREEN_HEIGHT - yHeight)/2.0f;
- UIPopoverListView* companyPopList = [[UIPopoverListView alloc] initWithFrame:CGRectMake(10, yOffset, xWidth, yHeight) isDateView:NO];
- companyPopList.isCannotClickBackGround = YES;
- companyPopList.delegate=self;
- companyPopList.datasource=self;
- [companyPopList setTitle:@"请选择公司"];
- companyPopList.BackBlock=^(){
- [self dismissAlert];
- };
- [companyPopList show];
- }
- }
- #pragma mark --- 存储 公司(企业)名称 和 公司IP
- -(NSArray *)checkErpAccountCount:(NSArray *)platArray
- {
- _erpNameAndIpArray = [[NSMutableArray alloc] init];
- NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
-
- NSMutableArray *erpArray = [[NSMutableArray alloc] initWithCapacity:0];
-
- for (int i=0; i<[platArray count]; i++) {
- id platForm = platArray[i];
- NSString *formName = [platForm objectForKey:@"platform"];
-
- if ([formName isEqualToString:@"ERP"]) {
- [erpArray addObject:platForm];
-
- NSString *webStrPort = [platForm objectForKey:@"website"];
- if (![webStrPort isEqualToString:@"null"]) {
-
- //存入字典 公司名 和 ip
- id tempDic = [NSDictionary dictionaryWithObjectsAndKeys:[platForm objectForKey:@"name"],@"name",webStrPort,@"ipAndPort",nil];
- //加入数组
- [_erpNameAndIpArray addObject:tempDic];
-
- }
-
- }else if([formName isEqualToString:@"B2B"])
- {
- /*做成跟ERP一样的数据格式*/
- NSArray *spacesArr = [platForm objectForKey:@"spaces"];
- for (int i = 0; i < spacesArr.count; i++) {
- /*如果B2B企业名跟ERP相同则不加入*/
- NSString *nameStr = FORMAT(@"%@",[spacesArr[i] objectForKey:@"name"]);
- int num = 0;
- for (int j = 0; j<platArray.count; j++) {
- id platForm1 = platArray[j];
- NSString *formName1 = [platForm1 objectForKey:@"platform"];
- if ([formName1 isEqualToString:@"ERP"]) {
- NSString *secondName = FORMAT(@"%@",[platForm1 objectForKey:@"name"]);
- if ([nameStr isEqualToString:secondName]) {
- num ++;
- }
- }
- }
-
- if (num == 0) {
- NSDictionary *dic = @{@"account":FORMAT(@"%@",[platForm objectForKey:@"account"]),
- @"imid":FORMAT(@"%@",[platForm objectForKey:@"imid"]),
- @"platform":@"B2B",
- @"enuu":FORMAT(@"%@",[spacesArr[i] objectForKey:@"enuu"]),
- @"name":FORMAT(@"%@",[spacesArr[i] objectForKey:@"name"]),
- @"master":@"",
- @"masterId":@"",
- @"userName":FORMAT(@"%@",[platForm objectForKey:@"userName"]),
- @"website":@"http://b2b.usoftchina.com/",
- @"businessCode":FORMAT(@"%@",[spacesArr[i] objectForKey:@"businessCode"]),
- };
- [erpArray addObject:dic];
-
- NSDictionary *tempDic = @{@"name":FORMAT(@"%@",[spacesArr[i] objectForKey:@"name"]),
- @"ipAndPort":@"http://b2b.usoftchina.com/"
- };
- [_erpNameAndIpArray addObject:tempDic];
- }
- }
-
- }
- }
-
- [userDefaults setObject:erpArray forKey:@"erpPlatItems"];
- [userDefaults setObject:_erpNameAndIpArray forKey:@"erpNameAndIpArray"];
-
- return erpArray;
- }
- #pragma mark --- 登录ERP
- -(void)newLoginExtend
- {
- NSString *url = FORMAT(@"%@mobile/login.action",g_id);
- NSDictionary *dic = @{@"enuu":g_B2B_enuu,@"token":g_accountToken};
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- //执行网络请求
- DLog(@"开始登录请求!!!!");
-
- UASNetworkManager *loginSeverManager = [UASNetworkManager shareManager];
- loginSeverManager.responseSerializer = [AFHTTPResponseSerializer serializer];
- [loginSeverManager request:url method:POST parameters:dic progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- //请求成功
- SLog(@"成功!");
- [[UASWorkManager shareManager] loadAllPunchData];
- erpIsLoginChecked=YES;
- [self dismissAlert];
- NSData *data=responseObject;
- NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
- //[self insertIpAndPort:tempIp];
- NSString* isSuccess=[dic objectForKey:@"success"];
- DLog(@"dic>>>>>>>>>>>>>>>>>>>>>>>>>=%@",dic);
-
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- if (dic.count>0&&isSuccess.boolValue) {
- //保存sessionId
- [userDefaults setObject:[dic objectForKey:@"sessionId"] forKey:@"sessionId"];
- [userDefaults setObject:[dic objectForKey:@"erpaccount"] forKey:@"erpaccount"];
- [userDefaults setObject:FORMAT(@"%@",[dic objectForKey:@"uu"]) forKey:@"erpUuId"];
- [[NSUserDefaults standardUserDefaults] setObject:FORMAT(@"%@",[dic objectForKey:@"master"]) forKey:@"erpMaster"];
-
- [(AppDelegate*)[UIApplication sharedApplication].delegate getPersonIdFromSever:[dic objectForKey:@"erpaccount"]];
-
- [userDefaults setBool:YES forKey:@"loginState"];
- isNoFirstLogin=YES;
- isAutoLogin=YES;
-
- //重新注册设备
- if (![userDefaults boolForKey:@"isMeNoPushCao"]) {
- [(AppDelegate*)[UIApplication sharedApplication].delegate initPushData];
- }
- //
- //设置别名
- NSString *indexName=[@"" stringByAppendingFormat:@"%@",[userDefaults objectForKey:@"userName"]];
- [XGPush setAccount:indexName];
-
- [userDefaults setBool:YES forKey:@"erpOpen"];
- DLog(@"indexERP----------------name=%@",indexName);
- if (self.erpForB2bCookieBlock) {
- self.erpForB2bCookieBlock();
- }
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"msgCount"object:nil];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"checkOfenSearchItem"object:nil];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"changeCompany"object:nil];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"kaiqizidongwaiqing" object:nil];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"JOMSGREFRASHTABLE" object:nil];
- //OA权限设置
- [[NSNotificationCenter defaultCenter] postNotificationName:@"OAAdminJurisdiction" object:nil];
-
- //OA首页加载数据库
-
- //请求账套
- [self newGetMasterDatas];
- }else
- {
- [userDefaults setBool:NO forKey:@"erpOpen"];
-
- [UASAlertView showWithTitle:nil content:@"账号或密码错误,UAS登录失败" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- }
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"platformSignal"object:nil];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- //请求失败
- if (self.loginCompleted) {
-
- self.loginCompleted(error);
-
- }
- DLog(@"失败!!! error=%@",error);
- erpIsLoginChecked=YES;
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"erpOpen"];
- [self dismissAlert];
-
- [UASAlertView showWithTitle:nil content:@"网络请求失败,服务器未连接!,UAS登录失败" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"platformSignal"object:nil];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- }];
- }
- //存入本地数据
- -(void)saveUserData
- {
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
-
- [userDefaults setObject:tempMasterDic forKey:@"masterDic"];
- //存一个master名,和先前使用的master数组
- [userDefaults setObject:masterText.text forKey:@"master"];
-
- [userDefaults setObject:doubleMasterArray forKey:@"doubleMasterArray"];
-
- [userDefaults setBool:isNoFirstLogin forKey:@"isFirstLogin"];
- [userDefaults setBool:isAutoLogin forKey:@"isAutoLogin"];
-
- [userDefaults setObject:ipAndPortArray forKey:@"ipAndPortArray"];
-
-
- DLog(@"aizheshi1:%@",tempMasterDic);
- DLog(@"aizheshi2:%@",masterText.text);
- DLog(@"aizheshi3:%@",doubleMasterArray);
- DLog(@"aizheshi4:%d",isNoFirstLogin);
- DLog(@"aizheshi5:%d",isAutoLogin);
- DLog(@"aizheshi6:%@",ipAndPortArray);
- }
- //取出本地数据,并且初始化 -- 没用
- -(void)initDataForLoginViewController
- {
- DLog(@"loginView---2");
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
-
- isNoFirstLogin=[userDefaults boolForKey:@"isFirstLogin"];
- isAutoLogin=[userDefaults boolForKey:@"isAutoLogin"];
- [self startAmation];
- if (isNoFirstLogin) {
- //[self startAmation];
- ipAndPortArray =[userDefaults objectForKey:@"ipAndPortArray"];
- dd1.tableArray=ipAndPortArray;
- nameText.text=[userDefaults stringForKey:@"userName"];
-
- NSString *pwdStr = [NSString encodeSeciWithStr:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"userPass"]]];
- passText.text=pwdStr;
- masterText.text=[userDefaults stringForKey:@"master"];
-
-
- doubleMasterArray=[userDefaults objectForKey:@"doubleMasterArray"];
- tempMasterDic=[userDefaults objectForKey:@"masterDic"];
- tempIp= [UASUserInfo shareManager].urlIp;
- //DLog(@"loginState=%@",[userDefaults objectForKey:@"loginState"]?@"YES":@"NO");
- if ([userDefaults boolForKey:@"isRemerberPass"]) {
- remerberPass.checked=YES;
- }
- else
- {
- remerberPass.checked=NO;
- }
-
- NSArray *array= [tempIp componentsSeparatedByString:@":"];
- DLog(@"%@",array);
- //dd1.textField.text=[array objectAtIndex:0];
- DLog(@"loginView---3");
- //duankou.text=[array objectAtIndex:1];
- DLog(@"loginView---4");
-
- }
-
- }
- //- (void)didReceiveMemoryWarning {
- // [super didReceiveMemoryWarning];
- // // Dispose of any resources that can be recreated.
- //
- //}
- #pragma mark --- 设置单列选择器
- //返回几列
- -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
- {
- return 1;
- }
- -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
- {
- return doubleMasterArray.count;
- }
- -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
- {
- return [[doubleMasterArray objectAtIndex:row] objectForKey:@"ma_function"];
- //[masterArray objectAtIndex:row];
- }
- -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
- {
- masterText.text=[[doubleMasterArray objectAtIndex:row] objectForKey:@"ma_function"];
- [masterText resignFirstResponder];
- tempMasterDic=[doubleMasterArray objectAtIndex:row];
- // defaultPickerRow_MASTER=row;
- }
- //UITextField delegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
-
- if (textField == nameText) { // _textField_QQ和_textField_password已被设为属性,判断键盘的第一响应者,如果是QQ输入框
-
- return [passText becomeFirstResponder]; //点击右下角的Next按钮,则将键盘第一响应者设为_textField_password,即密码输入框
-
- }else if(textField == passText){
-
- return [passText resignFirstResponder]; //否则(键盘第一响应者为密码输入框),则使键盘失去第一响应者,即消失
-
- }else if(textField ==dd1.textField)
- {
-
- return [duankou becomeFirstResponder];
- }else
- {
- return [duankou resignFirstResponder];
- }
-
- }
- - (IBAction)clickBackGround:(id)sender {
-
- [dd1.textField resignFirstResponder];
- [nameText resignFirstResponder];
- [passText resignFirstResponder];
- [masterText resignFirstResponder];
- [duankou resignFirstResponder];
- }
- -(void)backChooseLogin
- {
- DLog(@"点击来注销账户!!");
- NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
- [userDefaults setBool:NO forKey:@"isAutoLogin"];
- // AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
- // [myDelegate.rootNavController popToRootViewControllerAnimated:YES];
-
- }
- -(BOOL)checkStringByNumberOrStr:(NSString *)str
- {
- NSCharacterSet *cs;
- cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
- NSString *filtered =
- [[str componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
- BOOL basic = [str isEqualToString:filtered];
- if (!basic) {
-
-
- }
- return basic;
-
- }
- //加密
- - (NSString *) hmacSha1:(NSString*)key text:(NSString*)text
- {
-
- const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
-
- const char *cData = [text cStringUsingEncoding:NSUTF8StringEncoding];
-
- uint8_t cHMAC[CC_SHA256_DIGEST_LENGTH];
-
- CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
- //NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:CC_SHA1_DIGEST_LENGTH];
- NSString *hash;
- NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
-
- for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++)
- [output appendFormat:@"%02x", cHMAC[i]];
- hash = output;
- return hash;
- }
- #pragma mark --- UIPopoverListView delegate FUN
- - (UITableViewCell *)popoverListView:(UIPopoverListView *)popoverListView
- cellForIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *identifier = @"cell";
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
- reuseIdentifier:identifier] ;
- id erpPlatItem = [_erpArray objectAtIndex:indexPath.row];
- cell.textLabel.text = [erpPlatItem objectForKey:@"name"];
- cell.textLabel.font = FONT_SIZE(13);;
-
- return cell;
- }
- - (NSInteger)popoverListView:(UIPopoverListView *)popoverListView
- numberOfRowsInSection:(NSInteger)section
- {
- return [_erpArray count];
- }
- - (void)popoverListView:(UIPopoverListView *)popoverListView
- didSelectIndexPath:(NSIndexPath *)indexPath
- {
- id erpPlatItem = [_erpArray objectAtIndex:indexPath.row];
- [[NSUserDefaults standardUserDefaults] setObject:erpPlatItem forKey:@"userManageAllDataDic"];
-
- NSString *userInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"ERPUserOrB2BUser"];
-
- if ([userInfo isEqualToString:@"ERPUser"]) {
- if ([[erpPlatItem objectForKey:@"platform"] isEqualToString:@"ERP"]) {
- NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
- NSDictionary *erpTempNameAndIpDic = [[userDefaults objectForKey:@"erpNameAndIpArray"] objectAtIndex:indexPath.row];
- [userDefaults setObject:erpTempNameAndIpDic forKey:@"erpTempNameAndIpDic"];
- [userDefaults setObject:[@"" stringByAppendingFormat:@"%@",[erpPlatItem objectForKey:@"enuu"]] forKey:@"erpUuId"];
- [userDefaults setObject:[erpPlatItem objectForKey:@"website"] forKey:@"erpPort"];
- [userDefaults setObject:[erpPlatItem objectForKey:@"website"] forKey:@"ipAndPort"];
- [userDefaults setObject:[erpPlatItem objectForKey:@"account"] forKey:@"erpUserName"];
- [userDefaults setObject:[erpPlatItem objectForKey:@"master"] forKey:@"erpMaster"];
-
- DLog(@"GAGAG1--:%@",erpTempNameAndIpDic);
-
- //保存登录数据
- [self newLoginExtend];
- }
- else{
- NSString *enuu = [NSString stringWithFormat:@"%@",[erpPlatItem objectForKey:@"enuu"]];
-
- NSDictionary *erpTempNameAndIpDic = [[[NSUserDefaults standardUserDefaults] objectForKey:@"erpNameAndIpArray"] objectAtIndex:indexPath.row];
- [[NSUserDefaults standardUserDefaults] setObject:erpTempNameAndIpDic forKey:@"erpTempNameAndIpDic"];
-
- NSDictionary *b2b = [[[NSUserDefaults standardUserDefaults] objectForKey:@"erpPlatItems"] objectAtIndex:indexPath.row];
- [[NSUserDefaults standardUserDefaults] setObject:b2b forKey:@"masterDic"];
-
- [[NSUserDefaults standardUserDefaults] setObject:enuu forKey:@"erpUuId"];
-
- //默认为B2B用户
- [[NSUserDefaults standardUserDefaults] setObject:@"B2BUser" forKey:@"ERPUserOrB2BUser"];
-
- //保存个人emcode
- NSString *account = [NSString stringWithFormat:@"%@",[erpPlatItem objectForKey:@"account"]];
- [[NSUserDefaults standardUserDefaults] setObject:account forKey:@"erpUserName"];
- [[NSUserDefaults standardUserDefaults] setObject:account forKey:@"erpaccount"];
-
- //保存个人中文名字
- NSString *userNameStr = [NSString stringWithFormat:@"%@",[erpPlatItem objectForKey:@"userName"]];
- [[NSUserDefaults standardUserDefaults] setObject:userNameStr forKey:@"personName"];
-
- NSString *pwdStr = [NSString encodeSeciWithStr:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"userPass"]]];
-
- [self loginB2BwithUserData:[[NSUserDefaults standardUserDefaults] objectForKey:@"userName"] withPass:pwdStr withAll:_erpArray withSpaceUU:enuu];
- }
- }
-
- else if ([userInfo isEqualToString:@"B2BUser"]) {
-
- NSString *enuu = [NSString stringWithFormat:@"%@",[erpPlatItem objectForKey:@"enuu"]];
-
- NSDictionary *erpTempNameAndIpDic = [[[NSUserDefaults standardUserDefaults] objectForKey:@"erpNameAndIpArray"] objectAtIndex:indexPath.row];
- [[NSUserDefaults standardUserDefaults] setObject:erpTempNameAndIpDic forKey:@"erpTempNameAndIpDic"];
-
- NSDictionary *b2b = [[[NSUserDefaults standardUserDefaults] objectForKey:@"erpPlatItems"] objectAtIndex:indexPath.row];
- [[NSUserDefaults standardUserDefaults] setObject:b2b forKey:@"masterDic"];
-
- [[NSUserDefaults standardUserDefaults] setObject:enuu forKey:@"erpUuId"];
-
- [self loginB2BwithUserData:[[NSUserDefaults standardUserDefaults] objectForKey:@"userName"] withPass:[[NSUserDefaults standardUserDefaults] objectForKey:@"userPass"] withAll:_erpArray withSpaceUU:enuu];
-
- }
-
- }
- - (NSInteger)numberOfSectionsInUIPopoverListView:(UIPopoverListView *)tableView
- {
- return 1;
- }
- - (CGFloat)popoverListView:(UIPopoverListView *)popoverListView
- heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 36.0f;
- }
- -(NSString*)popoverListView:(UIPopoverListView*)popoverListView titleForHeaderInSection:(NSInteger)section
- {
- return @"";
- }
- @end
|