Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "LoginView.h"
- #import "JsonPaser.h"
- #import "AFNetworking.h"
- #import "CustomerDetails.h"
- #import "CustomIOS7AlertView.h"
- #import "ServiceUrls.h"
- #import "SignUp.h"
- #import <IQKeyboardManager/IQKeyboardManager.h>
- @interface LoginView ()
- @end
- @implementation LoginView
- /*static NSString* const BaseURLString = @"http://mobilepgnqa.paragonsoft.net/";
- static NSString* const Login_url = @"http://mobilepgnqa.paragonsoft.net/PgnMobileService.asmx/GiftCardCustomerLogin";
- static NSString* const notificationRegistrationUrl=@"http://mobilepgnqa.paragonsoft.net/PgnMobileService.asmx/NotificationReg";
- static NSString* const BaseURLString = @"http://mobilepgnqa.paragonsoft.net/";
- static NSString* const Login_url = @"http://paragonsoft.us/PGNMobileService/PgnMobileService.asmx/GiftCardCustomerLogin";
- static NSString* const notificationRegistrationUrl=@"http://paragonsoft.us/PGNMobileService/PgnMobileService.asmx/NotificationReg";
- //static NSString* const notificationRegistrationUrl=@"http://mobilepgnqa.paragonsoft.net/PgnMobileService.asmx/NotificationReg"; */
- NSString* hasError;
- UITextField *text;
- NSString *str;
- - (void)viewDidLoad
- {
- [[[IQKeyboardManager sharedManager] enabledDistanceHandlingClasses] addObject:[self class]];
- [super viewDidLoad];
- [self fillBackground];
- [self.email_text setDelegate:self];
- [self.password_text setDelegate:self];
- // Do any additional setup after loading the view, typically from a nib.
- str = [NSString stringWithFormat: @"%@ %@", [ServiceUrls getBaseUrl], @"GiftCardCustomerLogin"];
- self.navigationItem.hidesBackButton = YES;
- }
- -(void)fillBackground{
- UIGraphicsBeginImageContext(self.view.frame.size);
- [[UIImage imageNamed:@"bg.png"] drawInRect:self.view.bounds];
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- self.view.backgroundColor = [UIColor colorWithPatternImage:image];
- self.LoginButton.backgroundColor = [self colorWithHexString:@"52160B"];
- self.LoginButton.innerBevelColor = [self colorWithHexString:@"2A0C06"];
- self.LoginButton.pressedWhenSelected = YES;
- self.LoginButton.cornerRadius = 2.0;
- }
- -(void)checkforcurentView{
- UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
- if (orientation == UIInterfaceOrientationLandscapeLeft) {
- NSLog(@"Landscape left check view");
- CGRect frame =CGRectMake(190,5,100,100);
- CGRect frame2 =CGRectMake(102,100,280,169);
- self.scroler.frame = CGRectMake(0, 0, 280, 460);
- self.textAndbuttons.frame = frame2;
- self.logoView.frame = frame;
- self.logoView.center = self.view.center;
- } else if (orientation == UIInterfaceOrientationLandscapeRight) {
- NSLog(@"Landscape right");
- CGRect frame =CGRectMake(190,5,100,100);
- CGRect frame2 =CGRectMake(102,100,280,169);
- self.textAndbuttons.frame = frame2;
- self.logoView.frame = frame;
- // self.lblInfo.text = @"Landscape right";
- } else if (orientation == UIInterfaceOrientationPortrait) {
- NSLog(@"Portrait");
- CGRect frame = CGRectMake(80,30,160,149);
- CGRect frame2 =CGRectMake(20,200,280,169);
- self.logoView.frame = frame;
- self.textAndbuttons.frame = frame2;
- } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
- NSLog(@"Upside down");
- // self.lblInfo.text = @"Upside down";
- CGRect frame = CGRectMake(80,30,160,149);
- CGRect frame2 =CGRectMake(20,200,280,169);
- self.logoView.frame = frame;
- self.textAndbuttons.frame = frame2;
- }
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)viewWillAppear:(BOOL)animated{
- self.email_text.text = @"";
- self.password_text.text=@"";
- }
- -(IBAction)signUpAction:(id)sender
- {
- UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
- SignUp *login = (SignUp *)[mainStoryboard instantiateViewControllerWithIdentifier:@"signUp"];
- UINavigationController *navCtl = [[UINavigationController alloc] init];
- self.window.rootViewController = navCtl;
- [self.navigationController pushViewController:login animated:YES];
- NSLog(@"navighation %@",self.navigationController);
- self.window.rootViewController = self.nav;
- NSLog(@"navighation %@",self.nav);
- [self.nav pushViewController:login animated:YES];
- }
- -(IBAction)loginAction:(id)sender
- {
- NSLog(@"loginAction Y Changes : %f",self.view.frame.origin.y);
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
- UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
- //indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
- indicator.center = self.view.center;
- [self.view addSubview:indicator];
- [indicator bringSubviewToFront:self.view];
- [UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
- [indicator setHidden:NO];
- [indicator startAnimating];
- NSString* email = self.email_text.text;
- NSString* password = self.password_text.text;
- NSString* authKey = [CustomerDetails getAuthKey];
- NSString* validationStatus =[self checkTextFields:email :password];
- NSLog(@"%@",[CustomerDetails getAccountNumber]);
- if(validationStatus==nil){
- NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAndKeys:email, @"email",password,@"password",authKey,@"authkey",[CustomerDetails getAccountNumber],@"accountNumber", nil];
- JsonPaser *jp = [[JsonPaser alloc]init];
- [jp getWebServiceResponce:[ServiceUrls getLoginUrl] :parameters success:^(NSDictionary *responseObject){
- NSLog(@"LOGIN RESPONSE :%@" ,[responseObject description]);
- hasError = [responseObject valueForKey:@"HasError"];
- if ([hasError boolValue] == 0) {
- //NSString* custId = [[responseObject objectForKey:@"Response"] valueForKey:@"CustomerId"];
- //NSString* fname = [[responseObject objectForKey:@"Response"] valueForKey:@"FirstName"];
- //NSString* lname = [[responseObject objectForKey:@"Response"] valueForKey:@"LastName"];
- //NSString* city = [[responseObject objectForKey:@"Response"] valueForKey:@"City"];
- [CustomerDetails setCustomerID:[[responseObject objectForKey:@"Response"] valueForKey:@"CustomerId"]];
- [CustomerDetails setCustomerFirstName:[[responseObject objectForKey:@"Response"] valueForKey:@"FirstName"]];
- [CustomerDetails setCustomerLastName:[[responseObject objectForKey:@"Response"] valueForKey:@"LastName"]];
- [CustomerDetails setCity:[[responseObject objectForKey:@"Response"] valueForKey:@"City"]];
- [CustomerDetails setStreet:[[responseObject objectForKey:@"Response"] valueForKey:@"Street"]];
- [CustomerDetails setstate:[[responseObject objectForKey:@"Response"] valueForKey:@"State"]];
- [CustomerDetails setZip:[[responseObject objectForKey:@"Response"] valueForKey:@"Zip"]];
- [CustomerDetails setPhone:[[responseObject objectForKey:@"Response"] valueForKey:@"Phone"]];
- NSString* giftcard = [[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"PgnCardNo"];
- NSString* serial = [[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"SerialNumber"];
- //save user credentials along with customer id to later use
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- if (![giftcard isEqual:[NSNull null]]) {
- [defaults setObject:serial forKey:@"serial"];
- [defaults setObject:giftcard forKey:@"cardNumber"];
- }
- if([self.swich isOn]){
- [defaults setObject:email forKey:@"username"];
- [defaults setObject:password forKey:@"password"];
- [defaults setObject:[CustomerDetails getCustomerID] forKey:@"customerID"];
- [defaults synchronize];
- }else{
- [defaults setObject:[CustomerDetails getCustomerID] forKey:@"customerID"];
- [defaults synchronize];
- }
- /*
- //send device token here
- NSDictionary *param = [[NSDictionary alloc] initWithObjectsAndKeys:@"2",@"phoneTypeId",[CustomerDetails getDeviceToken],@"registrationID",[CustomerDetails getCustomerID],@"customerId",authKey,@"authkey", nil];
- [jp getWebServiceResponce:notificationRegistrationUrl :param success:^(NSDictionary *responseObject)
- {
- NSString* hasErr = [responseObject valueForKey:@"HasError"];
- NSLog(@"has error %@",hasErr);
- if (hasErr.boolValue == 0) {
- NSLog(@"DeviceToken successfully sent");
- }else{
- NSLog(@"DeviceToken faild to sent");
- }
- }];
- */
- if ([giftcard isEqual:[NSNull null]]) {
- [self performSegueWithIdentifier:@"login_to_buy_card" sender:sender];
- }else{
- // NSString* giftcardAmount = [[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"CardAmount"];
- [CustomerDetails setGiftCardNo:giftcard];
- [CustomerDetails setCardAmount:[[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"CardAmount"]];
- [defaults setObject:[[[responseObject objectForKey:@"Response"] objectForKey:@"GiftCard"] valueForKey:@"SerialNumber"] forKey:@"serial"];
- [self performSegueWithIdentifier:@"login_to_home" sender:sender];
- }
- }else{
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not a Valid User"
- message:@"Check your UserName or Password!"
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [alert show];
- }
- }];
- }
- else{
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not a Valid User"
- message:validationStatus
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [alert show];
- }
- [indicator stopAnimating];
- [UIApplication sharedApplication].networkActivityIndicatorVisible = FALSE;
- // [self.indicator stopAnimating];
- }
- -(IBAction)forgetPassword:(id)sender{
- // Here we need to pass a full frame
- CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
- // Add some custom content to the alert view
- [alertView setContainerView:[self createDemoView]];
- // Modify the parameters
- [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", @"Cancel", nil]];
- [alertView setDelegate:self];
- // You may use a Block, rather than a delegate.
- [alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex)
- {
- if(buttonIndex==0){
- NSLog(@"ok");
- NSString* emailTosent = text.text;
- NSDictionary *param = [[NSDictionary alloc] initWithObjectsAndKeys:[CustomerDetails getAuthKey],@"authkey",[CustomerDetails getAccountNumber],@"accountNumber",emailTosent,@"email", nil];
- JsonPaser* jps = [[JsonPaser alloc]init];
- [jps getWebServiceResponce:[ServiceUrls getforgrtPwdUrl] :param success:^(NSDictionary *responseObject)
- {
- NSString* responces = [responseObject valueForKey:@"HasError"];
- NSLog(@"has %@",responces);
- NSLog(@"ResponceType %@",[responseObject description]);
- if ([responces boolValue]== 0) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email Sent"
- message:@"You may recive an email soon"
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [alert show];
- }else{
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email Not Sent"
- message:@"check your Email again"
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [alert show];
- }
- }];
- }
- }];
- [alertView setUseMotionEffects:true];
- // And launch the dialog
- [alertView show];
- }
- -(UIView*)createDemoView{
- // CustomIOS7AlertView* alertView = [[CustomIOS7AlertView alloc] init];
- UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 100)];
- //alertView.tag=2;
- UILabel *helpText=[[UILabel alloc]initWithFrame:CGRectMake(10, 25, 290, 45)];
- helpText.backgroundColor=[UIColor clearColor];
- helpText.font=[UIFont boldSystemFontOfSize:12];
- helpText.text=@"Enter your email address to reset your password";
- UILabel *emaillbl=[[UILabel alloc]initWithFrame:CGRectMake(10, 57, 290, 45)];
- emaillbl.backgroundColor=[UIColor clearColor];
- emaillbl.font=[UIFont boldSystemFontOfSize:15];
- emaillbl.text=@"Email";
- UILabel *lblAlertTItle=[[UILabel alloc]initWithFrame:CGRectMake(5, 5, 290, 45)];
- lblAlertTItle.backgroundColor=[UIColor clearColor];
- lblAlertTItle.textAlignment= NSTextAlignmentCenter;
- lblAlertTItle.font=[UIFont boldSystemFontOfSize:18];
- lblAlertTItle.text=@"Reset Your Password";
- text = [[UITextField alloc]initWithFrame:CGRectMake(100, 65, 170, 25)];
- text.backgroundColor=[UIColor whiteColor];
- [text setKeyboardType:UIKeyboardTypeEmailAddress];
- [demoView addSubview:lblAlertTItle];
- [demoView addSubview:text];
- [demoView addSubview:helpText];
- [demoView addSubview:emaillbl];
- return demoView;
- }
- - (void)customIOS7dialogButtonTouchUpInside: (CustomIOS7AlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
- {
- NSLog(@"Delegate: Button at position %ld is clicked on alertView %ld.", (long)buttonIndex, (long)[alertView tag]);
- [alertView close];
- }
- -(NSString*)checkTextFields:(NSString*)user :(NSString*) password {
- NSString* message;
- if (user.length==0) {
- message = @"user Name is empty";
- }
- else if (password.length==0) {
- message = @"password is empty";
- }
- return message;
- }
- -(BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [textField resignFirstResponder];
- return YES;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement