|
|
@@ -92,17 +92,27 @@
|
|
|
|
|
|
NSMutableDictionary* up = self.logindata[indexPath.row];
|
|
|
|
|
|
+ NSString *user = up[@"name"];
|
|
|
+ NSString *password = up[@"pwd"];
|
|
|
|
|
|
+ if (user.length == 0 || password.length == 0) {
|
|
|
+ [self dismissViewControllerAnimated:YES completion:nil];
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
UIApplication * app = [UIApplication sharedApplication];
|
|
|
AppDelegate *appDelegate = (AppDelegate *)[app delegate];
|
|
|
|
|
|
if(appDelegate.bLogin)
|
|
|
{
|
|
|
+ if ([user.lowercaseString isEqualToString:appDelegate.user.lowercaseString]) { // 当前用户
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Switch user"];
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
- NSDictionary* return_json = [RANetwork logout];
|
|
|
+ [RANetwork logout];
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
@@ -137,147 +147,107 @@
|
|
|
[appDelegate SetSo:nil];
|
|
|
[appDelegate set_main_button_panel];
|
|
|
|
|
|
+ [appDelegate Logout];
|
|
|
+ [appDelegate checkLogin:NO];
|
|
|
+
|
|
|
+// [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
|
|
|
|
|
|
- [appDelegate Logout];
|
|
|
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
-
|
|
|
-
|
|
|
- int ret=[RANetwork Authorize:up[@"name"] password:up[@"pwd"]];
|
|
|
-
|
|
|
+
|
|
|
+ int ret=[RANetwork Authorize:user password:password];
|
|
|
+
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
-
|
|
|
|
|
|
+ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
+
|
|
|
if(ret==RESULT_TRUE)
|
|
|
-
|
|
|
{
|
|
|
-
|
|
|
- //
|
|
|
- // NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
|
|
|
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
|
|
- // appDelegate.contact_id=contactid;
|
|
|
- // appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
|
|
|
-
|
|
|
+
|
|
|
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
|
|
|
[defaults removeObjectForKey:@"user"];
|
|
|
[defaults removeObjectForKey:@"password"];
|
|
|
if(true)
|
|
|
{
|
|
|
NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
|
|
|
- NSString* encryptp=[AESCrypt encrypt:up[@"pwd"] password:@"usai"] ;
|
|
|
-
|
|
|
+ NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
|
|
|
+
|
|
|
[defaults setValue:encryptu forKey:@"user"];
|
|
|
[defaults setValue:encryptp forKey:@"password"];
|
|
|
-
|
|
|
-
|
|
|
- // [defaults setBool:TRUE forKey:@"autologin"];
|
|
|
+
|
|
|
}
|
|
|
[defaults synchronize];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
|
|
|
if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
|
|
|
{
|
|
|
-
|
|
|
[main_vc checklogin:false];
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
[main_vc checklogin:false];
|
|
|
-
|
|
|
}
|
|
|
- [self dismissViewControllerAnimated:true completion:^{
|
|
|
- if(self.returnValue)
|
|
|
- self.returnValue(true);
|
|
|
- }];
|
|
|
-
|
|
|
|
|
|
-
|
|
|
- }
|
|
|
+ [self dismissViewControllerAnimated:true completion:^{
|
|
|
+ if(self.returnValue)
|
|
|
+ self.returnValue(true);
|
|
|
+ }];
|
|
|
+
|
|
|
+ } // 登陆成功
|
|
|
else
|
|
|
{
|
|
|
NSString* msg=nil;
|
|
|
-
|
|
|
+
|
|
|
switch (ret) {
|
|
|
-
|
|
|
+
|
|
|
case RESULT_NET_NOTAVAILABLE:
|
|
|
msg = MSG_NET_NOTAVAILABLE;
|
|
|
break;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
case RESULT_NET_ERROR:
|
|
|
msg = MSG_NET_ERROR;
|
|
|
break;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
case RESULT_FALSE:
|
|
|
msg = MSG_USERAUTH_ERROR;
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case RESULT_VER_LOW:
|
|
|
msg = MSG_VER_LOW;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
|
|
|
//block代码块取代了delegate
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
[self dismissViewControllerAnimated:true completion:^{
|
|
|
if(self.returnValue)
|
|
|
self.returnValue(false);
|
|
|
}];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
}];
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
[alertControl addAction:actionOne];
|
|
|
-
|
|
|
|
|
|
-
|
|
|
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
|
|
|
-
|
|
|
-
|
|
|
[self presentViewController:alertControl animated:YES completion:nil];
|
|
|
-
|
|
|
|
|
|
-
|
|
|
- //[RAUtils alert_view:msg title:@"Sign in"];
|
|
|
-
|
|
|
+ } // 登陆失败
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- });
|
|
|
- });
|
|
|
+ }); // update login ui
|
|
|
+
|
|
|
+ }); // attemp login
|
|
|
+
|
|
|
+ }); // update logout ui
|
|
|
+
|
|
|
+ }); // logout
|
|
|
}
|
|
|
|
|
|
|