Authentication Module - TypeScript Functions

Angular Admin Panel Documentation

Authentication Module - TypeScript Functions

🔐 LoginComponent Functions

Main user authentication interface with form validation, session management, and error handling.

🔄 Lifecycle Methods

/**
 * Component initialization
 * Sets up forms, error handling, and URL parameters
 */
ngOnInit(): void

🔑 Authentication Methods

/**
 * Main user authentication method
 * Validates form and processes login
 */
onLogin(): void

/**
 * Form submission handler
 * Navigates to dashboard on success
 */
onSubmit(): void

/**
 * Navigates to forgot password page
 */
forgotpwd(): void

/**
 * Handles error invocation
 */
invokeErr(): void

📝 Form Management

/**
 * Gets username form control
 */
get username(): FormControl

/**
 * Gets password form control  
 */
get password(): FormControl

/**
 * Form validation helper
 */
get f(): any

🗂️ Session Management

/**
 * Sets up session storage with user data
 * @param userData - User authentication data
 */
private setSessionData(userData: any): void

/**
 * Handles post-login navigation based on user status
 * @param userData - User data with verification flags
 */
private handlePostLoginNavigation(userData: any): void

⚠️ Error Handling

/**
 * Displays error messages
 * @param message - Error message to display
 */
private showError(message: string): void

/**
 * Hides error alerts after timeout
 */
private hideErrorAlert(): void

📝 SignupComponent Functions

User registration and account creation with payment integration and validation.

🔄 Lifecycle Methods

/**
 * Component initialization
 * Sets up registration form and URL parameters
 */
ngOnInit(): void

👤 Registration Methods

/**
 * Handles user registration
 * Validates form and creates new account
 */
onSignup(): void

/**
 * Gets URL parameter for referral tracking
 */
getUrl(): void

/**
 * Handles payment processing
 */
pay(amount: number): void

/**
 * Initializes payment handler
 */
invokeStripe(): void

📝 Form Management

/**
 * Validates signup form
 */
validateForm(): boolean

/**
 * Gets first name form control
 */
get firstName(): FormControl

/**
 * Gets last name form control
 */
get lastName(): FormControl

/**
 * Gets email form control
 */
get email(): FormControl

/**
 * Gets password form control
 */
get password(): FormControl

/**
 * Gets policy acceptance form control
 */
get policy(): FormControl

🔗 Integration Methods

/**
 * Sets up Zoho SalesIQ visitor tracking
 * @param name - User's full name
 * @param email - User's email address
 * @param id - User account ID
 */
ZohoVisitors(name: string, email: string, id: number): void

/**
 * Handles Google login integration
 */
googleLogin(): void

/**
 * Processes successful registration response
 * @param response - Registration response data
 */
private handleSuccessfulSignup(response: any): void

✅ Validation Methods

/**
 * Validates email format
 * @param email - Email to validate
 */
private validateEmail(email: string): boolean

/**
 * Validates password strength
 * @param password - Password to validate
 */
private validatePassword(password: string): boolean

/**
 * Shows validation error messages
 * @param field - Form field name
 * @param message - Error message
 */
private showValidationError(field: string, message: string): void

🔄 ForgotComponent Functions

Password recovery and reset functionality with email verification.

🔄 Lifecycle Methods

/**
 * Component initialization
 * Sets up forgot password form and route parameters
 */
ngOnInit(): void

🔐 Password Recovery Methods

/**
 * Handles forgot password request
 * Sends password reset email or updates password
 */
onForgot(): void

/**
 * Sends password reset email
 * @param data - User email and username
 */
private sendPasswordResetEmail(data: any): void

/**
 * Updates user password with new credentials
 * @param passwordData - New password information
 */
private updateUserPassword(passwordData: any): void

📝 Form Management

/**
 * Validates forgot password form
 */
validateForgotForm(): boolean

/**
 * Validates password reset form
 */
validatePasswordResetForm(): boolean

/**
 * Gets email form control
 */
get email(): FormControl

/**
 * Gets username form control
 */
get username(): FormControl

/**
 * Gets new password form control
 */
get newPassword(): FormControl

/**
 * Gets confirm password form control
 */
get confirmPassword(): FormControl

✅ VerifyComponent Functions

Account verification and activation with SMS and email verification.

🔄 Lifecycle Methods

/**
 * Component initialization
 * Sets up verification form and processes URL parameters
 */
ngOnInit(): void

✅ Verification Methods

/**
 * Handles account verification
 * Processes verification code and activates account
 */
onVerify(): void

