|
@@ -0,0 +1,65 @@
|
|
|
+import { Component } from '@angular/core';
|
|
|
+import { AlertController, ModalController, IonicModule } from '@ionic/angular';
|
|
|
+import { CloudUser } from 'src/lib/ncloud';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-modal-user-register',
|
|
|
+ standalone: true,
|
|
|
+ templateUrl: './modal-user-register.component.html',
|
|
|
+ styleUrls: ['./modal-user-register.component.scss'],
|
|
|
+ imports: [
|
|
|
+ CommonModule,
|
|
|
+ FormsModule,
|
|
|
+ IonicModule
|
|
|
+ ]
|
|
|
+})
|
|
|
+export class ModalUserRegisterComponent {
|
|
|
+ username = '';
|
|
|
+ password = '';
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private modalCtrl: ModalController,
|
|
|
+ private alertCtrl: AlertController
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ async register() {
|
|
|
+ if (!this.username || !this.password) {
|
|
|
+ const alert = await this.alertCtrl.create({
|
|
|
+ header: '错误',
|
|
|
+ message: '请输入用户名和密码',
|
|
|
+ buttons: ['确定']
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const user: any = new CloudUser();
|
|
|
+ user.set('username', this.username);
|
|
|
+ user.set('password', this.password);
|
|
|
+ const signedUpUser = await user.signUp();
|
|
|
+
|
|
|
+ const alert = await this.alertCtrl.create({
|
|
|
+ header: '注册成功',
|
|
|
+ message: '欢迎你!',
|
|
|
+ buttons: ['确定']
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+
|
|
|
+ this.modalCtrl.dismiss({ user: signedUpUser }, 'success');
|
|
|
+ } catch (error: any) {
|
|
|
+ const alert = await this.alertCtrl.create({
|
|
|
+ header: '注册失败',
|
|
|
+ message: error.message || '注册过程中发生错误',
|
|
|
+ buttons: ['确定']
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ close() {
|
|
|
+ this.modalCtrl.dismiss(null, 'cancel');
|
|
|
+ }
|
|
|
+}
|