ModifyPwdViewController.m 4.06 KB
//
//  ModifyPwdViewController.m
//  CNLiveUserSystemDemo
//
//  Created by 张旭 on 2017/5/27.
//  Copyright © 2017年 zhulin. All rights reserved.
//

#import "ModifyPwdViewController.h"

@interface ModifyPwdViewController ()

@property (nonatomic ,strong) UITextField * _Nullable             emailTF;
@property (nonatomic ,strong) UITextField * _Nullable             pwdTF;
@property (nonatomic, strong) UIButton * _Nullable                confirmBtn;

@end

@implementation ModifyPwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.emailTF];
    [self.view addSubview:self.pwdTF];
    [self.view addSubview:self.confirmBtn];
}


- (void)confirmBtnAction
{
    if (self.type == ModifyPwdTypeEmail) {
        [CNLiveUserSystemCenter modifyPwdWithEmail:self.emailTF.text newPwd:self.pwdTF.text success:^(id result) {
            
            [Tools toast:result[@"errorMessage"]];
            
        } failure:^(NSDictionary *errorDic) {
            [Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
        }];
    
    }else if (self.type == ModifyPwdTypeOldPwd){
         UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
        [CNLiveUserSystemCenter oldPwdChangePasswordWithUid:model.uid pwd:self.emailTF.text newPwd:self.pwdTF.text success:^(id result) {
            
            [Tools toast:result[@"errorMessage"]];
        } failure:^(NSDictionary *errorDic) {
             [Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
        }];
        
    }
    
    
}

- (UIButton *)confirmBtn
{
    if (!_confirmBtn) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setFrame:CGRectMake(10, 280, KScreenWidth - 20, 40)];
        [_confirmBtn setTitle:@"确  认" forState:UIControlStateNormal];
        [_confirmBtn addTarget:self action:@selector(confirmBtnAction) forControlEvents:UIControlEventTouchUpInside];
        _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:18];
        [_confirmBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
        _confirmBtn.layer.cornerRadius = 20;
        _confirmBtn.layer.masksToBounds = YES;
        _confirmBtn.layer.borderColor = [UIColor blackColor].CGColor;
        _confirmBtn.layer.borderWidth = 1;
    }
    return _confirmBtn;
}

- (UITextField *)emailTF
{
    if (!_emailTF) {
        _emailTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 70, KScreenWidth - 20, 57)];
        if (self.type == ModifyPwdTypeEmail) {
            _emailTF.placeholder = @"请输入您的邮箱";
        }else if (self.type == ModifyPwdTypeOldPwd){
            _emailTF.placeholder = @"请输入您的旧密码";
        }
        _emailTF.keyboardType = UIKeyboardTypeNamePhonePad;
        _emailTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _emailTF.font = [UIFont systemFontOfSize:17];
    }
    return _emailTF;
}

- (UITextField *)pwdTF
{
    if (!_pwdTF) {
        _pwdTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 70 + 57, KScreenWidth - 20, 57)];
        _pwdTF.placeholder = @"请输入您的新密码";
        _pwdTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _pwdTF.keyboardType = UIKeyboardTypeNamePhonePad;
        _pwdTF.font = [UIFont systemFontOfSize:17];
    }
    return _pwdTF;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#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