Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "LoginView.h"
  2. #import "JsonPaser.h"
  3. #import "AFNetworking.h"
  4. #import "CustomerDetails.h"
  5. #import "CustomIOS7AlertView.h"
  6. #import "ServiceUrls.h"
  7. #import "SignUp.h"
  8. #import <IQKeyboardManager/IQKeyboardManager.h>
  9. @interface LoginView ()
  10.  
  11. @end
  12.  
  13. @implementation LoginView
  14.  
  15. /*static NSString* const BaseURLString = @"http://mobilepgnqa.paragonsoft.net/";
  16. static NSString* const Login_url = @"http://mobilepgnqa.paragonsoft.net/PgnMobileService.asmx/GiftCardCustomerLogin";
  17. static NSString* const notificationRegistrationUrl=@"http://mobilepgnqa.paragonsoft.net/PgnMobileService.asmx/NotificationReg";
  18.  
  19. static NSString* const BaseURLString = @"http://mobilepgnqa.paragonsoft.net/";
  20. static NSString* const Login_url = @"http://paragonsoft.us/PGNMobileService/PgnMobileService.asmx/GiftCardCustomerLogin";
  21.  
  22. static NSString* const notificationRegistrationUrl=@"http://paragonsoft.us/PGNMobileService/PgnMobileService.asmx/NotificationReg";
  23.  
  24. //static NSString* const notificationRegistrationUrl=@"http://mobilepgnqa.paragonsoft.net/PgnMobileService.asmx/NotificationReg"; */
  25.  
  26. NSString* hasError;
  27. UITextField *text;
  28.  
  29. NSString *str;
  30.  
  31.  
  32.  
  33.  
  34. - (void)viewDidLoad
  35. {
  36.    
  37.     [[[IQKeyboardManager sharedManager] enabledDistanceHandlingClasses] addObject:[self class]];
  38.    
  39.    
  40.     [super viewDidLoad];
  41.     [self fillBackground];
  42.     [self.email_text setDelegate:self];
  43.     [self.password_text setDelegate:self];
  44.    
  45.    
  46. // Do any additional setup after loading the view, typically from a nib.
  47.    
  48.     str = [NSString stringWithFormat: @"%@ %@", [ServiceUrls getBaseUrl], @"GiftCardCustomerLogin"];
  49.     self.navigationItem.hidesBackButton = YES;
  50. }
  51.  
  52. -(void)fillBackground{
  53.     UIGraphicsBeginImageContext(self.view.frame.size);
  54.     [[UIImage imageNamed:@"bg.png"] drawInRect:self.view.bounds];
  55.     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  56.     UIGraphicsEndImageContext();
  57.     self.view.backgroundColor = [UIColor colorWithPatternImage:image];
  58.    
  59.     self.LoginButton.backgroundColor = [self colorWithHexString:@"52160B"];
  60.     self.LoginButton.innerBevelColor = [self colorWithHexString:@"2A0C06"];
  61.     self.LoginButton.pressedWhenSelected = YES;
  62.     self.LoginButton.cornerRadius = 2.0;
  63. }
  64.  
  65. -(void)checkforcurentView{
  66.     UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
  67.    
  68.     if (orientation == UIInterfaceOrientationLandscapeLeft) {
  69.         NSLog(@"Landscape left check view");
  70.        
  71.         CGRect frame =CGRectMake(190,5,100,100);
  72.         CGRect frame2 =CGRectMake(102,100,280,169);
  73.         self.scroler.frame = CGRectMake(0, 0, 280, 460);
  74.         self.textAndbuttons.frame = frame2;
  75.         self.logoView.frame = frame;
  76.         self.logoView.center = self.view.center;
  77.        
  78.     } else if (orientation == UIInterfaceOrientationLandscapeRight) {
  79.         NSLog(@"Landscape right");
  80.        
  81.         CGRect frame =CGRectMake(190,5,100,100);
  82.         CGRect frame2 =CGRectMake(102,100,280,169);
  83.         self.textAndbuttons.frame = frame2;
  84.         self.logoView.frame = frame;
  85.  
  86.         //  self.lblInfo.text = @"Landscape right";
  87.     } else if (orientation == UIInterfaceOrientationPortrait) {
  88.         NSLog(@"Portrait");
  89.         CGRect frame = CGRectMake(80,30,160,149);
  90.         CGRect frame2 =CGRectMake(20,200,280,169);
  91.         self.logoView.frame = frame;
  92.         self.textAndbuttons.frame = frame2;
  93.        
  94.     } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
  95.         NSLog(@"Upside down");
  96.         //  self.lblInfo.text = @"Upside down";
  97.         CGRect frame = CGRectMake(80,30,160,149);
  98.         CGRect frame2 =CGRectMake(20,200,280,169);
  99.         self.logoView.frame = frame;
  100.         self.textAndbuttons.frame = frame2;
  101.     }
  102.  
  103. }
  104.  
  105. - (void)didReceiveMemoryWarning
  106. {
  107.     [super didReceiveMemoryWarning];
  108.     // Dispose of any resources that can be recreated.
  109. }
  110.  
  111. -(void)viewWillAppear:(BOOL)animated{
  112.     self.email_text.text = @"";
  113.     self.password_text.text=@"";
  114. }
  115.  
  116. -(IBAction)signUpAction:(id)sender
  117. {
  118.    
  119.     UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
  120.     SignUp *login = (SignUp *)[mainStoryboard instantiateViewControllerWithIdentifier:@"signUp"];
  121.     UINavigationController *navCtl = [[UINavigationController alloc] init];
  122.     self.window.rootViewController = navCtl;
  123.     [self.navigationController pushViewController:login animated:YES];
  124.    
  125.    
  126.     NSLog(@"navighation %@",self.navigationController);
  127.     self.window.rootViewController = self.nav;
  128.     NSLog(@"navighation %@",self.nav);
  129.     [self.nav pushViewController:login animated:YES];
  130.    
  131. }
  132.  
  133. -(IBAction)loginAction:(id)sender
  134. {
  135.     NSLog(@"loginAction Y Changes : %f",self.view.frame.origin.y);
  136.    
  137.     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
  138.     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  139.    
  140.     //indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
  141.     indicator.center = self.view.center;
  142.     [self.view addSubview:indicator];
  143.     [indicator bringSubviewToFront:self.view];
  144.     [UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
  145.     [indicator setHidden:NO];
  146.     [indicator startAnimating];
  147.     NSString* email = self.email_text.text;
  148.     NSString* password = self.password_text.text;
  149.     NSString* authKey = [CustomerDetails getAuthKey];
  150.     NSString* validationStatus =[self checkTextFields:email :password];
  151.     NSLog(@"%@",[CustomerDetails getAccountNumber]);
  152.     if(validationStatus==nil){
  153.         NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAndKeys:email, @"email",password,@"password",authKey,@"authkey",[CustomerDetails getAccountNumber],@"accountNumber", nil];
  154.        
  155.         JsonPaser *jp = [[JsonPaser alloc]init];
  156.         [jp getWebServiceResponce:[ServiceUrls getLoginUrl] :parameters success:^(NSDictionary *responseObject){
  157.             NSLog(@"LOGIN RESPONSE :%@" ,[responseObject description]);
  158.             hasError = [responseObject valueForKey:@"HasError"];
  159.            
  160.             if ([hasError boolValue] == 0) {
  161.                 //NSString* custId = [[responseObject objectForKey:@"Response"] valueForKey:@"CustomerId"];
  162.                 //NSString* fname = [[responseObject objectForKey:@"Response"] valueForKey:@"FirstName"];
  163.                 //NSString* lname = [[responseObject objectForKey:@"Response"] valueForKey:@"LastName"];
  164.                 //NSString* city = [[responseObject objectForKey:@"Response"] valueForKey:@"City"];
  165.                 [CustomerDetails setCustomerID:[[responseObject objectForKey:@"Response"] valueForKey:@"CustomerId"]];
  166.                 [CustomerDetails setCustomerFirstName:[[responseObject objectForKey:@"Response"] valueForKey:@"FirstName"]];
  167.                 [CustomerDetails setCustomerLastName:[[responseObject objectForKey:@"Response"] valueForKey:@"LastName"]];
  168.                 [CustomerDetails setCity:[[responseObject objectForKey:@"Response"] valueForKey:@"City"]];
  169.                 [CustomerDetails setStreet:[[responseObject objectForKey:@"Response"] valueForKey:@"Street"]];
  170.                 [CustomerDetails setstate:[[responseObject objectForKey:@"Response"] valueForKey:@"State"]];
  171.                 [CustomerDetails setZip:[[responseObject objectForKey:@"Response"] valueForKey:@"Zip"]];
  172.                 [CustomerDetails setPhone:[[responseObject objectForKey:@"Response"] valueForKey:@"Phone"]];
  173.                
  174.                 NSString* giftcard = [[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"PgnCardNo"];
  175.                
  176.                 NSString* serial = [[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"SerialNumber"];
  177.                
  178.                 //save user credentials along with customer id to later use
  179.                  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  180.                 if (![giftcard isEqual:[NSNull null]]) {
  181.                     [defaults setObject:serial forKey:@"serial"];
  182.                     [defaults setObject:giftcard forKey:@"cardNumber"];
  183.                 }
  184.                
  185.                 if([self.swich isOn]){
  186.                    
  187.                     [defaults setObject:email forKey:@"username"];
  188.                     [defaults setObject:password forKey:@"password"];
  189.                    
  190.                     [defaults setObject:[CustomerDetails getCustomerID] forKey:@"customerID"];
  191.                     [defaults synchronize];
  192.                 }else{
  193.                     [defaults setObject:[CustomerDetails getCustomerID] forKey:@"customerID"];
  194.                     [defaults synchronize];
  195.                 }
  196.                
  197.                
  198.                /*
  199.                 //send device token here
  200.                 NSDictionary *param = [[NSDictionary alloc] initWithObjectsAndKeys:@"2",@"phoneTypeId",[CustomerDetails getDeviceToken],@"registrationID",[CustomerDetails getCustomerID],@"customerId",authKey,@"authkey", nil];
  201.                
  202.                 [jp getWebServiceResponce:notificationRegistrationUrl :param success:^(NSDictionary *responseObject)
  203.                     {
  204.                       NSString* hasErr = [responseObject valueForKey:@"HasError"];
  205.                         NSLog(@"has error %@",hasErr);
  206.                         if (hasErr.boolValue == 0) {
  207.                             NSLog(@"DeviceToken successfully sent");
  208.                         }else{
  209.                              NSLog(@"DeviceToken faild to sent");
  210.                         }
  211.                    
  212.                     }];
  213.                
  214.                 */
  215.                
  216.                 if ([giftcard isEqual:[NSNull null]]) {
  217.                    
  218.                     [self performSegueWithIdentifier:@"login_to_buy_card" sender:sender];
  219.                    
  220.                 }else{
  221.                    // NSString* giftcardAmount = [[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"CardAmount"];
  222.                     [CustomerDetails setGiftCardNo:giftcard];
  223.                     [CustomerDetails setCardAmount:[[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"CardAmount"]];
  224.                    
  225.                     [defaults setObject:[[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"SerialNumber"] forKey:@"serial"];
  226.                     [self performSegueWithIdentifier:@"login_to_home" sender:sender];
  227.                 }
  228.                
  229.                
  230.             }else{
  231.                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not a Valid User"
  232.                                                                 message:@"Check your UserName or Password!"
  233.                                                                delegate:nil
  234.                                                       cancelButtonTitle:@"OK"
  235.                                                       otherButtonTitles:nil];
  236.                 [alert show];
  237.             }
  238.            
  239.         }];
  240.     }
  241.     else{
  242.         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not a Valid User"
  243.                                                         message:validationStatus
  244.                                                        delegate:nil
  245.                                               cancelButtonTitle:@"OK"
  246.                                               otherButtonTitles:nil];
  247.         [alert show];
  248.     }
  249.    
  250.    
  251.     [indicator stopAnimating];
  252.     [UIApplication sharedApplication].networkActivityIndicatorVisible = FALSE;
  253.    // [self.indicator stopAnimating];
  254.    
  255. }
  256.  
  257. -(IBAction)forgetPassword:(id)sender{
  258.    
  259.     // Here we need to pass a full frame
  260.     CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
  261.    
  262.     // Add some custom content to the alert view
  263.     [alertView setContainerView:[self createDemoView]];
  264.    
  265.     // Modify the parameters
  266.     [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", @"Cancel", nil]];
  267.     [alertView setDelegate:self];
  268.    
  269.     // You may use a Block, rather than a delegate.
  270.     [alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex)
  271.     {
  272.         if(buttonIndex==0){
  273.             NSLog(@"ok");
  274.             NSString* emailTosent = text.text;
  275.             NSDictionary *param = [[NSDictionary alloc] initWithObjectsAndKeys:[CustomerDetails getAuthKey],@"authkey",[CustomerDetails getAccountNumber],@"accountNumber",emailTosent,@"email", nil];
  276.             JsonPaser* jps = [[JsonPaser alloc]init];
  277.             [jps getWebServiceResponce:[ServiceUrls getforgrtPwdUrl] :param success:^(NSDictionary *responseObject)
  278.              {
  279.                  NSString* responces = [responseObject valueForKey:@"HasError"];
  280.                  NSLog(@"has %@",responces);
  281.                  
  282.                  NSLog(@"ResponceType %@",[responseObject description]);
  283.                  if ([responces boolValue]== 0) {
  284.                      
  285.                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email Sent"
  286.                                                                      message:@"You may recive an email soon"
  287.                                                                     delegate:nil
  288.                                                            cancelButtonTitle:@"OK"
  289.                                                            otherButtonTitles:nil];
  290.                      [alert show];
  291.                  }else{
  292.                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email Not Sent"
  293.                                                                     message:@"check your Email again"
  294.                                                                    delegate:nil
  295.                                                           cancelButtonTitle:@"OK"
  296.                                                           otherButtonTitles:nil];
  297.                      [alert show];
  298.                  }
  299.                  
  300.              }];
  301.  
  302.         }
  303.    
  304.     }];
  305.    
  306.     [alertView setUseMotionEffects:true];
  307.    
  308.     // And launch the dialog
  309.     [alertView show];
  310.  
  311. }
  312.  
  313. -(UIView*)createDemoView{
  314.    
  315.     // CustomIOS7AlertView* alertView = [[CustomIOS7AlertView alloc] init];
  316.     UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 100)];
  317.    
  318.     //alertView.tag=2;
  319.    
  320.     UILabel *helpText=[[UILabel alloc]initWithFrame:CGRectMake(10, 25, 290, 45)];
  321.     helpText.backgroundColor=[UIColor clearColor];
  322.     helpText.font=[UIFont boldSystemFontOfSize:12];
  323.     helpText.text=@"Enter your email address to reset your password";
  324.    
  325.     UILabel *emaillbl=[[UILabel alloc]initWithFrame:CGRectMake(10, 57, 290, 45)];
  326.     emaillbl.backgroundColor=[UIColor clearColor];
  327.     emaillbl.font=[UIFont boldSystemFontOfSize:15];
  328.     emaillbl.text=@"Email";
  329.    
  330.     UILabel *lblAlertTItle=[[UILabel alloc]initWithFrame:CGRectMake(5, 5, 290, 45)];
  331.     lblAlertTItle.backgroundColor=[UIColor clearColor];
  332.     lblAlertTItle.textAlignment= NSTextAlignmentCenter;
  333.     lblAlertTItle.font=[UIFont boldSystemFontOfSize:18];
  334.     lblAlertTItle.text=@"Reset Your Password";
  335.    
  336.    
  337.     text = [[UITextField alloc]initWithFrame:CGRectMake(100, 65, 170, 25)];
  338.     text.backgroundColor=[UIColor whiteColor];
  339.     [text setKeyboardType:UIKeyboardTypeEmailAddress];
  340.     [demoView addSubview:lblAlertTItle];
  341.     [demoView addSubview:text];
  342.     [demoView addSubview:helpText];
  343.     [demoView addSubview:emaillbl];
  344.    
  345.    
  346.     return demoView;
  347.  
  348. }
  349.  
  350. - (void)customIOS7dialogButtonTouchUpInside: (CustomIOS7AlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
  351. {
  352.     NSLog(@"Delegate: Button at position %ld is clicked on alertView %ld.", (long)buttonIndex, (long)[alertView tag]);
  353.     [alertView close];
  354. }
  355.  
  356. -(NSString*)checkTextFields:(NSString*)user :(NSString*) password {
  357.     NSString* message;
  358.     if (user.length==0) {
  359.         message = @"user Name is empty";
  360.        
  361.     }
  362.     else if (password.length==0) {
  363.         message = @"password is empty";
  364.        
  365.     }
  366.     return message;
  367. }
  368.  
  369.  
  370. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  371. {
  372.     [textField resignFirstResponder];
  373.     return YES;
  374. }
  375.  
  376.  
  377.  
  378. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement