OfflineUnlockViewController.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // OfflineUnlockViewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Ray on 10/10/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OfflineUnlockViewController.h"
  9. #import "RAUtils.h"
  10. #import "iSalesDB.h"
  11. #import "AESCrypt.h"
  12. @interface OfflineUnlockViewController ()
  13. @end
  14. @implementation OfflineUnlockViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // Do any additional setup after loading the view.
  18. }
  19. - (void)didReceiveMemoryWarning {
  20. [super didReceiveMemoryWarning];
  21. // Dispose of any resources that can be recreated.
  22. }
  23. - (IBAction)OnUnlockClicked:(id)sender {
  24. NSString* user = self.edituser.text;
  25. NSString* password = self.editpass.text;
  26. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  27. if(user.length==0||password.length==0)
  28. {
  29. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error!" message:@"user or password can not be empty." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
  30. // // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  31. //
  32. //
  33. // //[[UILabel appearanceWhenContainedIn:UIAlertView.class, nil] setAppearanceFont:[UIFont boldSystemFontOfSize:10]];
  34. // [alert show];
  35. [RAUtils message_alert:@"Username or Password cannot be blank." title:@"Unlock offline" controller:self];
  36. // [RAUtils alert_view:@"Username or Password cannot be blank." title:@"Unlock offline"];
  37. return;
  38. }
  39. sqlite3* db = [iSalesDB get_db];
  40. int offline_user_exist=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"lower(username)='%@' and password='%@'",user.lowercaseString ,[AESCrypt encrypt:password password:@"usai"]]];
  41. [iSalesDB close_db:db];
  42. if(offline_user_exist>0)
  43. [self dismissViewControllerAnimated:YES completion:^{
  44. if(self.returnValue)
  45. self.returnValue(true);
  46. }];
  47. else
  48. {
  49. [RAUtils message_alert:MSG_USERAUTH_ERROR title:@"Unlock offline" controller:self];
  50. // [RAUtils alert_view:MSG_USERAUTH_ERROR title:@"Unlock offline"];
  51. }
  52. }
  53. - (IBAction)CloseClick:(id)sender {
  54. [self dismissViewControllerAnimated:true completion:nil];
  55. if(self.returnValue)
  56. self.returnValue(false);
  57. }
  58. /*
  59. #pragma mark - Navigation
  60. // In a storyboard-based application, you will often want to do a little preparation before navigation
  61. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  62. // Get the new view controller using [segue destinationViewController].
  63. // Pass the selected object to the new view controller.
  64. }
  65. */
  66. @end