This now emails users when a login is detected.

This commit is contained in:
James Quinley 2022-02-08 01:31:38 -08:00
parent 25c791c3b5
commit 20741b50e2
4 changed files with 69 additions and 0 deletions

10
pom.xml
View File

@ -30,6 +30,16 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.6.2</version>
</dependency>
<dependency> <dependency>
<groupId>com.jfoenix</groupId> <groupId>com.jfoenix</groupId>
<artifactId>jfoenix</artifactId> <artifactId>jfoenix</artifactId>

View File

@ -1,9 +1,65 @@
package com.jamesquinley.Asecure; package com.jamesquinley.Asecure;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
public class emailVerify { public class emailVerify {
/* /*
This will handle both account creation verify and login verify tasks, it will not verify for token based logins as This will handle both account creation verify and login verify tasks, it will not verify for token based logins as
that form of login is client controlled and no user input is allowed, hacked clients are also locked out of the network that form of login is client controlled and no user input is allowed, hacked clients are also locked out of the network
*/ */
static final String senderEmailId = "jqerverupkeepa.alertserver@gmail.com";
static final String senderPassword = "aotskDEVSIGNSERVICE32143214";
static final String emailSMTPserver = "smtp.gmail.com";
static final String emailSMTPPort = "465";
public static void SendEmailThroughGmail(String receiverEmail) {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yy");
String Date = formatter.format(date);
Properties props = new Properties();
props.put("mail.smtp.host", emailSMTPserver);
props.put("mail.smtp.socketFactory.port", emailSMTPPort);
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", emailSMTPPort);
try {
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(senderEmailId));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(receiverEmail));
message.setSubject("Obsidian Core Account Login Notice | " + Date);
message.setText("We detected a new login on your account, if this was you ignore this email, if it wasn't you, \n please login and change your password. \n \n \n \n \n This was sent on behalf of Obsidian Core Studios by our super cool login robots! \n NOTICE: This is a no-reply address.");
Transport.send(message);
System.out.println("Server Failed To Send User Login Notice");
} catch (Exception e) {
e.printStackTrace();
System.err.println("Notice Was Not Sent Because Of An Error.");
}
}
private static class SMTPAuthenticator extends
javax.mail.Authenticator {
public PasswordAuthentication
getPasswordAuthentication() {
return new PasswordAuthentication(senderEmailId,
senderPassword);
}
}
} }

View File

@ -296,6 +296,7 @@ public class delegationServices {
Fname = (String) accountServer.get("FName"); Fname = (String) accountServer.get("FName");
Path = (String) accountServer.get("Path"); Path = (String) accountServer.get("Path");
Email = (String) accountServer.get("Email"); Email = (String) accountServer.get("Email");
com.jamesquinley.Asecure.emailVerify.SendEmailThroughGmail(Email);
UserName = (String) accountServer.get("User"); UserName = (String) accountServer.get("User");
BasicDBObject searchQuery = new BasicDBObject(); BasicDBObject searchQuery = new BasicDBObject();
@ -400,6 +401,7 @@ public class delegationServices {
Fname = (String) accountServer.get("FName"); Fname = (String) accountServer.get("FName");
Path = (String) accountServer.get("Path"); Path = (String) accountServer.get("Path");
Email = (String) accountServer.get("Email"); Email = (String) accountServer.get("Email");
com.jamesquinley.Asecure.emailVerify.SendEmailThroughGmail(Email);
UserName = (String) accountServer.get("User"); UserName = (String) accountServer.get("User");
BasicDBObject searchQuery = new BasicDBObject(); BasicDBObject searchQuery = new BasicDBObject();

View File

@ -14,5 +14,6 @@ public class init
com.jamesquinley.DelegationServices.delegationTimer.trigger(); com.jamesquinley.DelegationServices.delegationTimer.trigger();
DeleteAllRequests(); DeleteAllRequests();
System.out.println("We've started everything, requests are now being served"); System.out.println("We've started everything, requests are now being served");
} }
} }