import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import * as Parse from "parse"

@Component({
  selector: 'app-register',
  templateUrl: './register.page.html',
  styleUrls: ['./register.page.scss'],
})
export class RegisterPage implements OnInit {

  username:string | undefined
  email:string | undefined
  password:string | undefined

  constructor(private router: Router) { }

  ngOnInit() {
  }

  currentUser:any
  async saveRegister(){
    // this.currentUser = Parse.User.current()
    if(!this.username){
      return alert("用户名未填写")
    } else if(!this.password){
      return alert("密码未填写")
    }
    let user = Parse.Object.extend("_User")
    user = new user()
    user.set('mobile',this.username)
    user.set('username',this.username)
    user.set('email',this.email)
    user.set('password',this.password)
    try {
      await user.save()
      alert("保存成功")
      this.router.navigate(['/login']);
      console.log("保存成功");
    } catch (error){
      alert("保存失败")
      console.log("保存失败");
    }
  }

  gologin(){
    this.router.navigate(['/login']);
  }

}
