-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/development' into 31-implementat…
…ion-adding-fe-and-be-of-various-pages
- Loading branch information
Showing
24 changed files
with
1,193 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,32 +3,15 @@ | |
import model.DAO.DAOUser; | ||
import model.entity.User; | ||
import model.service.login.Authenticator; | ||
//import model.service.message.Conversation; | ||
import model.service.registration.Registration; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Encryption encryption = new Encryption(); | ||
DAOUser db = new DAOUser(); | ||
String plainTextPassword = "123456"; | ||
EmailManager message = new EmailManager(); | ||
|
||
/* | ||
String hashedPassword = encryption.encryptPassword(plainTextPassword); | ||
//Conversation conv = new Conversation(9); | ||
//System.out.println(conv.getUnreadMessagesCounter()); | ||
//System.out.println(conv.getConversations()); | ||
|
||
// Use hashed password to create new user | ||
db.createUser("[email protected]", hashedPassword, 0); | ||
*/ | ||
|
||
/* | ||
User user = db.getUserByIdOrEmail("[email protected]"); | ||
System.out.println(encryption.verifyPassword(plainTextPassword, user.getPassword())); | ||
*/ | ||
|
||
|
||
//test email | ||
//message.sendEmail("[email protected]", "Email Test", "questo è una email di test"); | ||
|
||
//test email recupero password | ||
Authenticator authenticator = new Authenticator(); | ||
System.out.println(authenticator.authenticate("[email protected]", "123456")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package controller; | ||
|
||
import model.service.message.MessageManager; | ||
|
||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
import java.io.IOException; | ||
|
||
@WebServlet("/CountMessages") | ||
public class CountMessagesServlet extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws IOException { | ||
HttpSession session = request.getSession(); | ||
int recipientId = (int) session.getAttribute("id"); | ||
MessageManager messageManager = new MessageManager(); | ||
int receivedMessageCount = messageManager.countReceivedMessages(recipientId); | ||
|
||
response.setContentType("text/plain"); // Output is a plain text integer | ||
response.getWriter().println(receivedMessageCount); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package controller; | ||
|
||
import java.io.IOException; | ||
import java.sql.Timestamp; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import model.entity.Message; | ||
import model.service.message.MessageManager; | ||
|
||
import java.util.List; | ||
import javax.json.*; | ||
|
||
@WebServlet("/GetMessages") | ||
public class GetMessageServlet extends HttpServlet { | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
HttpSession session = request.getSession(); | ||
int userId = (int) session.getAttribute("id"); | ||
|
||
int contactId = Integer.parseInt(request.getParameter("contact_id")); // Get the contact's ID from the request | ||
|
||
// Retrieve the messages between the user and the contact | ||
MessageManager messageManager = new MessageManager(); | ||
List<Message> messages = messageManager.retrieveMessages(userId, contactId); | ||
|
||
// Now build the JSON response | ||
JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder(); | ||
|
||
for (Message message : messages) { | ||
JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder(); | ||
jsonObjectBuilder.add("sender", message.getSender()); | ||
jsonObjectBuilder.add("recipient", message.getRecipient()); | ||
jsonObjectBuilder.add("body", message.getBody()); | ||
// Convert timestamp to format HH:MM | ||
Timestamp timestamp = message.getSent(); | ||
java.util.Date date = new java.util.Date(timestamp.getTime()); | ||
java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("HH:mm"); | ||
String formattedDate = dateFormat.format(date); | ||
|
||
jsonObjectBuilder.add("sent", formattedDate); | ||
jsonArrayBuilder.add(jsonObjectBuilder.build()); | ||
} | ||
messageManager.markMessagesAsRead(contactId, userId); | ||
JsonArray jsonArray = jsonArrayBuilder.build(); | ||
|
||
response.setContentType("application/json"); | ||
response.getWriter().write(jsonArray.toString()); | ||
} | ||
|
||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws IOException { | ||
try { | ||
HttpSession session = request.getSession(); | ||
int sender = (int) session.getAttribute("id"); | ||
int recipient = Integer.parseInt(request.getParameter("recipient")); | ||
String body = request.getParameter("body"); | ||
|
||
// send the message | ||
MessageManager messageManager = new MessageManager(); | ||
messageManager.sendMessage(sender, recipient, body); | ||
|
||
response.getWriter().write("Message successfully sent"); | ||
|
||
} catch (NumberFormatException e) { | ||
// The request parameter could not be parsed as an integer | ||
response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.