First try
This commit is contained in:
@@ -9,10 +9,10 @@ import { AuthenticationService } from "../../services/authentication.service";
|
||||
import { User } from "../../models/user";
|
||||
|
||||
@Component({
|
||||
selector: "app-create-user",
|
||||
templateUrl: "./create-user.component.html",
|
||||
styleUrls: ["./create-user.component.css"],
|
||||
standalone: false
|
||||
selector: "app-create-user",
|
||||
templateUrl: "./create-user.component.html",
|
||||
styleUrls: ["./create-user.component.css"],
|
||||
standalone: false,
|
||||
})
|
||||
export class CreateUserComponent implements OnInit {
|
||||
createForm: FormGroup;
|
||||
@@ -21,11 +21,13 @@ export class CreateUserComponent implements OnInit {
|
||||
returnUrl: string;
|
||||
error = "";
|
||||
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private authenticationService: AuthenticationService,
|
||||
private translateService: TranslateService) {
|
||||
constructor(
|
||||
private formBuilder: FormBuilder,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private authenticationService: AuthenticationService,
|
||||
private translateService: TranslateService
|
||||
) {
|
||||
// redirect to home if already logged in
|
||||
if (this.authenticationService.currentUserValue) {
|
||||
this.router.navigate(["/"]);
|
||||
@@ -38,11 +40,16 @@ export class CreateUserComponent implements OnInit {
|
||||
username: ["", [Validators.required, Validators.minLength(3)]],
|
||||
password: [
|
||||
"",
|
||||
[Validators.required, Validators.pattern("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[@$!%*#?&\-_|]).{8,}$")]
|
||||
[
|
||||
Validators.required,
|
||||
Validators.pattern(
|
||||
"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[@$!%*#?&-_|]).{8,}$"
|
||||
),
|
||||
],
|
||||
],
|
||||
firstname: ["", [Validators.required, Validators.minLength(3)]],
|
||||
lastname: ["", [Validators.required, Validators.minLength(3)]],
|
||||
email: ["", [Validators.required, Validators.email]]
|
||||
email: ["", [Validators.required, Validators.email]],
|
||||
},
|
||||
{ updateOn: "blur" }
|
||||
);
|
||||
@@ -65,23 +72,24 @@ export class CreateUserComponent implements OnInit {
|
||||
}
|
||||
|
||||
let createUser = new User();
|
||||
createUser.login = this.formCtrls.username.value;
|
||||
createUser.password = this.formCtrls.password.value;
|
||||
createUser.firstName = this.formCtrls.firstname.value;
|
||||
createUser.lastName = this.formCtrls.lastname.value;
|
||||
createUser.email = this.formCtrls.email.value;
|
||||
createUser.login = this.formCtrls["username"].value;
|
||||
createUser.password = this.formCtrls["password"].value;
|
||||
createUser.firstName = this.formCtrls["firstname"].value;
|
||||
createUser.lastName = this.formCtrls["lastname"].value;
|
||||
createUser.email = this.formCtrls["email"].value;
|
||||
createUser.language = this.translateService.currentLang;
|
||||
|
||||
this.authenticationService.create(createUser)
|
||||
.pipe(first())
|
||||
.subscribe(
|
||||
data => {
|
||||
this.router.navigate([this.returnUrl]);
|
||||
},
|
||||
error => {
|
||||
this.error = error;
|
||||
this.invalidForm = false;
|
||||
}
|
||||
);
|
||||
this.authenticationService
|
||||
.create(createUser)
|
||||
.pipe(first())
|
||||
.subscribe(
|
||||
(data) => {
|
||||
this.router.navigate([this.returnUrl]);
|
||||
},
|
||||
(error) => {
|
||||
this.error = error;
|
||||
this.invalidForm = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user