项目中 登录注册逻辑判断

来源:互联网 发布:淘宝数据分析网站 编辑:程序博客网 时间:2024/06/06 19:53

在项目中用的 是三方服务器。做的demo 短信验证 。记录逻辑实现 比较简单 在button的点击事件中进行判断




- (void)buttonAction:(UIButton *)buttonAction {

    /**
     *  首先 进入注册后 . 进入后台服务器 查找用户名信息是否含有 如果有提示 : 已注册过可直接登录 直接return 返回结束事件
     *  其次 没有注册过 . sdk 发送短信验证 没上线登记 每日限20条 。如果发送成功 跳转到下级页面 进行验证 成功后模态回个人界面
     *  手机 格式不对     提示 手机格式不正确
     */
    BmobQuery *bquery = [BmobQuery queryWithClassName:@"_User"];
    // 表的数据
    [bquery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        for (BmobObject *obj in array) {
            //打印Name
//            NSLog(@"obj.playerName = %@", [obj objectForKey:@"username"]);
            // 老用户
            if ([[obj objectForKey:@"username"] isEqualToString:_userName.text]) {
                UIAlertController *hyAlert = [UIAlertController alertControllerWithTitle:@"提示" message:@"该账户注册过,可直接登录" preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *alertAc = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    // 方法回调
                }];
                [hyAlert addAction:alertAc];
                [self presentViewController:hyAlert animated:YES completion:nil];
                return;
            }
        }
        // 新用户
        /**
         *  @from                    v1.1.1
         *  @brief                   获取验证码(Get verification code)
         *
         *  @param method            获取验证码的方法(The method of getting verificationCode)
         *  @param phoneNumber       电话号码(The phone number)
         *  @param zone              区域号,不要加"+"号(Area code)
         *  @param customIdentifier  自定义短信模板标识 该标识需从官网http://www.mob.com上申请,审核通过后获得。(Custom model of SMS.  The identifier can get it  from http://www.mob.com  when the application had approved)
         *  @param result            请求结果回调(Results of the request)
         */
        [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:_userName.text zone:@"86" customIdentifier:nil result:^(NSError *error){
            if (!error) {
                NSLog(@"获取验证码成功");
                MessageViewController *vc = [MessageViewController new];
                vc.string = _userName.text;
                [self.navigationController pushViewController:vc animated:YES];
                // 在手机号正确的前提下 bmob 中插入一条数据  插入用户名密码进来.
                BmobObject *userScore = [BmobObject objectWithoutDatatWithClassName:@"_User" objectId:_userName.text];
                [userScore setObject:_userName.text forKey:@"username"];
                [userScore setObject:_passWord.text forKey:@"password"];
                [userScore saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
                    //进行操作
                }];
                
            } else {
                NSLog(@"错误信息:%@",error);
                UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输正确手机号" preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    // 方法回调
                }];
                [errorAlert addAction:alertAction];
                [self presentViewController:errorAlert animated:YES completion:nil];
            }
        }];


    }];
}
0 0
原创粉丝点击