Skip to content

Instantly share code, notes, and snippets.

@Akash52
Last active March 31, 2024 21:33
Show Gist options
  • Save Akash52/0c983904cabc918d84293e34dc5f6909 to your computer and use it in GitHub Desktop.
Save Akash52/0c983904cabc918d84293e34dc5f6909 to your computer and use it in GitHub Desktop.
// Class responsible for handling user authentication and authorization
class Authenticator {
public authenticateUser(username: string, password: string): boolean {
// Authentication logic
return true;
}
public authorizeUser(userRole: string): boolean {
// Authorization logic
return userRole === "admin";
}
}
// Class responsible for sending email notifications and SMS notifications
class NotificationManager {
public sendEmailNotification(email: string, message: string): void {
// Email sending logic
console.log(`Sending email to ${email}: ${message}`);
}
public sendSMSNotification(phoneNumber: string, message: string): void {
// SMS sending logic
console.log(`Sending SMS to ${phoneNumber}: ${message}`);
}
}
// Example usage
const authenticator = new Authenticator();
const notificationManager = new NotificationManager();
// Authenticate and authorize a user
const isAuthenticated = authenticator.authenticateUser("john_doe", "password123");
const isAuthorized = authenticator.authorizeUser("admin");
console.log("User authenticated:", isAuthenticated);
console.log("User authorized:", isAuthorized);
// Send notifications
notificationManager.sendEmailNotification("example@example.com", "Test email message");
notificationManager.sendSMSNotification("+1234567890", "Test SMS message");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment