Skip to content
Snippets Groups Projects
Commit ad5aafa9 authored by Ali Akbar's avatar Ali Akbar
Browse files

Update delete token saat logout

parent f35d0ead
No related merge requests found
Showing
with 127 additions and 117 deletions
......@@ -8,7 +8,6 @@ package org.ChatService;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
......@@ -36,34 +35,18 @@ public class DeleteToken extends HttpServlet {
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
JSONObject json = new JSONObject();
try {
Connection conn = DBChatToken.getConnection();
if (conn != null) {
Statement stmt = conn.createStatement();
String sql;
String user_id = request.getParameter("user_id");
sql = "DELETE FROM chattoken WHERE user_id =" + user_id;
stmt.executeUpdate(sql);
json.put("status","OK");
PrintWriter out = response.getWriter();
out.print(json.toString());
} else {
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet login</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Connection NULL!!</h1>");
out.println("</body>");
out.println("</html>");
}
}
} catch (SQLException ex) {
Logger.getLogger(TokenSaver.class.getName()).log(Level.SEVERE, null, ex);
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet DeleteToken</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet DeleteToken at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
......@@ -80,7 +63,21 @@ public class DeleteToken extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
JSONObject json = new JSONObject();
processRequest(request,response);
Connection conn = DBChatToken.getConnection();
if (conn != null) {
try {
Statement stmt = conn.createStatement();
String sql;
String user_id = request.getParameter("user_id");
sql = "DELETE FROM chattoken WHERE user_id =" + user_id;
stmt.executeUpdate(sql);
json.put("status","OK");
PrintWriter out = response.getWriter();
out.print(json.toString());
} catch (SQLException ex) {
Logger.getLogger(DeleteToken.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/**
......@@ -94,7 +91,7 @@ public class DeleteToken extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request,response);
doGet(request, response);
}
/**
......
......@@ -48,7 +48,9 @@ public class TokenSaver extends HttpServlet {
String sql;
String username = request.getParameter("username");
String chattoken = request.getParameter("chattoken");
sql = "insert into chattoken values (\"" + chattoken + "\",\"" + username + "\")";
String user_id = request.getParameter("user_id");
sql = "insert into chattoken values (\"" + chattoken + "\",\"" + username + "\",\""
+ user_id + "\")";
stmt.executeUpdate(sql);
PrintWriter out = response.getWriter();
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
No preview for this file type
deploy.ant.properties.file=/home/khrs/.netbeans/8.2/config/GlassFishEE6/Properties/gfv3-2049786751.properties
deploy.ant.properties.file=C:\\Users\\Ali-pc\\AppData\\Roaming\\NetBeans\\8.0.2\\config\\GlassFishEE6\\Properties\\gfv3-445781616.properties
j2ee.platform.is.jsr109=true
j2ee.server.domain=/home/khrs/glassfish-4.1.1/glassfish/domains/domain1
j2ee.server.home=/home/khrs/glassfish-4.1.1/glassfish
j2ee.server.instance=[/home/khrs/glassfish-4.1.1/glassfish:/home/khrs/glassfish-4.1.1/glassfish/domains/domain1]deployer:gfv3ee6wc:localhost:4848
j2ee.server.middleware=/home/khrs/glassfish-4.1.1
user.properties.file=/home/khrs/.netbeans/8.2/build.properties
j2ee.server.domain=C:/Users/Ali-pc/AppData/Roaming/NetBeans/8.0.2/config/GF_4.1/domain1
j2ee.server.home=C:/Program Files/glassfish-4.1/glassfish
j2ee.server.instance=[C:\\Program Files\\glassfish-4.1\\glassfish;C:\\Program Files\\glassfish-4.1\\glassfish\\domains\\domain1]deployer:gfv3ee6:localhost:4848
j2ee.server.middleware=C:/Program Files/glassfish-4.1
user.properties.file=C:\\Users\\Ali-pc\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
......@@ -5,11 +5,19 @@
*/
package org.IdentService;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
......@@ -67,8 +75,21 @@ public class logout extends HttpServlet {
JSONObject responseJSON = new JSONObject();
try {
Statement stmt = conn.createStatement();
String sql = "DELETE FROM accountdb.token WHERE token.token=\""+token+"\"";
stmt.executeUpdate(sql);
String sql = "SELECT * FROM token NATURAL JOIN account "
+ "WHERE token=\""+token+"\"";
ResultSet rs = stmt.executeQuery(sql);
String user_name = null;
int user_id = 0;
if (rs.next()){
user_id = rs.getInt("user_id");
user_name = rs.getString("username");
}
String urlRequest = "http://localhost:8080/ChatService/DeleteToken?user_id="+user_id;
URL obj = new URL(urlRequest);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader((con.getInputStream())));
String sql1 = "DELETE FROM accountdb.token WHERE token.token=\""+token+"\"";
stmt.executeUpdate(sql1);
responseJSON.put("status","OK");
String detail = "Delete token="+token;
responseJSON.put("detail",detail);
......
......@@ -13,21 +13,21 @@ import javax.xml.bind.annotation.XmlType;
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="add_edit_product"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="description" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="price" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="image" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="option" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="product_id" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="token" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* &lt;complexType name="add_edit_product">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="description" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="price" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="image" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="option" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="product_id" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="token" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
......
......@@ -13,15 +13,15 @@ import javax.xml.bind.annotation.XmlType;
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="add_edit_productResponse"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="ProcedureStatus" type="{http://Service.MarketPlaceService.KAA.org/}procedureStatus" minOccurs="0"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* &lt;complexType name="add_edit_productResponse">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="ProcedureStatus" type="{http://Service.MarketPlaceService.KAA.org/}procedureStatus" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
......
......@@ -13,21 +13,21 @@ import javax.xml.bind.annotation.XmlType;
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="buy"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="token" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="product_id" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="quantity" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="cosignee" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="fulladdress" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="postalcode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="phone_number" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* &lt;complexType name="buy">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="token" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="product_id" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="quantity" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="cosignee" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="fulladdress" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="postalcode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="phone_number" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
......
......@@ -13,15 +13,15 @@ import javax.xml.bind.annotation.XmlType;
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="buyResponse"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="return" type="{http://Service.MarketPlaceService.KAA.org/}procedureStatus" minOccurs="0"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* &lt;complexType name="buyResponse">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="return" type="{http://Service.MarketPlaceService.KAA.org/}procedureStatus" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
......
......@@ -13,16 +13,16 @@ import javax.xml.bind.annotation.XmlType;
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="delete_product"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="token" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="product_id" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* &lt;complexType name="delete_product">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="token" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="product_id" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
......
......@@ -13,15 +13,15 @@ import javax.xml.bind.annotation.XmlType;
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="delete_productResponse"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="return" type="{http://Service.MarketPlaceService.KAA.org/}procedureStatus" minOccurs="0"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* &lt;complexType name="delete_productResponse">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="return" type="{http://Service.MarketPlaceService.KAA.org/}procedureStatus" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment