OfflineUnlockViewController.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 alert_view:@"Username or Password cannot be blank." title:@"Unlock offline"];
  36. return;
  37. }
  38. sqlite3* db = [iSalesDB get_db];
  39. 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"]]];
  40. [iSalesDB close_db:db];
  41. if(offline_user_exist>0)
  42. [self dismissViewControllerAnimated:YES completion:^{
  43. if(self.returnValue)
  44. self.returnValue(true);
  45. }];
  46. else
  47. [RAUtils alert_view:MSG_USERAUTH_ERROR title:@"Unlock offline"];
  48. }
  49. - (IBAction)CloseClick:(id)sender {
  50. [self dismissViewControllerAnimated:true completion:nil];
  51. if(self.returnValue)
  52. self.returnValue(false);
  53. }
  54. /*
  55. #pragma mark - Navigation
  56. // In a storyboard-based application, you will often want to do a little preparation before navigation
  57. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  58. // Get the new view controller using [segue destinationViewController].
  59. // Pass the selected object to the new view controller.
  60. }
  61. */
  62. @end