Search in sources :

Example 16 with UserBean

use of models.UserBean in project bil372-proje by mertserezli.

the class ForgotPasswordServlet method doPost.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    PrintWriter pw = response.getWriter();
    try {
        UserBean user = new UserBean();
        String username = request.getParameter("username");
        user.setUserName(username);
        user = ForgotPasswordDAO.getPassword(user);
        if (user.getEmail() == null) {
            pw.println("<h1>No such user exists!</h1> <br/>");
        } else {
            boolean success = SendMail.sendMail(user);
            if (success)
                pw.println("<h1>Mail has been sent to your email! " + user.getEmail() + "</h1><br/>");
            else
                pw.println("<h1>Problem occured while sending email!</h1>");
        }
    } catch (Throwable theException) {
        System.out.println(theException);
    }
}
Also used : UserBean(models.UserBean) PrintWriter(java.io.PrintWriter)

Example 17 with UserBean

use of models.UserBean in project bil372-proje by mertserezli.

the class LoginServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    try {
        UserBean user = new UserBean();
        user.setUserName(request.getParameter("username"));
        user.setPassword(request.getParameter("password"));
        user = LoginDAO.login(user);
        if (user.isValid()) {
            HttpSession session = request.getSession(true);
            session.setAttribute("currentSessionUser", user);
            response.sendRedirect("profile.jsp?username=" + user.getUsername());
        } else
            response.sendRedirect("invalidLogin.jsp");
    } catch (Throwable theException) {
        System.out.println(theException);
    }
}
Also used : UserBean(models.UserBean) HttpSession(javax.servlet.http.HttpSession)

Example 18 with UserBean

use of models.UserBean in project bil372-proje by mertserezli.

the class MessageServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    try {
        PrintWriter pw = response.getWriter();
        UserBean currentUser = (UserBean) request.getSession().getAttribute("currentSessionUser");
        java.sql.Date date = new java.sql.Date(Calendar.getInstance().getTime().getTime());
        MessageBean message = new MessageBean();
        message.setSender(currentUser.getUsername());
        message.setReceiver(request.getParameter("receivers").split(","));
        message.setDate(date);
        message.setTitle(request.getParameter("title"));
        message.setContent(request.getParameter("content"));
        boolean success = MessageDAO.sendMessage(message);
        if (success) {
            for (String receiver : message.getReceiver()) {
                NotificationBean notification = new NotificationBean();
                notification.setUsername(receiver);
                notification.setDate(date);
                notification.setNotification("(Mesaj)" + message.getSender() + " adli kullanici size mesaj gonderdi");
                NotificationDAO.sendNotification(notification);
            }
            pw.println("Message is sent succesfully");
            return;
        }
        pw.println("Message couldn't sent");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageBean(models.MessageBean) NotificationBean(models.NotificationBean) UserBean(models.UserBean) Date(java.sql.Date) ServletException(javax.servlet.ServletException) PrintWriter(java.io.PrintWriter) Date(java.sql.Date)

Example 19 with UserBean

use of models.UserBean in project bil372-proje by mertserezli.

the class SearchDAO method searchForUserWithQualifications.

public static List<UserBean> searchForUserWithQualifications(String qualificationsRequest) throws SQLException {
    List<String> employees = new ArrayList<String>();
    List<UserBean> result = new ArrayList<UserBean>();
    PreparedStatement ps = null;
    String searchQueryOne = "Select DISTINCT Username From EMP_QUALIFICATIONS Where ";
    String[] qRequests = qualificationsRequest.split(",");
    for (String s : qRequests) {
        searchQueryOne += "'" + s + "'=ANY(qualifications)";
        if (!s.equals(qRequests[qRequests.length - 1]))
            searchQueryOne += " AND ";
    }
    try {
        ConnectionManager connect = new ConnectionManager();
        currentConnection = connect.getConnection();
        ps = currentConnection.prepareStatement(searchQueryOne);
        rs = ps.executeQuery();
        while (rs.next()) {
            String employee = rs.getString("Username");
            employees.add(employee);
        }
        String searchQueryTwo;
        for (String e : employees) {
            searchQueryTwo = "Select * From EMPLOYEE Where Username = '" + e + "'";
            ps = currentConnection.prepareStatement(searchQueryTwo);
            rs = ps.executeQuery();
            while (rs.next()) {
                UserBean user = new UserBean();
                user.setUserName(rs.getString("Username"));
                user.setPassword(rs.getString("Password"));
                user.setJobTitle(rs.getString("JobTitle"));
                user.setImage(rs.getString("Image"));
                user.setFirstName(rs.getString("FirstName"));
                user.setMiddleName(rs.getString("MiddleName"));
                user.setLastName(rs.getString("LastName"));
                user.setEmail(rs.getString("Email"));
                user.setValid(true);
                result.add(user);
            }
        }
        while (rs.next()) {
        }
    } finally {
        finalizeConnection(currentConnection, ps, rs);
    }
    return result;
}
Also used : UserBean(models.UserBean) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 20 with UserBean

use of models.UserBean in project bil372-proje by mertserezli.

the class SearchDAO method searchForUser.

public static List<UserBean> searchForUser(String usernameRequest) throws SQLException {
    List<UserBean> result = new ArrayList<UserBean>();
    PreparedStatement ps = null;
    String searchQuery = "Select DISTINCT * From EMPLOYEE Where UPPER(Username) LIKE UPPER('%" + usernameRequest + "%')";
    try {
        ConnectionManager connect = new ConnectionManager();
        currentConnection = connect.getConnection();
        ps = currentConnection.prepareStatement(searchQuery);
        rs = ps.executeQuery();
        while (rs.next()) {
            UserBean user = new UserBean();
            user.setUserName(rs.getString("Username"));
            user.setPassword(rs.getString("Password"));
            user.setJobTitle(rs.getString("JobTitle"));
            user.setImage(rs.getString("Image"));
            user.setFirstName(rs.getString("FirstName"));
            user.setMiddleName(rs.getString("MiddleName"));
            user.setLastName(rs.getString("LastName"));
            user.setEmail(rs.getString("Email"));
            user.setValid(true);
            result.add(user);
        }
    } finally {
        finalizeConnection(currentConnection, ps, rs);
    }
    return result;
}
Also used : UserBean(models.UserBean) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Aggregations

UserBean (models.UserBean)21 ArrayList (java.util.ArrayList)8 PrintWriter (java.io.PrintWriter)6 ProjectBean (models.ProjectBean)5 ServletException (javax.servlet.ServletException)4 NotificationBean (models.NotificationBean)4 PreparedStatement (java.sql.PreparedStatement)3 Date (java.sql.Date)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletContext (javax.servlet.ServletContext)1 HttpSession (javax.servlet.http.HttpSession)1 Part (javax.servlet.http.Part)1 CommentBean (models.CommentBean)1 CompanyBean (models.CompanyBean)1 MessageBean (models.MessageBean)1 TaskBean (models.TaskBean)1