iOS登录序列修复程序
这是我登录的成功参数,位于viewDidload的右括号下iOS登录序列修复程序,ios,Ios,这是我登录的成功参数,位于viewDidload的右括号下 //check whether it's a login or register NSString* command = (sender.tag==1)?@"register":@"login"; NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:command, @"command", fldUsername.text, @"u
//check whether it's a login or register
NSString* command = (sender.tag==1)?@"register":@"login";
NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:command, @"command", fldUsername.text, @"username", hashedPassword, @"password", nil];
//make the call to the web API
[[API sharedInstance] commandWithParams:params onCompletion:^(NSDictionary *json) {
//result returned
NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];
if ([json objectForKey:@"error"]==nil && [[res objectForKey:@"IdUser"] intValue]>0) {
[[API sharedInstance] setUser: res];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
//show message to the user
[[[UIAlertView alloc] initWithTitle:@"Logged in" message:[NSString stringWithFormat:@"Welcome %@",[res objectForKey:@"username"]] delegate:nil cancelButtonTitle:@"Close" otherButtonTitles: nil] show];
} else {
//error
[UIAlertView error:[json objectForKey:@"error"]];
}
}];
}
这是视图中的编程连接,我想在用户被授权时显示它
-(void)viewDidload
[super viewDidLoad];
{
if (![[API sharedInstance] isAuthorized]) {
[self performSegueWithIdentifier:@"ShowLogin" sender:nil];
}
问题是,当我在数据库中输入保存的登录凭据时,即用户名:user1密码:password,我得到了正确的UIAlert,我应该接收登录-欢迎用户1。但当我输入username:user1 password:fake password时,仍然会收到登录的UIAlert。此外,如果我尝试从应用程序注册新用户,即用户名:user2密码:password 2,我会收到身份验证失败的UIAlert。此外,当我输入有效凭据时,我的segue实际上不会发生。有什么建议吗
更新:注销代表
-(void)logout {
//logout the user from the server, and also upon success destroy the local authorization
[[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"logout", @"command", nil] onCompletion:^(NSDictionary *json) {
//logged out from server
[API sharedInstance].user = nil;
[self performSegueWithIdentifier:@"ShowLogin" sender:nil];
}];
}
找到添加了内联注释//的行,然后在代码中尝试这些注释。同样如前所述,更新登录视图->视图将出现并注销方法
希望这有帮助。您在哪里设置-[[API sharedInstance]设置已授权:否];因为如果用户注销并重新登录,那么下次应该将此paran设置为NO。我想这是在您的情况下造成的问题,当您下次尝试使用错误的密码时,该参数已设置为“是”。只是猜测一下,因为没有太多用于注销的代码。如果登录/注册不完整,则会设置这些错误。另外,我已经测试了该应用程序,正在使用相同的代码将其导入到我自己的应用程序中。在注销操作以及登录屏幕上,ViewWillAspect事件-尝试以下操作:[API sharedInstance].isAuthorized=NO和[API sharedInstance].user=nil。这提醒了我,原始应用程序有一个初始视图public,必须检查您提示的参数:当用户单击某个操作时,它会将他们带到登录屏幕上/我只是想使用登录屏幕,但我忘记了分析任何已检查的实例。老实说,我甚至不知道我在哪里指定在这一观点被驳回。
[[API sharedInstance] commandWithParams:params onCompletion:^(NSDictionary *json) {
//result returned
NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];
if ([json objectForKey:@"error"]==nil && [[res objectForKey:@"IdUser"] intValue]>0) {
[[API sharedInstance] setUser: res];
[API sharedInstance].isAuthorized = YES; //Added
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
//show message to the user
[[[UIAlertView alloc] initWithTitle:@"Logged in" message:[NSString stringWithFormat:@"Welcome %@",[res objectForKey:@"username"]] delegate:nil cancelButtonTitle:@"Close" otherButtonTitles: nil] show];
} else {
[[API sharedInstance] setUser: nil]; //Added
[API sharedInstance].isAuthorized = NO; //Added
//error
[UIAlertView error:[json objectForKey:@"error"]];
}
}];