Ionic 4 WordPress REST用户验证Stuc

时间:2019-07-04 13:34:56

标签: ionic-framework ionic4

我正在尝试通过WP REST Api上开发人员的引导框架进行身份验证。附件是移动应用程序登录页面上的代码,每当我尝试登录时,它将停留在“正在加载,请稍候”。任何想法?提前致谢。单击登录按钮时显示doLogin()函数。 login.ts

doLogin() {
    this.translateService.get(['Notice', 'Loading', 'NetWork_Error', 'OK', 'Sign_In_Failed', 'Sign_In_No_Email', 'Sign_In_Email_Error', 'No_Email_Or_Password']).
    subscribe(async value => {
      var loadingModal = await this.loadingCtrl.create({
        message: value['Loading']
      });
      if (this.appConfig.Enable_Login_With_Password) {
        if (this.email == null || this.password == null || this.email.trim().length == 0 || this.password.trim().length < 6) {
          var alert=await this.alertCtrl.create({
            header: value['Notice'],
            message: value['No_Email_Or_Password'],
            buttons: [value['OK']]
          });
          alert.present();
          return;
        }

        loadingModal.present();

        var password = this.password;
        if (this.appConfig.App_Secret != '') {
          var key = CryptoJS.enc.Utf8.parse(CryptoJS.MD5(this.appConfig.App_Secret).toString());
          var iv = CryptoJS.enc.Utf8.parse(CryptoJS.MD5(this.appConfig.App_Secret).toString().substr(0, 16));
          password = CryptoJS.AES.encrypt(password, key, { iv: iv }).toString();
        }

        this.sowService.login({ email: this.email, password: encodeURIComponent(password) }).then(async (data: any) => {
          if (data && data != 'error') {
            this.userService.id = data.id;
            this.userService.email = data.email;
            this.userService.first_name = data.first_name;
            this.userService.last_name = data.last_name;
            this.userService.name = data.first_name + data.last_name;
            this.userService.username = data.username;
            this.userService.isAuthenticated = true;

            await this.storage.set('oddwolves-user-info', data);
            loadingModal.dismiss();
            this.modalCtrl.dismiss();

          } else {
            loadingModal.dismiss();
            var alert=await this.alertCtrl.create({
                 header: value['Notice'],
                 message: value['Sign_In_Failed'],
                 buttons: [value['OK']]
             });
            alert.present();

          }
        }, (reson) => {

         loadingModal.dismiss();
        });
      }
      else {
        if (this.email == null || this.email.trim().length == 0) {
          var alert=await this.alertCtrl.create({
            header: value['Notice'],
            message: value['Sign_In_No_Email'],
            buttons: [value['OK']]
          });
          alert.present();
          return;
        }
        loadingModal.present();
        this.wooService.getCustomerByEmail({ email: this.email }).then(async (data: Array<any>) => {
          if (data.length > 0 && data[0] && data[0].id > 0) {
            this.userService.id = data[0].id;
            this.userService.email = data[0].email;
            this.userService.first_name = data[0].first_name;
            this.userService.last_name = data[0].last_name;
            this.userService.name = data[0].first_name + data[0].last_name;
            this.userService.username = data[0].username;
            this.userService.isAuthenticated = true;

             loadingModal.dismiss();
             this.modalCtrl.dismiss();

          } else {
            loadingModal.dismiss();
            var alert=await this.alertCtrl.create({
              header: value['Notice'],
              message: value['Sign_In_Email_Error'],
              buttons: [value['OK']]
            });
            alert.present();
          }
        }, (reson) => {
          loadingModal.dismiss();
        });
      }
    });

  }

enter image description here

0 个答案:

没有答案