use of org.example.app0.entities.User in project C-DAC-Notes by shreeshailaya.
the class ConfirmServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// insert the record of shopping summary in database
// first column is AI
// second column is uid
RequestDispatcher rd = request.getRequestDispatcher("/header");
rd.include(request, response);
HttpSession session = request.getSession();
User u = (User) session.getAttribute("cuser");
String uid = u.getUid();
// current date and time - third column
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");
String cdate = sdf.format(Calendar.getInstance().getTime());
// forth column - total cost
int total = (Integer) session.getAttribute("totalcost");
// create insert query for shopping table
PreparedStatement ps = null;
PrintWriter out = response.getWriter();
out.println("UID : " + uid);
out.println("date : " + cdate);
out.println("total : " + total);
out.println("<h3>Thanks for shopping with us<h3>");
out.println("<p> Bill will be mailed at " + u.getEmail() + "</p>");
out.println("<p> You will receive the message on " + u.getContact() + "before delivery</p>");
out.println("<br/> <a href='logout'> LOGOUT </a> ");
}
use of org.example.app0.entities.User in project C-DAC-Notes by shreeshailaya.
the class HeaderServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
User u = (User) session.getAttribute("cuser");
if (u == null) {
out.println("<h2>Welcome GUEST !!</h2>");
} else {
out.println("<h2>Welcome " + u.getFname() + " " + u.getLname() + "</h2>");
}
out.println("<hr/>");
}
use of org.example.app0.entities.User in project C-DAC-Notes by shreeshailaya.
the class LoginServlet method doPost.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// login authentication will be done
PrintWriter out = response.getWriter();
String uid = request.getParameter("uid");
String pwd = request.getParameter("pwd");
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = con.prepareStatement("select * from users where uid = ? and password = ?");
ps.setString(1, uid);
ps.setString(2, pwd);
rs = ps.executeQuery();
boolean flag = false;
while (rs.next()) {
if (rs.getString(1).equals(uid) && rs.getString(2).equals(pwd)) {
flag = true;
User u = new User(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6));
request.getSession().setAttribute("cuser", u);
}
}
if (// success login
flag) {
/*out.println("Login successful");
out.println("<h2> Welcome "+ fnm+" "+lnm+"</h2>");*/
// delete the loginerror cookie
Cookie[] allc = request.getCookies();
if (allc != null) {
for (Cookie c : allc) {
if (c.getName().equals("loginerror")) {
c.setMaxAge(0);
response.addCookie(c);
}
}
}
RequestDispatcher rd = request.getRequestDispatcher("/home");
rd.forward(request, response);
} else // failed login
{
/*out.println("Login failed"); */
// relative URL - / means root of web application
/*RequestDispatcher rd = request.getRequestDispatcher("/login.jsp");
rd.forward(request, response);*/
Cookie c = new Cookie("loginerror", "Wrong_ID_or_PASSWORD");
response.addCookie(c);
// relative URL - / means the root of server
response.sendRedirect("/ShoppingApp/login.jsp");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of org.example.app0.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method deleteImgAdmin.
@Test
public void deleteImgAdmin() throws IOException {
// prepare
Long adminId = 1L;
User sheldonAdmin = UserUtils.adminSheldonCooper(adminId);
Long ownerId = 2L;
User howardOwner = UserUtils.courierHowardWolowitz(ownerId);
String imgName = "test.jpeg";
Path pathTestPng = UPLOAD_PATH.resolve(imgName);
// file name, where we locate our test.png
final String fileUuid = "e2233b13-8439-4cf4-a5a3-f3351ebe6368";
Path fileUuidPath = createFileUuidPath(fileUuid);
Files.copy(pathTestPng, fileUuidPath, StandardCopyOption.REPLACE_EXISTING);
File fileEntity = new File(UUID.fromString(fileUuid), FileType.JPEG, imgName, Files.size(fileUuidPath), Timestamp.valueOf(LocalDateTime.now()), howardOwner);
doNothing().when(fileRepoMock).delete(fileEntity);
fileService.delete(fileEntity, sheldonAdmin);
assertFalse(Files.exists(fileUuidPath));
verify(fileRepoMock, times(1)).delete(fileEntity);
}
use of org.example.app0.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method savePngClient.
@Test
public void savePngClient() throws IOException {
// prepare
Long userId = 1L;
User rajeshClient = UserUtils.clientRajeshKoothrappali(userId);
MultipartFile file = getImgWithType("test", "png");
Long fileSize = file.getSize();
log.info("FILE SIZE before uploading: " + fileSize + " FILE NAME: " + file.getName());
when(fileRepoMock.save(any(File.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
FileLinkDTO fileLinkDTO = fileService.save(file, rajeshClient);
verify(fileRepoMock, times(1)).save(any(File.class));
Path uploadedFile = getUploadedFilePath(fileLinkDTO.getFileUuid());
assertTrue(Files.exists(uploadedFile));
Long uploadedFileSize = Files.size(uploadedFile);
log.info("FILE SIZE after uploading: " + uploadedFileSize + " FILE UUID: " + fileLinkDTO.getFileUuid());
// uploaded size more than income because convert from png to jpeg
assertTrue(fileSize < uploadedFileSize);
}
Aggregations