diff --git a/amber/src/main/scala/org/apache/texera/web/resource/EmailTemplate.scala b/amber/src/main/scala/org/apache/texera/web/resource/EmailTemplate.scala index 1ad3c57af7a..1b7517b4cd1 100644 --- a/amber/src/main/scala/org/apache/texera/web/resource/EmailTemplate.scala +++ b/amber/src/main/scala/org/apache/texera/web/resource/EmailTemplate.scala @@ -44,6 +44,8 @@ object EmailTemplate { def userRegistrationNotification( receiverEmail: String, userEmail: Option[String], + affiliation: Option[String], + reason: Option[String], toAdmin: Boolean ): EmailMessage = { if (toAdmin) { @@ -55,9 +57,11 @@ object EmailTemplate { |Hello Admin, | |A new user has attempted to log in or register, but their account is not yet approved. - |Please review the account request for the following email: + |Please review the account request for the following user: | - |${userEmail.getOrElse("Unknown")} + |Email: ${userEmail.getOrElse("Unknown")} + |Affiliation: ${affiliation.filter(_.trim.nonEmpty).getOrElse("Not provided")} + |Reason: ${reason.filter(_.trim.nonEmpty).getOrElse("Not provided")} | |Visit the admin panel at: $deployment | diff --git a/amber/src/main/scala/org/apache/texera/web/resource/GmailResource.scala b/amber/src/main/scala/org/apache/texera/web/resource/GmailResource.scala index 255567494fc..f06f1f92102 100644 --- a/amber/src/main/scala/org/apache/texera/web/resource/GmailResource.scala +++ b/amber/src/main/scala/org/apache/texera/web/resource/GmailResource.scala @@ -35,7 +35,13 @@ import javax.mail.{Message, PasswordAuthentication, Session, Transport} import javax.ws.rs._ import scala.util.{Failure, Success, Try} -case class EmailMessage(receiver: String, subject: String, content: String) +case class EmailMessage( + receiver: String, + subject: String, + content: String, + affiliation: Option[String] = None, + reason: Option[String] = None +) object GmailResource { private def context = @@ -169,6 +175,8 @@ class GmailResource { userRegistrationNotification( receiverEmail = adminEmail, userEmail = Some(emailMessage.receiver), + affiliation = emailMessage.affiliation, + reason = emailMessage.reason, toAdmin = true ), adminEmail @@ -184,6 +192,8 @@ class GmailResource { userRegistrationNotification( receiverEmail = emailMessage.receiver, userEmail = None, + affiliation = None, + reason = None, toAdmin = false ), emailMessage.receiver diff --git a/frontend/src/app/common/service/gmail/gmail.service.ts b/frontend/src/app/common/service/gmail/gmail.service.ts index 4645a694e76..925e7e3a39d 100644 --- a/frontend/src/app/common/service/gmail/gmail.service.ts +++ b/frontend/src/app/common/service/gmail/gmail.service.ts @@ -48,15 +48,17 @@ export class GmailService { }); } - public notifyUnauthorizedLogin(userEmail: string): void { - this.http.post(`${AppSettings.getApiEndpoint()}/gmail/notify-unauthorized`, { receiver: userEmail }).subscribe({ - next: () => this.notificationService.success("An admin has been notified about your account request."), - error: (error: unknown) => { - if (error instanceof HttpErrorResponse) { - this.notificationService.error("Failed to notify admin about your account request."); - console.error("Notify error:", error.error); - } - }, - }); + public notifyUnauthorizedLogin(userEmail: string, affiliation: string, reason: string): void { + this.http + .post(`${AppSettings.getApiEndpoint()}/gmail/notify-unauthorized`, { receiver: userEmail, affiliation, reason }) + .subscribe({ + next: () => this.notificationService.success("An admin has been notified about your account request."), + error: (error: unknown) => { + if (error instanceof HttpErrorResponse) { + this.notificationService.error("Failed to notify admin about your account request."); + console.error("Notify error:", error.error); + } + }, + }); } } diff --git a/frontend/src/app/common/service/user/auth.service.ts b/frontend/src/app/common/service/user/auth.service.ts index 5b7f38d5701..9c9d0587cc4 100644 --- a/frontend/src/app/common/service/user/auth.service.ts +++ b/frontend/src/app/common/service/user/auth.service.ts @@ -248,7 +248,7 @@ export class AuthService { try { await firstValueFrom(this.submitRegistration(uid, affiliation, reason)); - this.gmailService.notifyUnauthorizedLogin(email); + this.gmailService.notifyUnauthorizedLogin(email, affiliation, reason); } finally { this.logout(); }