/**
 * Resends verification code
 */
resendVerificationCode(): void

/**
 * Handles SMS verification
 * @param code - SMS verification code
 */
verifySMS(code: string): void

/**
 * Handles email verification
 * @param token - Email verification token
 */
verifyEmail(token: string): void

/**
 * Completes verification process
 * @param verificationData - Verification response data
 */
private completeVerification(verificationData: any): void

📝 Form Management

/**
 * Gets verification code form control
 */
get verificationCode(): FormControl

/**
 * Validates verification form
 */
validateVerificationForm(): boolean

/**
 * Handles verification form submission
 */
onSubmitVerification(): void

🔐 TwofactorComponent Functions

Two-factor authentication setup and management with multiple authentication methods.

🔄 Lifecycle Methods

/**
 * Component initialization
 * Sets up 2FA configuration and loads user settings
 */
ngOnInit(): void

🔐 Two-Factor Authentication Methods

/**
 * Enables two-factor authentication
 * @param method - Authentication method (SMS, EMAIL, APP)
 */
enableTwoFactor(method: string): void

/**
 * Disables two-factor authentication
 */
disableTwoFactor(): void

/**
 * Generates QR code for authenticator apps
 */
generateQRCode(): void

/**
 * Verifies 2FA setup
 * @param code - Verification code
 */
verifyTwoFactorSetup(code: string): void

/**
 * Sets up SMS authentication
 * @param phoneNumber - User's phone number
 */
setupSMSAuth(phoneNumber: string): void

/**
 * Sets up email authentication
 * @param email - User's email address
 */
setupEmailAuth(email: string): void

/**
 * Handles backup code generation
 */
generateBackupCodes(): void

📝 Form Management

/**
 * Gets authentication code form control
 */
get authCode(): FormControl

/**
 * Gets phone number form control
 */
get phoneNumber(): FormControl

/**
 * Validates 2FA setup form
 */
validateTwoFactorForm(): boolean

⚙️ AuthService Functions

Core authentication service providing login, registration, session management, and security features.

Service Properties

export class AuthService {
  // Private properties
  private readonly apiUrl = 'api/auth';
  private currentUserSubject = new BehaviorSubject<User | null>(null);
  private tokenSubject = new BehaviorSubject<string | null>(null);
  
  // Public observables
  public currentUser$ = this.currentUserSubject.asObservable();
  public token$ = this.tokenSubject.asObservable();
  public isAuthenticated$ = this.currentUser$.pipe(map(user => !!user));
}

🔐 Authentication Operations

/**
 * User login authentication
 * @param credentials - Login credentials
 */
login(credentials: LoginCredentials): Observable<AuthResponse>

/**
 * User registration
 * @param userData - Registration data
 */
register(userData: RegisterRequest): Observable<AuthResponse>

/**
 * User logout
 */
logout(): Observable<void>

/**
 * Refresh authentication token
 */
refreshToken(): Observable<AuthResponse>

/**
 * Validate current session
 */
validateSession(): Observable<boolean>

/**
 * Check if user is authenticated
 */
isAuthenticated(): boolean

🔄 Password Management

/**
 * Send password reset email
 * @param email - User email address
 */
forgotPassword(email: string): Observable<void>

/**
 * Reset password with token
 * @param token - Reset token
 * @param newPassword - New password
 */
resetPassword(token: string, newPassword: string): Observable<void>

/**
 * Change user password
 * @param currentPassword - Current password
 * @param newPassword - New password
 */
changePassword(currentPassword: string, newPassword: string): Observable<void>

/**
 * Validate password strength
 * @param password - Password to validate
 */
validatePasswordStrength(password: string): PasswordStrength

✅ Account Verification

/**
 * Send verification email
 * @param email - User email address
 */
sendVerificationEmail(email: string): Observable<void>

/**
 * Verify email with token
 * @param token - Verification token
 */
verifyEmail(token: string): Observable<void>

/**
 * Send SMS verification code
 * @param phoneNumber - User phone number
 */
sendSMSVerification(phoneNumber: string): Observable<void>

/**
 * Verify SMS code
 * @param code - SMS verification code
 */
verifySMS(code: string): Observable<void>

/**
 * Resend verification code
 * @param method - Verification method (EMAIL, SMS)
 */
resendVerificationCode(method: string): Observable<void>

🔐 Two-Factor Authentication

/**
 * Enable two-factor authentication
 * @param method - 2FA method
 */
enableTwoFactor(method: TwoFactorMethod): Observable<TwoFactorSetup>

/**
 * Disable two-factor authentication
 */
