67 lines
1.4 KiB
TypeScript
67 lines
1.4 KiB
TypeScript
export interface LoginFormData {
|
|
email: string;
|
|
password: string;
|
|
}
|
|
|
|
export interface LoginValidationErrors {
|
|
email?: string;
|
|
password?: string;
|
|
}
|
|
|
|
/**
|
|
* LoginCommandModel
|
|
*
|
|
* Encapsulates login form state, client-side validation, and
|
|
* prepares data for submission to the AuthService.
|
|
*/
|
|
export class LoginCommandModel {
|
|
private _email: string;
|
|
private _password: string;
|
|
|
|
constructor(initial: LoginFormData = { email: '', password: '' }) {
|
|
this._email = initial.email;
|
|
this._password = initial.password;
|
|
}
|
|
|
|
get email(): string {
|
|
return this._email;
|
|
}
|
|
|
|
set email(value: string) {
|
|
this._email = value;
|
|
}
|
|
|
|
get password(): string {
|
|
return this._password;
|
|
}
|
|
|
|
set password(value: string) {
|
|
this._password = value;
|
|
}
|
|
|
|
/** Basic client-side validation for login form */
|
|
validate(): LoginValidationErrors {
|
|
const errors: LoginValidationErrors = {};
|
|
|
|
if (!this._email.trim()) {
|
|
errors.email = 'Email is required';
|
|
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this._email)) {
|
|
errors.email = 'Invalid email format';
|
|
}
|
|
|
|
if (!this._password) {
|
|
errors.password = 'Password is required';
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
/** Convert to API LoginParams DTO */
|
|
toRequestDto(): { email: string; password: string } {
|
|
return {
|
|
email: this._email,
|
|
password: this._password,
|
|
};
|
|
}
|
|
}
|