Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ object EmailTemplate {
def userRegistrationNotification(
receiverEmail: String,
userEmail: Option[String],
affiliation: Option[String],
reason: Option[String],
toAdmin: Boolean
): EmailMessage = {
if (toAdmin) {
Expand All @@ -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
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -169,6 +175,8 @@ class GmailResource {
userRegistrationNotification(
receiverEmail = adminEmail,
userEmail = Some(emailMessage.receiver),
affiliation = emailMessage.affiliation,
reason = emailMessage.reason,
toAdmin = true
),
adminEmail
Expand All @@ -184,6 +192,8 @@ class GmailResource {
userRegistrationNotification(
receiverEmail = emailMessage.receiver,
userEmail = None,
affiliation = None,
reason = None,
toAdmin = false
),
emailMessage.receiver
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/app/common/service/gmail/gmail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
});
}
}
2 changes: 1 addition & 1 deletion frontend/src/app/common/service/user/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading