//
//  RetrievePassViewController.m
//  RedAnt ERP Mobile
//
//  Created by Ray on 9/10/15.
//  Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
//

#import "RetrievePassViewController.h"
#import "iSalesNetwork.h"
@interface RetrievePassViewController ()

@end

@implementation RetrievePassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
    // Dispose of any resources that can be recreated.
}
- (IBAction)onRetrieveClicked:(id)sender {
    NSString* user = self.editUser.text;
    NSString* email = self.editEmail.text;
    
    if(user.length==0||email.length==0)
    {
//        UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error!" message:@"user or email can not be empty." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
//        //        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
//        
//        
//        //[[UILabel appearanceWhenContainedIn:UIAlertView.class, nil] setAppearanceFont:[UIFont boldSystemFontOfSize:10]];
//        [alert show];
        
        
        [RAUtils alert_view:@"User or email cannot be empty." title:@"Input Error!"];
        return;
    }
    
    
    
    self.buttonRetrieve.enabled = false;
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        
        NSDictionary* json=[iSalesNetwork  retrieve_password:user email:email];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            self.buttonRetrieve.enabled = true;
            
            if([[json valueForKey:@"result"] intValue]==2)
            {
                
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Successful!" message:@"Please Check email later." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
             [alert show];
                
            }
            else
            {
                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Retrieve Password" controller:self] ;
            }
            
        });
    });
    

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
