OfflineUnlockViewController.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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:YES completion:^{
  55. if(self.returnValue)
  56. self.returnValue(false);
  57. }];
  58. }
  59. /*
  60. #pragma mark - Navigation
  61. // In a storyboard-based application, you will often want to do a little preparation before navigation
  62. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  63. // Get the new view controller using [segue destinationViewController].
  64. // Pass the selected object to the new view controller.
  65. }
  66. */
  67. @end