You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
60 lines
1.6 KiB
import { Component } from '@angular/core';
|
|
import { getEmail } from '../Helper/Helpers';
|
|
import { NgIf } from '@angular/common';
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
@Component({
|
|
selector: 'app-add-student',
|
|
imports: [NgIf, FormsModule],
|
|
templateUrl: './add-student.component.html',
|
|
styleUrl: './add-student.component.css'
|
|
})
|
|
export class AddStudentComponent {
|
|
Uname: string = '';
|
|
email: string = '';
|
|
password: string = '';
|
|
confirmPassword: string = '';
|
|
showPass: boolean = false;
|
|
|
|
ShowPassword() {
|
|
this.showPass = !this.showPass
|
|
}
|
|
|
|
// add a student to the database
|
|
async AddStudent() {
|
|
const Aemail = getEmail();
|
|
|
|
// password protection
|
|
if (this.password.length < 10 || this.password == "") {
|
|
alert("password must be at least 10 characters");
|
|
return;
|
|
}
|
|
else if(this.email == Aemail){
|
|
alert("Funny guy, eh?");
|
|
return;
|
|
}
|
|
|
|
if (this.password == this.confirmPassword) { // passwords match
|
|
const data = {name: this.Uname, email: this.email, Aemail: Aemail, password: this.password};
|
|
const res = await fetch('api/users/AddStudent', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type' : 'application/json'
|
|
},
|
|
body: JSON.stringify(data)
|
|
});
|
|
if (res.ok) {
|
|
console.log("Success: adding student");
|
|
window.opener.location.reload();
|
|
window.close();
|
|
}
|
|
else {
|
|
console.log("ERROR: adding student");
|
|
}
|
|
}
|
|
else {
|
|
alert("Passowrds do not match");
|
|
}
|
|
}
|
|
}
|