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);
}
}
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);
}
}
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();
}
}
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;
}
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;
}
Aggregations