diff --git a/src/lib/mysql-connector-java-5.1.9.jar b/src/lib/mysql-connector-java-5.1.9.jar
new file mode 100644
index 0000000..275c28d
Binary files /dev/null and b/src/lib/mysql-connector-java-5.1.9.jar differ
diff --git a/src/src/com/ruserba/model/Category.java b/src/src/com/ruserba/model/Category.java
new file mode 100644
index 0000000..95933c3
--- /dev/null
+++ b/src/src/com/ruserba/model/Category.java
@@ -0,0 +1,22 @@
+package com.ruserba.model;
+
+public class Category implements java.io.Serializable {
+
+ private int id_kategori;
+ private String nama_kategori;
+
+ public int getIdKategori(){
+ return this.id_kategori;
+ }
+ public void setIdKategori(int id_kategori){
+ this.id_kategori = id_kategori;
+ }
+
+ public String getNamaKategori(){
+ return this.nama_kategori;
+ }
+ public void setNamaKategori(String nama_kategori){
+ this.nama_kategori = nama_kategori;
+ }
+
+}
\ No newline at end of file
diff --git a/src/src/com/ruserba/model/Database.java b/src/src/com/ruserba/model/Database.java
new file mode 100644
index 0000000..3481a27
--- /dev/null
+++ b/src/src/com/ruserba/model/Database.java
@@ -0,0 +1,243 @@
+package com.ruserba.model;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+
+import java.util.ArrayList;
+
+public class Database {
+
+ public static final int COMP_LT = 1;
+ public static final int COMP_LTE = 2;
+ public static final int COMP_GT = 3;
+ public static final int COMP_GTE = 4;
+ public static final int SORT_ASC = 1;
+ public static final int SORT_DESC = 2;
+ public static final int ORDERBY_PRODUCTNAME = 1;
+ public static final int ORDERBY_PRICE = 2;
+ public static final int ORDERBY_SOLDQTY = 3;
+
+ private Connection conn = null;
+
+ public Database(String url, String user_name, String password)
+ {
+ try {
+ Class.forName("com.mysql.jdbc.Driver");
+ this.conn = DriverManager.getConnection(url, user_name, password);
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ // Untuk custom query.
+ public Connection getConnection()
+ {
+ return this.conn;
+ }
+
+ // Untuk custom query.
+ // Not recommended. Sebaiknya menggunakan getConnection() + prepared statement.
+ public ResultSet runQuery(String sql) throws SQLException
+ {
+ Statement sta = conn.createStatement();
+ return sta.executeQuery(sql);
+ }
+
+ private Product getProductDataFromResultSet(ResultSet res) throws SQLException
+ {
+ // Id produk tidak ditemukan.
+ if (!res.next()) return null;
+
+ // Dikuli... Semoga nggak ada typo... :p
+ Product prod = new Product();
+ prod.setIdBarang(res.getInt("id_barang"));
+ prod.setIdKategori(res.getInt("id_kategori"));
+ prod.setHarga(res.getInt("harga"));
+ prod.setJumlahPembelian(res.getInt("jumlah_pembelian"));
+ prod.setJumlahStok(res.getInt("jumlah_stok"));
+ prod.setNamaBarang(res.getString("nama_barang"));
+ prod.setSatuan(res.getString("satuan"));
+ prod.setDeskripsi(res.getString("deskripsi"));
+ prod.setNamaGambar(res.getString("nama_gambar"));
+ prod.setNamaGambarThumb(res.getString("nama_gambar_thumb"));
+
+ return prod;
+ }
+
+ // Mengambil seluruh data produk.
+ public Product getProductData(int product_id) throws SQLException
+ {
+ PreparedStatement stat = getConnection().prepareStatement("select * from barang where id_barang=?");
+ stat.setInt(1, product_id);
+ ResultSet res = stat.executeQuery();
+
+ return getProductDataFromResultSet(res);
+ }
+
+ private User getUserDataFromResultSet(ResultSet res) throws SQLException {
+ // Id produk tidak ditemukan.
+ if (!res.next()) return null;
+
+ // Dikuli... Lagi...
+ User user = new User();
+ user.setIdUser(res.getInt("id_user"));
+ user.setUsername(res.getString("username"));
+ user.setEmail(res.getString("email"));
+ user.setPassword(res.getString("password"));
+ user.setNamaLengkap(res.getString("nama_lengkap"));
+ user.setProvinsi(res.getString("provinsi"));
+ user.setKota(res.getString("kota"));
+ user.setAlamat(res.getString("alamat"));
+ user.setKodePos(res.getString("kode_pos"));
+ user.setKontak(res.getString("kontak"));
+ user.setNomorKartu(res.getString("nomor_kartu"));
+ user.setNamaKartu(res.getString("nama_kartu"));
+ user.setEkspirasiKartu(res.getString("ekspirasi_kartu"));
+
+ return user;
+ }
+
+ public User getUserData(int user_id) throws SQLException
+ {
+ PreparedStatement stat = getConnection().prepareStatement("select * from user where id_user=?");
+ stat.setInt(1, user_id);
+ ResultSet res = stat.executeQuery();
+
+ return getUserDataFromResultSet(res);
+ }
+
+ public User getUserDataFromUsername(String username) throws SQLException
+ {
+ PreparedStatement stat = getConnection().prepareStatement("select * from user where username=?");
+ stat.setString(1, username);
+ ResultSet res = stat.executeQuery();
+
+ return getUserDataFromResultSet(res);
+ }
+
+ public Category getCategoryData(int category_id) throws SQLException
+ {
+ PreparedStatement stat = getConnection().prepareStatement("select * from kategori where id_kategori=?");
+ stat.setInt(1, category_id);
+ ResultSet res = stat.executeQuery();
+
+ // Id produk tidak ditemukan.
+ if (!res.next()) return null;
+
+ // Dikuli... Lagi...
+ Category cat = new Category();
+ cat.setIdKategori(res.getInt("id_kategori"));
+ cat.setNamaKategori(res.getString("nama_kategori"));
+
+ return cat;
+ }
+
+ public ArrayList getCategory() throws SQLException
+ {
+ PreparedStatement stat = getConnection().prepareStatement("select * from kategori");
+ ResultSet res = stat.executeQuery();
+
+ ArrayList lst = new ArrayList();
+ while (res.next())
+ {
+ Category cat = new Category();
+ cat.setIdKategori(res.getInt("id_kategori"));
+ cat.setNamaKategori(res.getString("nama_kategori"));
+ lst.add(cat);
+ }
+ return lst;
+ }
+
+ private String getComparisonString(int compare_id)
+ {
+ if (compare_id == COMP_LT) return "<";
+ else if (compare_id == COMP_LTE) return "<=";
+ else if (compare_id == COMP_GT) return ">";
+ else if (compare_id == COMP_GTE) return ">=";
+ else return "<";
+ }
+
+ // Diasumsikan query sudah sesuai spesifikasi.
+ public ArrayList getProductSearchResult(SearchAttribute attr) throws SQLException
+ {
+ StringBuilder qb = new StringBuilder();
+
+ qb.append("select * from barang ");
+
+ ArrayList query_where_lst = new ArrayList();
+ if (!attr.getNamaBarang().equals(""))
+ query_where_lst.add("nama_barang like (\'%" + attr.getNamaBarang() + "%\')");
+ if (attr.getIdKategori() > 0)
+ query_where_lst.add("id_kategori = " + attr.getIdKategori());
+ if (attr.getIdPerbandingan() > 0 && attr.getHarga() >= 0)
+ query_where_lst.add("harga " + getComparisonString(attr.getIdPerbandingan()) + " " + attr.getHarga());
+
+ // Buat query where.
+ StringBuilder query_where_strb = new StringBuilder();
+ for (int i = 0; i < query_where_lst.size(); i++)
+ {
+ if (i != 0) query_where_strb.append(" and ");
+ query_where_strb.append(query_where_lst.get(i));
+ }
+ String query_where = query_where_strb.toString();
+
+ ArrayList query_end_lst = new ArrayList();
+ String sort_attr;
+ if (attr.getIdPengurutan() == ORDERBY_PRODUCTNAME) sort_attr = "nama_barang";
+ else if (attr.getIdPengurutan() == ORDERBY_PRICE) sort_attr = "harga";
+ else if (attr.getIdPengurutan() == ORDERBY_SOLDQTY) sort_attr = "jumlah_pembelian";
+ else sort_attr = "nama_barang";
+ query_end_lst.add("order by " + sort_attr);
+
+ String sort_method;
+ if (attr.getIdMetodePengurutan() == SORT_DESC) sort_method = "desc";
+ else sort_method = "asc";
+ query_end_lst.add(sort_method);
+
+ if (attr.getJumlah() < 0) attr.setJumlah(2147483647);
+ query_end_lst.add("limit " + attr.getIndeks() + ", " + attr.getJumlah());
+
+ // Buat query end.
+ StringBuilder query_end_strb = new StringBuilder();
+ for (int i = 0; i < query_end_lst.size(); i++)
+ {
+ if (i != 0) query_end_strb.append(" ");
+ query_end_strb.append(query_end_lst.get(i));
+ }
+ String query_end = query_end_strb.toString();
+
+ // Append query where.
+ if (query_where_lst.size() > 0) qb.append("where " + query_where + " ");
+
+ // Tambahkan akhir query.
+ qb.append(query_end);
+
+ // Ambil hasil dari query.
+ String final_query = qb.toString();
+
+ //return final_query;
+
+ PreparedStatement stat = getConnection().prepareStatement(final_query);
+ ResultSet res = stat.executeQuery();
+
+ ArrayList prod_list = new ArrayList();
+
+ while (true)
+ {
+ Product prod = getProductDataFromResultSet(res);
+ if (prod == null) break;
+ prod_list.add(prod);
+ }
+
+ return prod_list;
+ }
+
+}
diff --git a/src/src/com/ruserba/model/Product.java b/src/src/com/ruserba/model/Product.java
new file mode 100644
index 0000000..1ee1c44
--- /dev/null
+++ b/src/src/com/ruserba/model/Product.java
@@ -0,0 +1,86 @@
+package com.ruserba.model;
+
+public class Product implements java.io.Serializable {
+
+ private int id_barang;
+ private int id_kategori;
+ private String nama_barang;
+ private int harga;
+ private String satuan;
+ private String deskripsi;
+ private int jumlah_pembelian;
+ private int jumlah_stok;
+ private String nama_gambar;
+ private String nama_gambar_thumb;
+
+ public int getIdBarang(){
+ return this.id_barang;
+ }
+ public void setIdBarang(int id_barang){
+ this.id_barang = id_barang;
+ }
+
+ public int getIdKategori(){
+ return this.id_kategori;
+ }
+ public void setIdKategori(int id_kategori){
+ this.id_kategori = id_kategori;
+ }
+
+ public int getHarga(){
+ return this.harga;
+ }
+ public void setHarga(int harga){
+ this.harga = harga;
+ }
+
+ public int getJumlahPembelian(){
+ return this.jumlah_pembelian;
+ }
+ public void setJumlahPembelian(int jumlah_pembelian){
+ this.jumlah_pembelian = jumlah_pembelian;
+ }
+
+ public int getJumlahStok(){
+ return this.jumlah_stok;
+ }
+ public void setJumlahStok(int jumlah_stok){
+ this.jumlah_stok = jumlah_stok;
+ }
+
+ public String getNamaBarang(){
+ return this.nama_barang;
+ }
+ public void setNamaBarang(String nama_barang){
+ this.nama_barang = nama_barang;
+ }
+
+ public String getSatuan(){
+ return this.satuan;
+ }
+ public void setSatuan(String satuan){
+ this.satuan = satuan;
+ }
+
+ public String getDeskripsi(){
+ return this.deskripsi;
+ }
+ public void setDeskripsi(String deskripsi){
+ this.deskripsi = deskripsi;
+ }
+
+ public String getNamaGambar(){
+ return this.nama_gambar;
+ }
+ public void setNamaGambar(String nama_gambar){
+ this.nama_gambar = nama_gambar;
+ }
+
+ public String getNamaGambarThumb(){
+ return this.nama_gambar_thumb;
+ }
+ public void setNamaGambarThumb(String nama_gambar_thumb){
+ this.nama_gambar_thumb = nama_gambar_thumb;
+ }
+
+}
\ No newline at end of file
diff --git a/src/src/com/ruserba/model/SearchAttribute.java b/src/src/com/ruserba/model/SearchAttribute.java
new file mode 100644
index 0000000..99d1391
--- /dev/null
+++ b/src/src/com/ruserba/model/SearchAttribute.java
@@ -0,0 +1,71 @@
+package com.ruserba.model;
+
+public class SearchAttribute implements java.io.Serializable {
+
+ private String nama_barang; // tidak ada = empty string.
+ private int id_kategori; // Semua kategori dicari = 0.
+ private int harga; // Tidak ada harga = (< 0).
+ private int id_perbandingan; // <, <=, >, <=; 0 jika tidak ada harga.
+ private int id_pengurutan; // Id product name, id harga; 1 (product name) default.
+ private int id_metode_pengurutan; // Ascending, descending; 1 (ascending) default.
+ private int indeks; // Indeks awal yang ditampilkan pada hasil query; 0 default.
+ private int jumlah; // Jumlah record yang ditampilkan; 3 default.
+
+ public String getNamaBarang(){
+ return this.nama_barang;
+ }
+ public void setNamaBarang(String nama_barang){
+ this.nama_barang = nama_barang;
+ }
+
+ public int getIdKategori(){
+ return this.id_kategori;
+ }
+ public void setIdKategori(int id_kategori){
+ this.id_kategori = id_kategori;
+ }
+
+ public int getHarga(){
+ return this.harga;
+ }
+ public void setHarga(int harga){
+ this.harga = harga;
+ }
+
+ public int getIdPerbandingan(){
+ return this.id_perbandingan;
+ }
+ public void setIdPerbandingan(int id_perbandingan){
+ this.id_perbandingan = id_perbandingan;
+ }
+
+ public int getIdPengurutan(){
+ return this.id_pengurutan;
+ }
+ public void setIdPengurutan(int id_pengurutan){
+ this.id_pengurutan = id_pengurutan;
+ }
+
+ public int getIdMetodePengurutan(){
+ return this.id_metode_pengurutan;
+ }
+ public void setIdMetodePengurutan(int id_metode_pengurutan){
+ this.id_metode_pengurutan = id_metode_pengurutan;
+ }
+
+ public int getIndeks(){
+ return this.indeks;
+ }
+ public void setIndeks(int indeks){
+ this.indeks = indeks;
+ }
+
+ public int getJumlah(){
+ return this.jumlah;
+ }
+ public void setJumlah(int jumlah){
+ this.jumlah = jumlah;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/src/com/ruserba/model/User.java b/src/src/com/ruserba/model/User.java
new file mode 100644
index 0000000..636e284
--- /dev/null
+++ b/src/src/com/ruserba/model/User.java
@@ -0,0 +1,118 @@
+package com.ruserba.model;
+
+public class User implements java.io.Serializable {
+
+ private int id_user;
+ private String username;
+ private String email;
+ private String password; // ??!
+ private String nama_lengkap;
+ private String provinsi;
+ private String kota;
+ private String alamat;
+ private String kode_pos;
+ private String kontak;
+ private String nomor_kartu;
+ private String nama_kartu;
+ private String ekspirasi_kartu;
+ private boolean admin;
+
+ public int getIdUser(){
+ return this.id_user;
+ }
+ public void setIdUser(int id_user){
+ this.id_user = id_user;
+ }
+
+ public String getUsername(){
+ return this.username;
+ }
+ public void setUsername(String username){
+ this.username = username;
+ }
+
+ public String getEmail(){
+ return this.email;
+ }
+ public void setEmail(String email){
+ this.email = email;
+ }
+
+ public String getPassword(){
+ return this.password;
+ }
+ public void setPassword(String password){
+ this.password = password;
+ }
+
+ public String getNamaLengkap(){
+ return this.nama_lengkap;
+ }
+ public void setNamaLengkap(String nama_lengkap){
+ this.nama_lengkap = nama_lengkap;
+ }
+
+ public String getProvinsi(){
+ return this.provinsi;
+ }
+ public void setProvinsi(String provinsi){
+ this.provinsi = provinsi;
+ }
+
+ public String getKota(){
+ return this.kota;
+ }
+ public void setKota(String kota){
+ this.kota = kota;
+ }
+
+ public String getAlamat(){
+ return this.alamat;
+ }
+ public void setAlamat(String alamat){
+ this.alamat = alamat;
+ }
+
+ public String getKodePos(){
+ return this.kode_pos;
+ }
+ public void setKodePos(String kode_pos){
+ this.kode_pos = kode_pos;
+ }
+
+ public String getKontak(){
+ return this.kontak;
+ }
+ public void setKontak(String kontak){
+ this.kontak = kontak;
+ }
+
+ public String getNomorKartu(){
+ return this.nomor_kartu;
+ }
+ public void setNomorKartu(String nomor_kartu){
+ this.nomor_kartu = nomor_kartu;
+ }
+
+ public String getNamaKartu(){
+ return this.nama_kartu;
+ }
+ public void setNamaKartu(String nama_kartu){
+ this.nama_kartu = nama_kartu;
+ }
+
+ public String getEkspirasiKartu(){
+ return this.ekspirasi_kartu;
+ }
+ public void setEkspirasiKartu(String ekspirasi_kartu){
+ this.ekspirasi_kartu = ekspirasi_kartu;
+ }
+
+ public boolean getAdmin() {
+ return this.admin;
+ }
+ public void setAdmin(boolean admin){
+ this.admin = admin;
+ }
+
+}
diff --git a/src/src/com/ruserba/web/CheckUsernameService.java b/src/src/com/ruserba/web/CheckUsernameService.java
new file mode 100644
index 0000000..a723e1f
--- /dev/null
+++ b/src/src/com/ruserba/web/CheckUsernameService.java
@@ -0,0 +1,53 @@
+package com.ruserba.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.security.MessageDigest;
+import java.sql.SQLException;
+
+import com.ruserba.model.Database;
+import com.ruserba.model.User;
+import com.ruserba.web.WebUtil;
+
+public class CheckUsernameService extends HttpServlet
+{
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ {
+ response.setContentType("text/plain");
+
+ PrintWriter out = null;
+ try {
+ out = response.getWriter();
+ }
+ catch (Exception ex) {}
+
+ String username = request.getParameter("username");
+ String msg;
+
+ if (username != null)
+ {
+ Database db = WebUtil.getDatabase(getServletContext());
+
+ User user = null;
+ try
+ {
+ user = db.getUserDataFromUsername(username);
+ }
+ catch(Exception ex) {}
+
+ if (user != null) msg = "1";
+ else msg = "0";
+ }
+ else
+ {
+ msg = "0";
+ }
+
+ out.write(msg + "\n");
+
+ }
+}
diff --git a/src/src/com/ruserba/web/CobaServlet.java b/src/src/com/ruserba/web/CobaServlet.java
new file mode 100644
index 0000000..e162782
--- /dev/null
+++ b/src/src/com/ruserba/web/CobaServlet.java
@@ -0,0 +1,56 @@
+package com.ruserba.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.security.MessageDigest;
+import java.sql.SQLException;
+
+import com.ruserba.model.Database;
+import com.ruserba.model.User;
+import com.ruserba.model.SearchAttribute;
+import com.ruserba.web.WebUtil;
+
+public class CobaServlet extends HttpServlet
+{
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ {
+ response.setContentType("text/plain");
+
+ PrintWriter out = null;
+ try {
+ out = response.getWriter();
+ }
+ catch (Exception ex) {}
+
+ out.write("Hello");
+
+ Database db = WebUtil.getDatabase(getServletContext());
+
+ SearchAttribute attr = new SearchAttribute();
+
+ /*
+ attr.setNamaBarang("tomat");
+ attr.setIdKategori(2);
+ attr.setHarga(3143);
+ attr.setIdPerbandingan(2);
+ attr.setIdPengurutan(Database.ORDERBY_PRODUCTNAME);
+ attr.setIdMetodePengurutan(Database.SORT_ASC);
+ attr.setIndeks(0);
+ attr.setJumlah(5);
+ */
+
+ attr.setNamaBarang("");
+ attr.setIdKategori(3);
+ attr.setHarga(-1);
+ attr.setIdPerbandingan(0);
+ attr.setIdPengurutan(Database.ORDERBY_SOLDQTY);
+ attr.setIdMetodePengurutan(Database.SORT_DESC);
+ attr.setIndeks(0);
+ attr.setJumlah(3);
+
+ }
+}
diff --git a/src/src/com/ruserba/web/DatabaseInit.java b/src/src/com/ruserba/web/DatabaseInit.java
new file mode 100644
index 0000000..2b54ee8
--- /dev/null
+++ b/src/src/com/ruserba/web/DatabaseInit.java
@@ -0,0 +1,26 @@
+package com.ruserba.web;
+
+import com.ruserba.model.Database;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public class DatabaseInit implements ServletContextListener {
+
+ public void contextInitialized(ServletContextEvent event) {
+ ServletContext sc = event.getServletContext();
+
+ String db_url = sc.getInitParameter("db_url");
+ String db_username = sc.getInitParameter("db_username");
+ String db_password = sc.getInitParameter("db_password");
+ String db_name = sc.getInitParameter("db_name");
+ Database db = new Database(db_url + db_name, db_username, db_password);
+ sc.setAttribute("db", db);
+ }
+
+ public void contextDestroyed(ServletContextEvent arg0) {
+
+ }
+
+}
diff --git a/src/src/com/ruserba/web/LoginService.java b/src/src/com/ruserba/web/LoginService.java
new file mode 100644
index 0000000..508ecb4
--- /dev/null
+++ b/src/src/com/ruserba/web/LoginService.java
@@ -0,0 +1,87 @@
+package com.ruserba.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.security.MessageDigest;
+import java.sql.SQLException;
+
+import com.ruserba.model.Database;
+import com.ruserba.model.User;
+import com.ruserba.web.WebUtil;
+
+public class LoginService extends HttpServlet
+{
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ {
+ response.setContentType("text/plain");
+
+ PrintWriter out = null;
+ try {
+ out = response.getWriter();
+ }
+ catch (Exception ex) {}
+
+ String username = request.getParameter("username"); if (username == null) username = "";
+ String password = request.getParameter("password"); if (password == null) password = "";
+ Database db = WebUtil.getDatabase(getServletContext());
+
+ String msg_out;
+
+ User user;
+ try
+ {
+ user = db.getUserDataFromUsername(username);
+ }
+ catch(Exception ex)
+ {
+ user = null;
+ }
+
+ if (user != null)
+ {
+ MessageDigest md = null;
+ try
+ {
+ md = MessageDigest.getInstance("MD5");
+ }
+ catch(Exception ex)
+ {
+ md = null;
+ }
+ md.update(password.getBytes());
+ byte pass_byte[] = md.digest();
+
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < pass_byte.length; i++) {
+ sb.append(Integer.toString((pass_byte[i] & 0xff) + 0x100, 16).substring(1));
+ }
+
+ String password_hash = sb.toString();
+
+ if (password_hash.equals(user.getPassword()))
+ {
+ Cookie id_cookie = new Cookie("id_user", Integer.toString(user.getIdUser())); // Bad practice, but who cares? :p
+ id_cookie.setPath("/"); id_cookie.setMaxAge(2592000);
+ response.addCookie(id_cookie);
+
+ Cookie username_cookie = new Cookie("username", user.getUsername()); // Bad practice, but who cares? :p
+ username_cookie.setPath("/"); username_cookie.setMaxAge(2592000);
+ response.addCookie(username_cookie);
+ msg_out = "1";
+ }
+ else
+ {
+ msg_out = "0";
+ }
+ }
+ else
+ {
+ msg_out = "0";
+ }
+ out.write(msg_out + "\n"); // No JSON, no XML, just pure "linebreak separated"...
+ }
+}
diff --git a/src/src/com/ruserba/web/RegisterUserService.java b/src/src/com/ruserba/web/RegisterUserService.java
new file mode 100644
index 0000000..a2a981d
--- /dev/null
+++ b/src/src/com/ruserba/web/RegisterUserService.java
@@ -0,0 +1,93 @@
+package com.ruserba.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.security.MessageDigest;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+
+import com.ruserba.model.Database;
+import com.ruserba.model.User;
+import com.ruserba.web.WebUtil;
+
+public class RegisterUserService extends HttpServlet
+{
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ {
+ response.setContentType("text/plain");
+
+ /*PrintWriter out = null;
+ try {
+ out = response.getWriter();
+ }
+ catch (Exception ex) {}
+
+ out.write("Hello");*/
+
+ MessageDigest md = null;
+ try {
+ md = MessageDigest.getInstance("MD5");
+ } catch (Exception ex) {}
+ md.update(request.getParameter("password").getBytes());
+
+ byte byteData[] = md.digest();
+
+ //convert the byte to hex format method 1
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < byteData.length; i++)
+ {
+ sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
+ }
+ String pass_enc = sb.toString();
+
+ // Ambil data.
+
+ User user = new User();
+ user.setUsername(request.getParameter("username"));
+ user.setEmail(request.getParameter("email"));
+ user.setPassword(pass_enc);
+ user.setNamaLengkap(request.getParameter("namaLengkap"));
+ user.setProvinsi(request.getParameter("provinsi"));
+ user.setKota(request.getParameter("kota"));
+ user.setAlamat(request.getParameter("alamat"));
+ user.setKodePos(request.getParameter("kodePos"));
+ user.setKontak(request.getParameter("kontak"));
+
+ Database db = WebUtil.getDatabase(getServletContext());
+
+ PreparedStatement stat = null;
+ try
+ {
+ stat = db.getConnection().prepareStatement("insert into user(username, email, password, nama_lengkap, provinsi, kota, alamat, kode_pos, kontak, admin) " +
+ "values (?, ?, ?, ?, ?, ?, ?, ?, ?, 0)");
+
+ stat.setString(1, user.getUsername());
+ stat.setString(2, user.getEmail());
+ stat.setString(3, user.getPassword());
+ stat.setString(4, user.getNamaLengkap());
+ stat.setString(5, user.getProvinsi());
+ stat.setString(6, user.getKota());
+ stat.setString(7, user.getAlamat());
+ stat.setString(8, user.getKodePos());
+ stat.setString(9, user.getKontak());
+ stat.executeUpdate();
+ }
+ catch (Exception ex) {}
+
+ Cookie id_cookie = new Cookie("id_user", Integer.toString(user.getIdUser())); // Bad practice, but who cares? :p
+ id_cookie.setPath("/"); id_cookie.setMaxAge(2592000);
+ response.addCookie(id_cookie);
+
+ Cookie username_cookie = new Cookie("username", user.getUsername()); // Bad practice, but who cares? :p
+ username_cookie.setPath("/"); username_cookie.setMaxAge(2592000);
+ response.addCookie(username_cookie);
+ }
+}
diff --git a/src/src/com/ruserba/web/WebUtil.java b/src/src/com/ruserba/web/WebUtil.java
new file mode 100644
index 0000000..b330a07
--- /dev/null
+++ b/src/src/com/ruserba/web/WebUtil.java
@@ -0,0 +1,51 @@
+package com.ruserba.web;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.sql.SQLException;
+
+import com.ruserba.model.Database;
+
+public class WebUtil
+{
+ public static boolean isLoggedIn(ServletContext context, HttpServletRequest request) throws SQLException
+ {
+ Cookie[] cookies = request.getCookies();
+ int user_id;
+ if (cookies != null)
+ {
+ for (int i = 0; i < cookies.length; i++)
+ {
+ if (cookies[i].getName().equals("id_user"))
+ {
+ user_id = Integer.parseInt(cookies[i].getValue());
+
+ // Periksa kebenaran user ID.
+ Database db = getDatabase(context);
+ if (db.getUserData(user_id) != null) return true;
+ else return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static Database getDatabase(ServletContext context)
+ {
+ return (Database)context.getAttribute("db");
+ }
+
+ public static String getProductImagePath(String product_image_filename)
+ {
+ return "images/products/" + product_image_filename;
+ }
+
+ public static String getProductPage(int product_id)
+ {
+ return "product.jsp?product_id=" + product_id;
+ }
+
+}
diff --git a/src/web/admin.jsp b/src/web/admin.jsp
new file mode 100644
index 0000000..32488d1
--- /dev/null
+++ b/src/web/admin.jsp
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
HALAMAN KONTROL ADMIN
+ Tampilkan Daftar Barang
+
+ Modifikasi Daftar Barang
+
+ Tambah/Hapus Daftar Barang
+
+
\ No newline at end of file
diff --git a/src/web/adminadd.jsp b/src/web/adminadd.jsp
new file mode 100644
index 0000000..f2b251d
--- /dev/null
+++ b/src/web/adminadd.jsp
@@ -0,0 +1,42 @@
+<%@ page import="java.io.*,java.util.*,java.sql.*"%>
+<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
+
+
+
+Tambah Entri Barang
+
+
+
+Tambah entri barang, tanda * berarti wajib diisi
+