disableTwoFactor(): Observable<void>

/**
 * Verify two-factor code
 * @param code - 2FA code
 */
verifyTwoFactor(code: string): Observable<boolean>

/**
 * Generate backup codes
 */
generateBackupCodes(): Observable<string[]>

/**
 * Get 2FA QR code
 */
getTwoFactorQRCode(): Observable<string>

🗂️ Session Management

/**
 * Get current user
 */
getCurrentUser(): User | null

/**
 * Update user profile
 * @param userData - Updated user data
 */
updateProfile(userData: UpdateProfileRequest): Observable<User>

/**
 * Get user permissions
 */
getUserPermissions(): Observable<Permission[]>

/**
 * Check user permission
 * @param permission - Permission to check
 */
hasPermission(permission: string): boolean

/**
 * Get user roles
 */
getUserRoles(): Observable<Role[]>

🔒 Security Features

/**
 * Get login history
 * @param limit - Number of records to retrieve
 */
getLoginHistory(limit: number = 10): Observable<LoginHistory[]>

/**
 * Get active sessions
 */
getActiveSessions(): Observable<UserSession[]>

/**
 * Terminate session
 * @param sessionId - Session ID to terminate
 */
terminateSession(sessionId: string): Observable<void>

/**
 * Report suspicious activity
 * @param activityData - Suspicious activity details
 */
reportSuspiciousActivity(activityData: SuspiciousActivity): Observable<void>

/**
 * Enable account lock
 */
enableAccountLock(): Observable<void>

/**
 * Disable account lock
 */
disableAccountLock(): Observable<void>

🛡️ AuthGuard Functions

Route protection guard ensuring authenticated access to protected routes.

🛡️ Guard Methods

/**
 * Determines if a route can be activated
 * @param route - Activated route snapshot
 * @param state - Router state snapshot
 */
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | Observable<boolean>

/**
 * Determines if child routes can be activated
 * @param childRoute - Child route snapshot
 * @param state - Router state snapshot
 */
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | Observable<boolean>

/**
 * Determines if a route can be deactivated
 * @param component - Component instance
 * @param currentRoute - Current route snapshot
 * @param currentState - Current router state
 * @param nextState - Next router state
 */
canDeactivate(component: any, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): boolean | Observable<boolean>

/**
 * Checks user permissions for route access
 * @param requiredPermissions - Required permissions for route
 */
private checkPermissions(requiredPermissions: string[]): boolean

/**
 * Handles unauthorized access attempts
 * @param route - Attempted route
 */
private handleUnauthorizedAccess(route: string): void

📋 Interface Definitions

Core Interfaces

interface User {
  id: string;
  username: string;
  email: string;
  firstName: string;
  lastName: string;
  phone?: string;
  avatar?: string;
  isEmailVerified: boolean;
  isPhoneVerified: boolean;
  isTwoFactorEnabled: boolean;
  roles: Role[];
  permissions: Permission[];
  lastLoginAt?: Date;
  createdAt: Date;
  updatedAt: Date;
}

interface AuthResponse {
  user: User;
  token: string;
  refreshToken: string;
  expiresIn: number;
  permissions: Permission[];
}

interface LoginCredentials {
  username: string;
  password: string;
  rememberMe?: boolean;
  twoFactorCode?: string;
}

interface RegisterRequest {
  username: string;
  email: string;
  password: string;
  firstName: string;
  lastName: string;
  phone?: string;
  acceptTerms: boolean;
}

interface TwoFactorSetup {
  secret: string;
  qrCodeUrl: string;
  backupCodes: string[];
  method: TwoFactorMethod;
}

Enums

enum TwoFactorMethod {
  SMS = 'sms',
  EMAIL = 'email',
  AUTHENTICATOR_APP = 'authenticator_app'
}

enum PasswordStrength {
  WEAK = 'weak',
  MEDIUM = 'medium',
  STRONG = 'strong',
  VERY_STRONG = 'very_strong'
}

enum AccountStatus {
  ACTIVE = 'active',
  INACTIVE = 'inactive',
  SUSPENDED = 'suspended',
  PENDING_VERIFICATION = 'pending_verification'
}

enum LoginResult {
  SUCCESS = 'success',
  INVALID_CREDENTIALS = 'invalid_credentials',
  ACCOUNT_LOCKED = 'account_locked',
  TWO_FACTOR_REQUIRED = 'two_factor_required',
  EMAIL_VERIFICATION_REQUIRED = 'email_verification_required'
}

Related Documentation

📦 Module Overview