Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEXCLE - 13513023 - Alexander Sukono #14

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7b668f7
base code
vincentsthe Nov 11, 2015
23fb7fb
move project to its folder
vincentsthe Nov 11, 2015
3a52caa
bootstrap identity service
vincentsthe Nov 12, 2015
343dd1c
register functionality
vincentsthe Nov 12, 2015
f66f35a
login implemented
vincentsthe Nov 12, 2015
2d372ba
Question
randichilyon Nov 15, 2015
734cc77
update Question
randichilyon Nov 15, 2015
0e88cd1
Question
randichilyon Nov 15, 2015
7bc42e3
added .gitignore
randichilyon Nov 16, 2015
3cc2d49
moving to stack_exchange
randichilyon Nov 16, 2015
bdc7b29
add answerservice, question.jsp, and assets
alexandersukono Nov 17, 2015
72c7400
update
randichilyon Nov 18, 2015
5664f65
mass commit soap
vincentsthe Nov 21, 2015
9480ee8
fix merge conflict
alexandersukono Nov 23, 2015
3723c40
CLEANUP
alexandersukono Nov 23, 2015
786522e
Modified gitignore
alexandersukono Nov 23, 2015
9283ff1
InsertAnswer now works
alexandersukono Nov 25, 2015
a22889d
fix merge conflict
randichilyon Nov 26, 2015
32b6f0a
question index mass update
randichilyon Nov 26, 2015
e9bc5b0
Merge branch 'master' of https://github.com/lexcle/IF3110-2015-T2
randichilyon Nov 26, 2015
66d65bc
fix conflict
randichilyon Nov 26, 2015
83ba2ba
add fix conflict
randichilyon Nov 26, 2015
18bd07f
fix xsd
randichilyon Nov 26, 2015
82ca555
fix conflict
randichilyon Nov 26, 2015
511a108
updatequestion, update index.jsp
randichilyon Nov 26, 2015
d87eaca
upvote and downvote question
randichilyon Nov 26, 2015
92cffb0
can delete question
randichilyon Nov 26, 2015
46adb70
fix merge conflict
randichilyon Nov 26, 2015
6261382
delete and move downvote and upvotequestion package
randichilyon Nov 27, 2015
f366775
upvote and downvote now only can be done once
vincentsthe Nov 27, 2015
f26eb14
delete nbproject
vincentsthe Nov 27, 2015
0473e6a
delete nbproject
vincentsthe Nov 27, 2015
33c0a81
update index and can connect to login and register
randichilyon Nov 27, 2015
a28ff42
add user info api
vincentsthe Nov 27, 2015
8d48f11
Merge branch 'master' of https://github.com/lexcle/IF3110-2015-T2
vincentsthe Nov 27, 2015
b4e3245
token expire
vincentsthe Nov 27, 2015
874853f
can login,register, update add and updatequestion jsp
randichilyon Nov 27, 2015
bd1d296
Merge branch 'master' of https://github.com/lexcle/IF3110-2015-T2
randichilyon Nov 27, 2015
c11ab88
update question page
alexandersukono Nov 27, 2015
e9ddb43
update addquestion and editquestion jsp
randichilyon Nov 27, 2015
2045e8d
Merge branch 'master' of https://github.com/lexcle/IF3110-2015-T2
randichilyon Nov 27, 2015
a38f796
question page final
alexandersukono Nov 27, 2015
86d6153
fix merge conflict
alexandersukono Nov 27, 2015
95dfae9
fix merge conflict
alexandersukono Nov 27, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.idea
out
*.iml
build.xml
catalog.xml
/stack_exchange/catalog.xml
/stack_exchange/nbproject/*
/stack_exchange_netbeans/nbproject/*
/stack_exchange_netbeans/catalog.xml
/stack_exchange_netbeans/nbproject/*.xml
/stack_exchange_netbeans/build/*
/stack_exchange_netbeans/dist/*
/stack_exchange_web_services/build/*
/stack_exchange_web_services/dist/*
/stack_exchange_web_services/nbproject/*
*/nbproject/*
*/build/*
*/dist/*
/stack_exchange/nbproject/private/*
/stack_exchange_netbeans/nbproject/private/*
/stack_exchange_netbeans/build/*
/stack_exchange_netbeans/dist/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Diharapkan dengan tugas ini anda dapat mengerti:

### Link Laporan

*Masukkan link laporan anda di sini*
https://www.dropbox.com/s/6ggkn4hrh2ayifd/Laporan%20Tugas%20Besar%20II%20-%20WBD.pdf?dl=0

### Arsitektur Umum Server

Expand Down
86 changes: 86 additions & 0 deletions db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
-- phpMyAdmin SQL Dump
-- version 4.4.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 09, 2015 at 02:07 PM
-- Server version: 5.6.25
-- PHP Version: 5.5.26

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `stack_exchange_2`
--

-- --------------------------------------------------------

--
-- Table structure for table `answer`
--

CREATE TABLE IF NOT EXISTS `answer` (
`id` int(11) NOT NULL primary key auto_increment,
`user_id` int(11) NOT NULL,
`question_id` int(11) NOT NULL,
`content` text NOT NULL,
`vote` int(11) DEFAULT '0',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `thread`
--

CREATE TABLE IF NOT EXISTS `question` (
`id` int(11) NOT NULL primary key auto_increment,
`user_id` int(11) NOT NULL,
`topic` varchar(255) DEFAULT NULL,
`content` text,
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`vote` int(11) DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `token`
--

CREATE TABLE IF NOT EXISTS `token` (
`id` int not null primary key auto_increment,
`token` varchar(64) NOT NULL,
`user_id` int(11) NOT NULL,
`expire` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `user`
--

CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) NOT NULL primary key auto_increment,
`password` varchar(64) NOT NULL,
`email` varchar(64) NOT NULL,
`fullname` varchar(128) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
3 changes: 3 additions & 0 deletions identity_service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
out
*.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.stackexchange.identityservice.controller;

import org.stackexchange.identityservice.dao.UserDao;
import org.stackexchange.identityservice.model.Token;
import org.stackexchange.identityservice.model.User;
import org.stackexchange.identityservice.services.IdentityService;
import org.stackexchange.identityservice.services.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet{

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html");

request.setAttribute("testVariable", "tess");
request.getRequestDispatcher("login.jsp").forward(request, response);
}

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String email = request.getParameter("email");
String password = request.getParameter("password");

UserService userService = new UserService();
UserDao userDao = new UserDao();
IdentityService identityService = new IdentityService();
if (!userService.emailExist(email)) {
request.setAttribute("flash", "Email is not registered");
request.getRequestDispatcher("login.jsp").forward(request, response);
} else if (!userService.emailPasswordValid(email, password)) {
request.setAttribute("flash", "Invalid password");
request.getRequestDispatcher("login.jsp").forward(request, response);
} else {
User user = userDao.getByEmail(email);
Token token = identityService.generateToken(user.getId());
response.sendRedirect("http://localhost:8080/stack_exchange_netbeans/index?token=" + token.getToken());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.stackexchange.identityservice.controller;

import org.stackexchange.identityservice.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RegisterServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html");
request.getRequestDispatcher("register.jsp").forward(request, response);
}

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
UserDao userDao = new UserDao();

String email = request.getParameter("email");
if (!userDao.emailExist(email)) {
userDao.insertUser(request.getParameter("name"), request.getParameter("email"), request.getParameter("password"));
response.sendRedirect("/login");
} else {
request.setAttribute("flash", "tess");
response.setContentType("text/html");
request.getRequestDispatcher("register.jsp").forward(request, response);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.stackexchange.identityservice.controller;

import org.stackexchange.identityservice.dao.TokenDao;
import org.stackexchange.identityservice.dao.UserDao;
import org.stackexchange.identityservice.model.User;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class TokenCheckApiServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
String token = request.getParameter("token");
response.setContentType("application/json");

TokenDao tokenDao = new TokenDao();
boolean exist = tokenDao.existByToken(token);

try {
PrintWriter out = response.getWriter();
out.print(String.valueOf(exist));
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.stackexchange.identityservice.controller;

import org.stackexchange.identityservice.dao.TokenDao;
import org.stackexchange.identityservice.dao.UserDao;
import org.stackexchange.identityservice.model.User;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UserApiServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
String token = request.getParameter("token");
response.setContentType("application/json");

TokenDao tokenDao = new TokenDao();
UserDao userDao = new UserDao();
long userId = tokenDao.getFromToken(token).getUserId();
User user = userDao.getById(userId);

try {
PrintWriter out = response.getWriter();
out.print(user.getName());
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.stackexchange.identityservice.controller;

import org.stackexchange.identityservice.dao.TokenDao;
import org.stackexchange.identityservice.dao.UserDao;
import org.stackexchange.identityservice.model.User;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UserIdApiServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
String token = request.getParameter("token");
response.setContentType("application/json");

TokenDao tokenDao = new TokenDao();
UserDao userDao = new UserDao();
long userId = tokenDao.getFromToken(token).getUserId();
User user = userDao.getById(userId);

try {
PrintWriter out = response.getWriter();
out.print(user.getId());
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.stackexchange.identityservice.controller;

import com.google.gson.Gson;
import org.stackexchange.identityservice.dao.UserDao;
import org.stackexchange.identityservice.model.User;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

public class UserInfoApiServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
int id = Integer.valueOf(request.getParameter("id"));

UserDao userDao = new UserDao();
User user = userDao.getById(id);

Map<String, String> userInfo = new HashMap<>();
userInfo.put("name", user.getName());
userInfo.put("email", user.getEmail());

Gson gson = new Gson();
String json = gson.toJson(userInfo);

try {
PrintWriter out = response.getWriter();
out.print(json);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.stackexchange.identityservice.core;

import javax.servlet.http.HttpServlet;

public class Controller extends HttpServlet {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.stackexchange.identityservice.core;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MySQLDao {

final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
final String DB_URL = "jdbc:mysql://localhost:3306/stack_exchange_2";

final String USER = "root";
final String PASS = "";

protected Connection conn = null;

protected void getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection(DB_URL, USER, PASS);
} catch(SQLException se) {
se.printStackTrace();
} catch(ClassNotFoundException e) {
e.printStackTrace();
}
}

protected void closeConnection() {
try {
if(conn != null) {
conn.close();
}
} catch(SQLException se) {
se.printStackTrace();
}
}
}
Loading