Search in sources :

Example 1 with User

use of org.example.app1.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> ");
}
Also used : User(entities.User) HttpSession(javax.servlet.http.HttpSession) PreparedStatement(java.sql.PreparedStatement) SimpleDateFormat(java.text.SimpleDateFormat) RequestDispatcher(javax.servlet.RequestDispatcher) PrintWriter(java.io.PrintWriter)

Example 2 with User

use of org.example.app1.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/>");
}
Also used : User(entities.User) HttpSession(javax.servlet.http.HttpSession) PrintWriter(java.io.PrintWriter)

Example 3 with User

use of org.example.app1.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();
        }
    }
}
Also used : Cookie(javax.servlet.http.Cookie) User(entities.User) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SQLException(java.sql.SQLException) PrintWriter(java.io.PrintWriter)

Example 4 with User

use of org.example.app1.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);
}
Also used : Path(java.nio.file.Path) User(com.ncedu.fooddelivery.api.v1.entities.User) File(com.ncedu.fooddelivery.api.v1.entities.File) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with User

use of org.example.app1.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);
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) User(com.ncedu.fooddelivery.api.v1.entities.User) File(com.ncedu.fooddelivery.api.v1.entities.File) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) FileLinkDTO(com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)58 Test (org.junit.jupiter.api.Test)49 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)49 File (com.ncedu.fooddelivery.api.v1.entities.File)18 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)18 MultipartFile (org.springframework.web.multipart.MultipartFile)18 Path (java.nio.file.Path)16 FileLinkDTO (com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO)12 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 BufferedImage (java.awt.image.BufferedImage)8 CommitAfter (org.apache.tapestry5.jpa.annotations.CommitAfter)7 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)6 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)6 PersistenceContext (javax.persistence.PersistenceContext)6 User (org.example.app0.entities.User)6 User (org.example.app1.entities.User)6 User (org.example.app6.entities.User)5 EmailChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.EmailChangeDTO)4 PasswordChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO)4 IOException (java.io.IOException)4