diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c16ac0bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/SImpleBlog/nbproject/private/ +/SImpleBlog/build/ +/SImpleBlog/dist/ \ No newline at end of file diff --git a/SImpleBlog/build.xml b/SImpleBlog/build.xml new file mode 100644 index 00000000..a4e0212b --- /dev/null +++ b/SImpleBlog/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project SImpleBlog. + + + diff --git a/SImpleBlog/lib/mysql-connector-java-5.1.23-bin.jar b/SImpleBlog/lib/mysql-connector-java-5.1.23-bin.jar new file mode 100644 index 00000000..dd2585e0 Binary files /dev/null and b/SImpleBlog/lib/mysql-connector-java-5.1.23-bin.jar differ diff --git a/SImpleBlog/nbproject/ant-deploy.xml b/SImpleBlog/nbproject/ant-deploy.xml new file mode 100644 index 00000000..2d5f8778 --- /dev/null +++ b/SImpleBlog/nbproject/ant-deploy.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SImpleBlog/nbproject/build-impl.xml b/SImpleBlog/nbproject/build-impl.xml new file mode 100644 index 00000000..5677753b --- /dev/null +++ b/SImpleBlog/nbproject/build-impl.xml @@ -0,0 +1,1446 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SImpleBlog/nbproject/build-impl.xml~ b/SImpleBlog/nbproject/build-impl.xml~ new file mode 100644 index 00000000..7cc2f71b --- /dev/null +++ b/SImpleBlog/nbproject/build-impl.xml~ @@ -0,0 +1,1444 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SImpleBlog/nbproject/genfiles.properties b/SImpleBlog/nbproject/genfiles.properties new file mode 100644 index 00000000..8705ea4d --- /dev/null +++ b/SImpleBlog/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=93d3ec77 +build.xml.script.CRC32=005214f9 +build.xml.stylesheet.CRC32=651128d4@1.65.1.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=93d3ec77 +nbproject/build-impl.xml.script.CRC32=c2ad6026 +nbproject/build-impl.xml.stylesheet.CRC32=d659eb7a@1.65.1.1 diff --git a/SImpleBlog/nbproject/project.properties b/SImpleBlog/nbproject/project.properties new file mode 100644 index 00000000..796b938c --- /dev/null +++ b/SImpleBlog/nbproject/project.properties @@ -0,0 +1,93 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +auxiliary.org-netbeans-modules-projectapi.jsf_2e_language=Facelets +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +# Files to be excluded from distribution war +dist.archive.excludes= +dist.dir=dist +dist.ear.war=${dist.dir}/${war.ear.name} +dist.javadoc.dir=${dist.dir}/javadoc +dist.war=${dist.dir}/${war.name} +endorsed.classpath=\ + ${libs.javaee-endorsed-api-6.0.classpath} +excludes= +file.reference.mysql-connector-java-5.1.23-bin.jar=lib\\mysql-connector-java-5.1.23-bin.jar +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.7-web +j2ee.platform.classpath=${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar +j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar +j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar +j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar +j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar +j2ee.platform.wsit.classpath= +j2ee.server.type=gfv3ee6 +jar.compress=false +javac.classpath=\ + ${libs.mysql connector.classpath}:\ + ${libs.my connector.classpath}:\ + ${file.reference.mysql-connector-java-5.1.23-bin.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=SImpleBlog.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/SImpleBlog/nbproject/project.xml b/SImpleBlog/nbproject/project.xml new file mode 100644 index 00000000..a5dc3947 --- /dev/null +++ b/SImpleBlog/nbproject/project.xml @@ -0,0 +1,31 @@ + + + org.netbeans.modules.web.project + + + SImpleBlog + 1.6.5 + + + ${libs.mysql connector.classpath} + WEB-INF/lib + + + ${libs.my connector.classpath} + WEB-INF/lib + + + ${file.reference.mysql-connector-java-5.1.23-bin.jar} + WEB-INF/lib + + + + + + + + + + + + diff --git a/SImpleBlog/src/conf/MANIFEST.MF b/SImpleBlog/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/SImpleBlog/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/SImpleBlog/src/java/Database/EditPost.java b/SImpleBlog/src/java/Database/EditPost.java new file mode 100644 index 00000000..f6653b6d --- /dev/null +++ b/SImpleBlog/src/java/Database/EditPost.java @@ -0,0 +1,103 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.servlet.http.HttpServletRequest; + +/** + * + * @author Sakurai + */ +@ManagedBean(name = "Editpost", eager = true) +@SessionScoped +public class EditPost { + private int PostID; + + public EditPost(){ + + } + + public void setPostId(int PostID){ + this.PostID = PostID; + } + + public void Redirect(int PostID) throws IOException{ + setPostId(PostID); + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/EditPost.xhtml"); + } + + private Connection getConnection() throws ClassNotFoundException, SQLException, IllegalAccessException{ + Connection conn = null; + try{ + Class.forName("com.mysql.jdbc.Driver").newInstance(); + String url = "jdbc:mysql://localhost/blog"; + String user = "root"; + String password = ""; + conn = DriverManager.getConnection(url, user, password); + }catch(ClassNotFoundException | InstantiationException e){ + System.err.println(e); + } + return conn; + } + + public Post getPost() throws ClassNotFoundException, SQLException, IllegalAccessException{ + ResultSet result; + Post post = new Post(); + try{ + try (Connection conn = getConnection()) { + Statement stmt = conn.createStatement(); + String query = "Select * From post where ID = " + PostID + ";"; + result = stmt.executeQuery(query); + while(result.next()){ + post.setId(result.getInt(1)); + post.setJudul(result.getString(2)); + post.setTanggal(result.getString(3)); + post.setContent(result.getString(4)); + post.setAuthor(result.getString(5)); + post.setStatus(result.getString(6)); + } + } + + } catch(SQLException e){ + System.err.println(e); + } + + return post; + } + + public void editPostToDatabase() throws ClassNotFoundException, IllegalAccessException, IOException{ + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + String Judul = request.getParameter("Judul"); + String Konten = request.getParameter("Konten"); + + ResultSet result; + Post post = new Post(); + try{ + try (Connection conn = getConnection()) { + Statement stmt = conn.createStatement(); + String query = "Update post set Judul = \"" + Judul + "\", Content = \"" + Konten + "\" where ID = " + PostID + ";"; + stmt.executeUpdate(query); + } + + } catch(SQLException e){ + System.err.println(e); + } + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/Home.xhtml"); + } +} diff --git a/SImpleBlog/src/java/Database/Post.java b/SImpleBlog/src/java/Database/Post.java new file mode 100644 index 00000000..fe2798da --- /dev/null +++ b/SImpleBlog/src/java/Database/Post.java @@ -0,0 +1,78 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +/** + * + * @author Rikysamuel + */ +public class Post { + int Id; + String Judul; + String Tanggal; + String Content; + String Author; + String Status; + + public Post(){ + } + + public void setId(int Id) { + this.Id = Id; + } + + public int getId() { + return Id; + } + + public void setJudul(String Judul) { + this.Judul = Judul; + } + + public String getJudul() { + return Judul; + } + + public void setTanggal(String Tanggal) { + this.Tanggal = Tanggal; + } + + public String getTanggal() { + return Tanggal; + } + + public void setContent(String Content) { + this.Content = Content; + } + + public String getContent() { + return Content; + } + + public String getContentPreview(){ + if(Content.length() > 300) + return Content.substring(0, 300); + else + return Content; + } + + public String getAuthor() { + return Author; + } + + public void setAuthor(String Author) { + this.Author = Author; + } + + public void setStatus(String Status) { + this.Status = Status; + } + + public String getStatus() { + return Status; + } +} diff --git a/SImpleBlog/src/java/Database/PostingDatabase.java b/SImpleBlog/src/java/Database/PostingDatabase.java new file mode 100644 index 00000000..4a4c20d7 --- /dev/null +++ b/SImpleBlog/src/java/Database/PostingDatabase.java @@ -0,0 +1,626 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +import Login.Login; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.RequestScoped; +import javax.faces.bean.SessionScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + +/** + * + * @author Rikysamuel + */ +@ManagedBean(name="Posting", eager = true) +@RequestScoped +public class PostingDatabase { + + Login login; + String SelectedItem; + + @ManagedProperty(value="#{param.throwedauthor}") + private String author; + + @ManagedProperty(value ="#{param.throwedid}") + private int id; + + @ManagedProperty(value="#{param.throwediduser}") + private String username; + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getSelectedItem() { + return SelectedItem; + } + + public void setSelectedItem(String SelectedItem) { + this.SelectedItem = SelectedItem; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername(){ + return username; + } + + public void setUsername(String username){ + this.username = username; + } + + public PostingDatabase(){ + login = new Login(); + } + + public void toHome() throws IOException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + + public Connection makeConnection() throws ClassNotFoundException, SQLException{ + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + String url = "jdbc:mysql://localhost/blog"; + String user = "root"; + String password = ""; + con = DriverManager.getConnection(url,user,password); + return con; + } + + public List getPost() throws ClassNotFoundException{ + ResultSet rs; + Connection con; + List records = new ArrayList<>(); + try { + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select * from post where status=\"Published\""; + rs = stmt.executeQuery(query); + + while(rs.next()){ + Post post = new Post(); + post.setId(rs.getInt(1)); + post.setJudul(rs.getString(2)); + post.setTanggal(rs.getString(3)); + post.setContent(rs.getString(4)); + post.setAuthor(rs.getString(5)); + post.setStatus(rs.getString(6)); + records.add(post); + } + con.close(); + } catch (SQLException e) { + System.err.println(e); + } + return records; + } + + public List getAuthorPost() throws ClassNotFoundException{ + ResultSet rs; + Connection con; + List records = new ArrayList<>(); + try { + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select * from post where author=\""+login.getUserCookie().getValue()+"\" and status=\"published\";"; + rs = stmt.executeQuery(query); + + while(rs.next()){ + Post post = new Post(); + post.setId(rs.getInt(1)); + post.setJudul(rs.getString(2)); + post.setTanggal(rs.getString(3)); + post.setContent(rs.getString(4)); + post.setAuthor(rs.getString(5)); + post.setStatus(rs.getString(6)); + records.add(post); + } + con.close(); + } catch (SQLException e) { + System.err.println(e); + } + return records; + } + + public void addPost() throws ClassNotFoundException, SQLException, IOException, ParseException{ + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + String Judul = request.getParameter("Judul"); + String Tanggal = request.getParameter("Tanggal"); + String Konten = request.getParameter("Konten"); + ResultSet rs; + try (Connection con = makeConnection()) { + Statement stmt = con.createStatement(); + String query = "Select COUNT(Id) from post"; + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + java.util.Date parsed = format.parse(Tanggal); + java.sql.Date datesql = new java.sql.Date(parsed.getTime()); + + rs = stmt.executeQuery(query); + PreparedStatement ps; + int countsumId = 0; + while(rs.next()){ + countsumId = rs.getInt(1); + } + String query2 = "INSERT INTO post (Judul, Tanggal, Content, Author, Status) VALUES (?,?,?,?,?)"; + ps= con.prepareStatement(query2); + ps.setString(1,Judul); + ps.setDate(2,datesql); + ps.setString(3,Konten); + ps.setString(4,login.getUserCookie().getValue()); + ps.setString(5,"unpublished"); + int i = ps.executeUpdate(); + con.close(); + } + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/Home.xhtml"); + } + + public void deletePost() throws ClassNotFoundException, SQLException, IOException, ParseException{ + try (Connection con = makeConnection()) { + Statement stmt = con.createStatement(); + String query = "Update post Set status=\"deleted\" WHERE ID="+id; + int rs; + rs = stmt.executeUpdate(query); + con.close(); + } + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/Home.xhtml"); + } + + public void PublishPost() throws ClassNotFoundException, IOException, ParseException, SQLException{ + try (Connection con = makeConnection()){ + Statement stmt = con.createStatement(); + String query = "Update post Set status=\"published\" WHERE ID="+id; + int rs; + rs = stmt.executeUpdate(query); + PreparedStatement ps; + con.close(); + } + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/Home.xhtml"); + } + + public void setLoginOnLoad() throws ClassNotFoundException, SQLException, IOException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + Cookie cUsername = login.getUserCookie(); + Cookie cPassword = login.getPassCookie(); + if (cUsername!=null && cPassword!=null){ + ResultSet rs,rs2; + Connection con; + con = makeConnection(); + int existUser=0; + String UserRole = null; + Statement stmt = con.createStatement(); + String query = "Select COUNT(Username) from user where Username=\""+cUsername.getValue()+"\" and Password=\""+cPassword.getValue()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + existUser = rs.getInt(1); + if (existUser>0){ + if(getUserRole().equals("Editor")) + { + extCont.redirect("/SImpleBlog/Role/Editor.xhtml"); + } + if(getUserRole().equals("Owner")) + { + extCont.redirect("/SImpleBlog/Role/Owner.xhtml"); + } + if(getUserRole().equals("Admin")) + { + extCont.redirect("/SImpleBlog/Role/Admin.xhtml"); + } + } + else{ + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + con.close(); + } + + } + + public void Login() throws ClassNotFoundException, SQLException, IOException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + String Username = request.getParameter("login_username"); + String Password = request.getParameter("login_password"); + String UserRole = null; + ResultSet rs,rs2; + int existUser; + Connection con; + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select COUNT(Username) from user where Username=\""+Username+"\" and Password=\""+Password+"\";"; + rs = stmt.executeQuery(query); + + while(rs.next()){ + existUser = rs.getInt(1); + if(existUser>0){ + login.setCookie(Username,Password); + String query2 = "Select Role from user where Username=\""+Username+"\";"; + rs2 = stmt.executeQuery(query2); + while(rs2.next()){ + UserRole = rs2.getString("Role"); + if(UserRole.equals("Editor")) + { + extCont.redirect("/SImpleBlog/Role/Editor.xhtml"); + } + if(UserRole.equals("Owner")) + { + extCont.redirect("/SImpleBlog/Role/Owner.xhtml"); + } + if(UserRole.equals("Admin")) + { + extCont.redirect("/SImpleBlog/Role/Admin.xhtml"); + } + } + } + else{ + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + con.close(); + } + + public String getActiveUser() throws ClassNotFoundException, SQLException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + Cookie cUsername = login.getUserCookie(); + String activeUser = null; + + ResultSet rs; + Connection con; + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select Name from user where Username=\""+cUsername.getValue()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + activeUser = rs.getString("Name"); + } + con.close(); + return activeUser; + } + + public String getActiveUsername() throws ClassNotFoundException, SQLException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + Cookie cUsername = login.getUserCookie(); + String activeUsername = null; + + ResultSet rs; + Connection con; + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select Username from user where Username=\""+cUsername.getValue()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + activeUsername = rs.getString("Username"); + } + return activeUsername; + } + + public String getUserRole() throws ClassNotFoundException, SQLException{ + Cookie cUsername = login.getUserCookie(); + String UserRole = null; + + ResultSet rs; + Connection con; + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select Role from user where Username=\""+cUsername.getValue()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + UserRole = rs.getString("Role"); + } + con.close(); + return UserRole; + } + + public void setLogout() throws ClassNotFoundException, SQLException, IOException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + login.delUserCookie(); + login.delPassCookie(); + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + + public boolean getLoginState(){ + return(login.getUserCookie() != null); + } + + public String getActiveUserEmail() throws ClassNotFoundException, SQLException{ + Cookie cUsername = login.getUserCookie(); + String activeUserEmail = null; + + ResultSet rs; + Connection con; + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select email from user where Username=\""+cUsername.getValue()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + activeUserEmail = rs.getString("email"); + } + con.close(); + return activeUserEmail; + } + + public void checkAdminRole() throws ClassNotFoundException, SQLException, IOException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + if(getLoginState()) + { + Cookie cUsername = login.getUserCookie(); + Cookie cPassword = login.getPassCookie(); + if (cUsername!=null && cPassword!=null){ + ResultSet rs,rs2; + Connection con; + con = makeConnection(); + int existUser=0; + String UserRole = null; + Statement stmt = con.createStatement(); + String query = "Select COUNT(Username) from user where Username=\""+cUsername.getValue()+"\" and Password=\""+cPassword.getValue()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + existUser = rs.getInt(1); + if (existUser>0){ + if(!getUserRole().equals("Admin")) + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + else{ + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + con.close(); + } + else + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + else + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + + } + + public void CheckEditorRole() throws ClassNotFoundException, SQLException, IOException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + if(getLoginState()) + { + Cookie cUsername = login.getUserCookie(); + Cookie cPassword = login.getPassCookie(); + if (cUsername!=null && cPassword!=null){ + ResultSet rs,rs2; + Connection con; + con = makeConnection(); + int existUser=0; + String UserRole = null; + Statement stmt = con.createStatement(); + String query = "Select COUNT(Username) from user where Username=\""+cUsername.getValue()+"\" and Password=\""+cPassword.getValue()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + existUser = rs.getInt(1); + if (existUser>0){ + if(!getUserRole().equals("Editor")) + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + else{ + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + con.close(); + } + else + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + else + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + + } + + public void CheckOwnerRole() throws ClassNotFoundException, SQLException, IOException{ + ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); + if(getLoginState()) + { + Cookie cUsername = login.getUserCookie(); + Cookie cPassword = login.getPassCookie(); + if (cUsername!=null && cPassword!=null){ + ResultSet rs,rs2; + Connection con; + con = makeConnection(); + int existUser=0; + String UserRole = null; + Statement stmt = con.createStatement(); + String query = "Select COUNT(Username) from user where Username=\""+cUsername.getValue()+"\" and Password=\""+cPassword.getValue()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + existUser = rs.getInt(1); + if (existUser>0){ + if(!getUserRole().equals("Owner")) + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + else{ + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + con.close(); + } + else + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + else + { + extCont.redirect("/SImpleBlog/Home.xhtml"); + } + } + + public List getUsers() throws ClassNotFoundException, SQLException{ + List records = new ArrayList(); + + ResultSet rs; + Connection con; + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select * from user where Name<>\""+getActiveUser()+"\";"; + rs = stmt.executeQuery(query); + while(rs.next()){ + User user = new User(); + user.setUsername(rs.getString(1)); + user.setPassword(rs.getString(2)); + user.setName(rs.getString(3)); + user.setEmail(rs.getString(4)); + user.setRole(rs.getString(5)); + records.add(user); + } + con.close(); + return records; + } + + public void setInsertNewUser() throws ClassNotFoundException, SQLException{ + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + String Name = request.getParameter("Name"); + String Username = request.getParameter("Username"); + String Email = request.getParameter("Email"); + String Password = request.getParameter("Password"); + String Role = SelectedItem; + + try (Connection con = makeConnection()) { + PreparedStatement ps; + String query = "INSERT INTO `user` (`Username`,`Password`, `Name`, `email`, `Role`) VALUES (?,?,?,?,?)"; + ps= con.prepareStatement(query); + ps.setString(1,Username); + ps.setString(2,Password); + ps.setString(3,Name); + ps.setString(4,Email); + ps.setString(5,Role); + int i = ps.executeUpdate(); + con.close(); + } + } + + public void setDeleteUser() throws ClassNotFoundException, SQLException{ + try (Connection con = makeConnection()) { + Statement stmt = con.createStatement(); + String query = "Delete from user where username=\"" + username + "\";"; + int rs; + rs = stmt.executeUpdate(query); + PreparedStatement ps; + con.close(); + } + } + + public List getDeletedPosts() throws ClassNotFoundException{ + ResultSet rs; + Connection con; + List records = new ArrayList<>(); + try { + con = makeConnection(); + Statement stmt = con.createStatement(); + String query = "Select * from post where status=\"deleted\";"; + rs = stmt.executeQuery(query); + + while(rs.next()){ + Post post = new Post(); + post.setId(rs.getInt(1)); + post.setJudul(rs.getString(2)); + post.setTanggal(rs.getString(3)); + post.setContent(rs.getString(4)); + post.setAuthor(rs.getString(5)); + post.setStatus(rs.getString(6)); + records.add(post); + } + con.close(); + } catch (SQLException e) { + System.err.println(e); + } + return records; + } + + public void setRestorePost(int id) throws ClassNotFoundException, SQLException, IOException{ + try (Connection con = makeConnection()) { + Statement stmt = con.createStatement(); + String query = "Update post Set status=\"unpublished\" WHERE ID="+id; + int rs; + rs = stmt.executeUpdate(query); + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/Home.xhtml"); + con.close(); + } + } + + public void setRealDeletePost(int id) throws ClassNotFoundException, SQLException, IOException{ + try (Connection con = makeConnection()) { + Statement stmt = con.createStatement(); + String query = "Delete from post where id=\"" + id + "\";"; + int rs; + rs = stmt.executeUpdate(query); + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/Home.xhtml"); + con.close(); + } + } + + public void updateUser() throws ClassNotFoundException, SQLException, IOException + { + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + String Name = request.getParameter("EditName"); + String Username = request.getParameter("EditUsername"); + String Email = request.getParameter("EditEmail"); + String Password = request.getParameter("EditPassword"); + String Role = SelectedItem; + + try (Connection con = makeConnection()) { + PreparedStatement ps; + String query = "UPDATE `user` SET `Password`=?,`Name`=?,`email`=?,`Role`=? WHERE `Username`=?"; + ps= con.prepareStatement(query); + + ps.setString(1,Password); + ps.setString(2,Name); + ps.setString(3,Email); + ps.setString(4,Role); + ps.setString(5,Username); + int i = ps.executeUpdate(); + con.close(); + } + } + +} diff --git a/SImpleBlog/src/java/Database/PublishPost.java b/SImpleBlog/src/java/Database/PublishPost.java new file mode 100644 index 00000000..73af595f --- /dev/null +++ b/SImpleBlog/src/java/Database/PublishPost.java @@ -0,0 +1,105 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ViewScoped; + +/** + * + * @author Sakurai + */ +@ManagedBean(name = "Publishpost", eager = true) +@ViewScoped +public class PublishPost { + public PublishPost(){ + + } + + private Connection getConnection() throws ClassNotFoundException, SQLException, IllegalAccessException{ + Connection conn = null; + try{ + Class.forName("com.mysql.jdbc.Driver").newInstance(); + String url = "jdbc:mysql://localhost/blog"; + String user = "root"; + String password = ""; + conn = DriverManager.getConnection(url, user, password); + }catch(InstantiationException e){ + System.err.println(e); + } + return conn; + } + + public List getUnpublishedPost() throws ClassNotFoundException, IllegalAccessException, SQLException{ + ResultSet result; + List UnpublishedPost = new ArrayList<>(); + try (Connection conn = getConnection()) { + Statement stmt = conn.createStatement(); + String query = "Select * from post where Status = \"unpublished\""; + result = stmt.executeQuery(query); + + while(result.next()){ + Post post = new Post(); + post.setId(result.getInt(1)); + post.setJudul(result.getString(2)); + post.setTanggal(result.getString(3)); + post.setContent(result.getString(4)); + post.setAuthor(result.getString(5)); + post.setStatus(result.getString(6)); + UnpublishedPost.add(post); + } + } + return UnpublishedPost; + } + + public List getpublishedPost() throws ClassNotFoundException, IllegalAccessException{ + ResultSet result; + List publishedPost = new ArrayList<>(); + try { + try (Connection conn = getConnection()) { + Statement stmt = conn.createStatement(); + String query = "Select * from post where Status = \"published\""; + result = stmt.executeQuery(query); + + while(result.next()){ + Post post = new Post(); + post.setId(result.getInt(1)); + post.setJudul(result.getString(2)); + post.setTanggal(result.getString(3)); + post.setContent(result.getString(4)); + post.setAuthor(result.getString(5)); + post.setStatus(result.getString(6)); + publishedPost.add(post); + } + } + } catch (SQLException e) { + System.err.println(e); + } + return publishedPost; + } + + public void publishPost(int postID) throws ClassNotFoundException, IllegalAccessException{ + ResultSet result; + try { + try (Connection conn = getConnection()) { + Statement stmt = conn.createStatement(); + String query = "Update post set Status = \"published\" WHERE ID = " + postID + ";"; + stmt.executeUpdate(query); + } + } catch (SQLException e) { + System.err.println(e); + } + } + +} diff --git a/SImpleBlog/src/java/Database/Register.java b/SImpleBlog/src/java/Database/Register.java new file mode 100644 index 00000000..46b1043b --- /dev/null +++ b/SImpleBlog/src/java/Database/Register.java @@ -0,0 +1,47 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +import static java.lang.System.out; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.FacesValidator; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; + +/** + * + * @author Sakurai + */ +@FacesValidator("RegisterValidator") +public class Register implements Validator{ + + @Override + public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { + String username = value.toString(); + out.println("username: " + username); + try { + UserRegistry user = new UserRegistry(); + boolean userExist = user.isUserExist(username); + if(userExist == true){ + out.println("flag"); + FacesMessage msg = new FacesMessage("Username " + username + " already exists"); + msg.setSeverity(FacesMessage.SEVERITY_ERROR); + throw new ValidatorException(msg); + } + } catch (ClassNotFoundException ex) { + Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex); + } + + } + +} diff --git a/SImpleBlog/src/java/Database/User.java b/SImpleBlog/src/java/Database/User.java new file mode 100644 index 00000000..3913bc6c --- /dev/null +++ b/SImpleBlog/src/java/Database/User.java @@ -0,0 +1,77 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +/** + * + * @author Rikysamuel + */ +public class User { + String Username; + String Password; + String Name; + String Email; + String Role; + boolean editable; + public User(){ + } + + public boolean geteditable(){ + return this.editable; + } + + public void setEditable(boolean edit){ + editable = edit; + } + public void SaveAction(){ + this.editable = false; + } + + public void WantToEdit(){ + this.editable = true; + } + + public String getEmail() { + return Email; + } + + public void setEmail(String Email) { + this.Email = Email; + } + + public String getName() { + return Name; + } + + public void setName(String Name) { + this.Name = Name; + } + + public String getPassword() { + return Password; + } + + public void setPassword(String Password) { + this.Password = Password; + } + + public String getRole() { + return Role; + } + + public void setRole(String Role) { + this.Role = Role; + } + + public String getUsername() { + return Username; + } + + public void setUsername(String Username) { + this.Username = Username; + } +} diff --git a/SImpleBlog/src/java/Database/UserBean.java b/SImpleBlog/src/java/Database/UserBean.java new file mode 100644 index 00000000..d817a143 --- /dev/null +++ b/SImpleBlog/src/java/Database/UserBean.java @@ -0,0 +1,63 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +/** + * + * @author Kevin Huang + */ +import java.io.Serializable; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; + +/** + * + * @author Kevin Huang + */ +@ManagedBean(name="UserBean",eager = true) +@SessionScoped +public class UserBean implements Serializable{ + public PostingDatabase a = new PostingDatabase(); + private List ListUser; + + public UserBean() throws ClassNotFoundException{ + try { + System.out.println(a.getUsers().toString()); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserBean.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(UserBean.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public List getOrderList() throws ClassNotFoundException, SQLException { + return a.getUsers(); + } + public void setOrderList(List temp){ + ListUser = temp; + } + public String saveAction() throws ClassNotFoundException, SQLException { + + //get all existing value but set "editable" to false + for (User user : a.getUsers()){ + user.setEditable(false); + } + //return to current page + return null; + + } + + public String editAction(User user) { + user.setEditable(true); + return null; + } +} \ No newline at end of file diff --git a/SImpleBlog/src/java/Database/UserData.java b/SImpleBlog/src/java/Database/UserData.java new file mode 100644 index 00000000..1f2c509d --- /dev/null +++ b/SImpleBlog/src/java/Database/UserData.java @@ -0,0 +1,33 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +import java.io.Serializable; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; + +/** + * + * @author Sakurai + */ +@ManagedBean(name = "userData", eager = true) +@SessionScoped +public class UserData implements Serializable { + +private static final long serialVersionUID = 1L; + + public String data; + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/SImpleBlog/src/java/Database/UserRegistry.java b/SImpleBlog/src/java/Database/UserRegistry.java new file mode 100644 index 00000000..8f83f7d0 --- /dev/null +++ b/SImpleBlog/src/java/Database/UserRegistry.java @@ -0,0 +1,94 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +import java.io.IOException; +import static java.lang.System.out; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ViewScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.servlet.http.HttpServletRequest; + +/** + * + * @author Sakurai + */ +@ManagedBean(name = "UserRegistry", eager = true) +@ViewScoped +public class UserRegistry { + + public UserRegistry(){ + + } + + private Connection getConnection() throws ClassNotFoundException, SQLException, IllegalAccessException{ + Connection conn = null; + try{ + Class.forName("com.mysql.jdbc.Driver").newInstance(); + String url = "jdbc:mysql://localhost/blog"; + String user = "root"; + String password = ""; + conn = DriverManager.getConnection(url, user, password); + }catch(ClassNotFoundException | InstantiationException e){ + e.printStackTrace(); + } + return conn; + } + + public boolean isUserExist(String username) throws ClassNotFoundException, IllegalAccessException{ + boolean userExist = false; + ResultSet result; + try{ + Connection conn = getConnection(); + Statement stmt = conn.createStatement(); + String query = "Select * From user where Username = \"" + username + "\";"; + result = stmt.executeQuery(query); + if(!result.next()){ + userExist = false; + }else{ + userExist = true; + } + conn.close(); + + } catch(SQLException e){ + System.err.println(e); + } + return userExist; + } + + public void addUserOwner() throws ClassNotFoundException, SQLException, IllegalAccessException, IOException{ + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + String Username = request.getParameter("Form:Username"); + String Password = request.getParameter("Form:Password"); + String Email = request.getParameter("Form:Email"); + String Name = request.getParameter("Form:Name"); + out.println("password: " + Password); + if(!isUserExist(Username)){ + try (Connection con = getConnection()) { + PreparedStatement ps; + String query = "INSERT INTO `user` (`Username`,`Password`, `Name`, `email`, `Role`) VALUES (?,?,?,?,?)"; + ps= con.prepareStatement(query); + ps.setString(1,Username); + ps.setString(2,Password); + ps.setString(3,Name); + ps.setString(4,Email); + ps.setString(5,"Owner"); + int i = ps.executeUpdate(); + con.close(); + } + } + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/Home.xhtml"); + } +} diff --git a/SImpleBlog/src/java/Database/ViewPost.java b/SImpleBlog/src/java/Database/ViewPost.java new file mode 100644 index 00000000..a533ea1d --- /dev/null +++ b/SImpleBlog/src/java/Database/ViewPost.java @@ -0,0 +1,85 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Database; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; + +/** + * + * @author Sakurai + */ +@ManagedBean(name = "Viewpost", eager = true) +@SessionScoped +public class ViewPost { + private int PostID; + + public ViewPost(){ + + } + + public void setPostId(int PostID){ + this.PostID = PostID; + } + + public int getPostId(){ + return PostID; + } + + private Connection getConnection() throws ClassNotFoundException, SQLException, IllegalAccessException{ + Connection conn = null; + try{ + Class.forName("com.mysql.jdbc.Driver").newInstance(); + String url = "jdbc:mysql://localhost/blog"; + String user = "root"; + String password = ""; + conn = DriverManager.getConnection(url, user, password); + }catch(ClassNotFoundException | InstantiationException e){ + e.printStackTrace(); + } + return conn; + } + + public void Redirect(int PostID) throws IOException{ + setPostId(PostID); + ExternalContext extcon = FacesContext.getCurrentInstance().getExternalContext(); + extcon.redirect("/SImpleBlog/ViewPost.xhtml"); + } + + public Post getPost() throws ClassNotFoundException, SQLException, IllegalAccessException{ + ResultSet result; + Post post = new Post(); + try{ + Connection conn = getConnection(); + Statement stmt = conn.createStatement(); + String query = "Select * From post where ID = " + PostID + ";"; + result = stmt.executeQuery(query); + while(result.next()){ + post.setId(result.getInt(1)); + post.setJudul(result.getString(2)); + post.setTanggal(result.getString(3)); + post.setContent(result.getString(4)); + post.setAuthor(result.getString(5)); + post.setStatus(result.getString(6)); + } + conn.close(); + + } catch(SQLException e){ + System.err.println(e); + } + + return post; + } +} diff --git a/SImpleBlog/src/java/Login/Login.java b/SImpleBlog/src/java/Login/Login.java new file mode 100644 index 00000000..668ec2a9 --- /dev/null +++ b/SImpleBlog/src/java/Login/Login.java @@ -0,0 +1,106 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package Login; + +import javax.faces.context.FacesContext; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * + * @author Rikysamuel + */ +public class Login { + public Login(){ + + } + + public void setCookie(String Username, String Password){ + Cookie userCookie = new Cookie("username",Username); + userCookie.setMaxAge(3600*24); + HttpServletResponse userResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); + userResponse.addCookie(userCookie); + + Cookie passCookie = new Cookie("password",Password); + passCookie.setMaxAge(3600*24); + HttpServletResponse passResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); + passResponse.addCookie(passCookie); + } + + public Cookie getUserCookie(){ + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + Cookie userCookie; + Cookie[] Cookies; + + Cookies = request.getCookies(); + if (Cookies!=null && Cookies.length>0){ + for (Cookie Cookie : Cookies) { + if (Cookie.getName().equals("username")){ + userCookie = Cookie; + return userCookie; + } + } + } + return null; + } + + public Cookie getPassCookie(){ + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + Cookie passCookie; + Cookie[] Cookies; + + Cookies = request.getCookies(); + if (Cookies!=null && Cookies.length>0){ + for (Cookie Cookie : Cookies) { + if (Cookie.getName().equals("password")){ + passCookie = Cookie; + return passCookie; + } + } + } + return null; + } + + public void delUserCookie(){ + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + Cookie[] Cookies; + + Cookies = request.getCookies(); + if (Cookies!=null && Cookies.length>0){ + for (Cookie Cookie : Cookies) { + if (Cookie.getName().equals("username")){ + Cookie.setValue(null); + Cookie.setPath(request.getContextPath()); + Cookie.setMaxAge(0); + HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); + response.addCookie(Cookie); + } + } + } + } + + public void delPassCookie(){ + HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); + Cookie[] Cookies; + + Cookies = request.getCookies(); + if (Cookies!=null && Cookies.length>0){ + for (Cookie Cookie : Cookies) { + if (Cookie.getName().equals("password")){ + Cookie.setValue(null); + Cookie.setMaxAge(0); + Cookie.setPath(request.getContextPath()); + HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); + response.addCookie(Cookie); + } + } + } + } + +} diff --git a/SImpleBlog/web/EditPost.xhtml b/SImpleBlog/web/EditPost.xhtml new file mode 100644 index 00000000..565c6149 --- /dev/null +++ b/SImpleBlog/web/EditPost.xhtml @@ -0,0 +1,82 @@ + + + + + + + Simple Blog + + + + +
+ + + +
+ + +

-

+ +
+
+

Edit Post

+ +
+ + + + + + + + + + +
+ + +
+
+
+
+ +
+ + + +
+
+ + diff --git a/SImpleBlog/web/Home.xhtml b/SImpleBlog/web/Home.xhtml new file mode 100644 index 00000000..c501e4ca --- /dev/null +++ b/SImpleBlog/web/Home.xhtml @@ -0,0 +1,82 @@ + + + + + + + Simple Blog + + + + +
+ + + +
+
+ +
+
+ + + +
+
+ diff --git a/SImpleBlog/web/Register.xhtml b/SImpleBlog/web/Register.xhtml new file mode 100644 index 00000000..5ffac046 --- /dev/null +++ b/SImpleBlog/web/Register.xhtml @@ -0,0 +1,61 @@ + + + + + + Owner's Simple Blog + + + + + +
+ + +


+

-

+
+
+

Register

+ +
+ + + + + + + + + + + + + +
+
+
+
+
+
+ \ No newline at end of file diff --git a/SImpleBlog/web/Role/AddPost.xhtml b/SImpleBlog/web/Role/AddPost.xhtml new file mode 100644 index 00000000..9f4399ac --- /dev/null +++ b/SImpleBlog/web/Role/AddPost.xhtml @@ -0,0 +1,84 @@ + + + + + + + Simple Blog + + + + + + Publish Post + + + + + + + +
+ + + +
+ +
+
+ +

#{Viewpost.post.judul}

+

+
+
+ +
+
+
+ #{Viewpost.post.content} +
+ +

Komentar

+ +
+ + + + + + + +
+ + + +
+ + + + + + + +
+ + + + +
+
+ +
    + +
+
+
+ +
+ + + +
+ +
+ diff --git a/SImpleBlog/web/WEB-INF/web.xml b/SImpleBlog/web/WEB-INF/web.xml new file mode 100644 index 00000000..63b5d60d --- /dev/null +++ b/SImpleBlog/web/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + javax.faces.PROJECT_STAGE + Development + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.xhtml + + + + 30 + + + + Home.xhtml + + diff --git a/SImpleBlog/web/assets/ajax.js b/SImpleBlog/web/assets/ajax.js new file mode 100644 index 00000000..8df6b6b2 --- /dev/null +++ b/SImpleBlog/web/assets/ajax.js @@ -0,0 +1,71 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + + +function LoadCommentList(PostID){ + var xmlhttp = new XMLHttpRequest(); + + xmlhttp.open("GET","assets/loadcomments.jsp?ID=" + PostID,true); + xmlhttp.onreadystatechange=function(){ + if (xmlhttp.readyState==4 && xmlhttp.status==200){ + document.getElementById("comment-list").innerHTML=xmlhttp.responseText; + } + } + xmlhttp.send(); +} + +function AddComment(PostID){ + if(IsEmailValid()){ + var xmlhttp = new XMLHttpRequest(); + + xmlhttp.open("POST","assets/newcomment.jsp?ID=" +PostID + "&Name=" + document.getElementById("Nama").value + "&Email=" + document.getElementById("Email").value + "&Comment=" + document.getElementById("Komentar").value,true); + xmlhttp.onreadystatechange=function(){ + if (xmlhttp.readyState==4 && xmlhttp.status==200){ + document.getElementById("comment-list").innerHTML=xmlhttp.responseText; + } + } + xmlhttp.send(); + return true; + }else{ + return false; + } +} + +function AddCommentLoggedIn(PostID){ + var xmlhttp = new XMLHttpRequest(); + + xmlhttp.open("POST","assets/newcomment.jsp?ID=" +PostID + "&Name=" + document.getElementById("Nama2").value + "&Email=" + document.getElementById("Email2").value + "&Comment=" + document.getElementById("Komentar2").value,true); + xmlhttp.onreadystatechange=function(){ + if (xmlhttp.readyState==4 && xmlhttp.status==200){ + document.getElementById("comment-list").innerHTML=xmlhttp.responseText; + } + } + xmlhttp.send(); +} + +function IsEmailValid(){ + var regex = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/; + var emailInput = document.forms["Form"]["Email"].value; + + if(!regex.test(emailInput)){ + alert("Invalid email"); + return false; + }else{ + return true; + } +} + +function IsEmailValidForRegistry(){ + var regex = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/; + var emailInput = document.forms["Form"]["Form:Email"].value; + + if(!regex.test(emailInput)){ + alert("Invalid email"); + return false; + }else{ + return true; + } +} diff --git a/SImpleBlog/web/assets/confirmdate.js b/SImpleBlog/web/assets/confirmdate.js new file mode 100644 index 00000000..343db7be --- /dev/null +++ b/SImpleBlog/web/assets/confirmdate.js @@ -0,0 +1,33 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +function validateform() { + var date =document.forms["Form"]["Tanggal"].value; + var judul = document.forms["Form"]["Judul"].value; + var konten = document.forms["Form"]["Konten"].value; + if (date == null || date == "" || judul == null || judul == "" || konten == null || konten == "") { + alert("All input must be filled out"); + return false; + } + else + { + var datereg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/; + if(date.match(datereg)){ + var z = new Date(date.substr(0,4),date.substr(5,2)-1,date.substr(8,2),23,59,59,0); + var y = new Date(); + if(z + +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.Statement"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> + +<% + if (request.getParameter("ID") != null) { + Connection connection = null; + Statement stmt = null; + try { + String connectionURL = "jdbc:mysql://localhost:3306/blog"; + Class.forName("com.mysql.jdbc.Driver").newInstance(); + connection = DriverManager.getConnection(connectionURL, "root", ""); + stmt = connection.createStatement(); + String query = "Select * From comment where PostID = " + Integer.parseInt(request.getParameter("ID")) + ";"; + ResultSet result = stmt.executeQuery(query); + while(result.next()){ + String name = result.getString("Nama"); + String comment = result.getString("Komentar"); + String date = result.getString("Tanggal"); + out.println("
  • "); + out.println("
    "); + out.println("

    " + name +"

    "); + out.println("
    " + date + "
    "); + out.println("
    "); + out.println("

    "); + out.println(comment); + out.println("

    "); + out.println("
  • "); + } + connection.close(); + }catch(Exception ex){ + System.out.println("cannot connect to database"); + } + } + + +%> diff --git a/SImpleBlog/web/assets/newcomment.jsp b/SImpleBlog/web/assets/newcomment.jsp new file mode 100644 index 00000000..2590fb1d --- /dev/null +++ b/SImpleBlog/web/assets/newcomment.jsp @@ -0,0 +1,32 @@ +<%-- + Document : newcomment + Created on : Nov 25, 2014, 11:30:16 AM + Author : Sakurai +--%> + +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.DriverManager"%> +<%@page import="java.sql.Statement"%> +<%@page import="java.sql.Connection"%> + +<% + if (request.getParameter("ID") != null) { + Connection connection = null; + Statement stmt = null; + try { + String connectionURL = "jdbc:mysql://localhost:3306/blog"; + Class.forName("com.mysql.jdbc.Driver").newInstance(); + connection = DriverManager.getConnection(connectionURL, "root", ""); + stmt = connection.createStatement(); + int ID = Integer.parseInt(request.getParameter("ID")); + String Name = request.getParameter("Name"); + String Comment = request.getParameter("Comment"); + String Email = request.getParameter("Email"); + String query = "INSERT INTO comment (PostID, Nama, Email, Komentar, Tanggal) VALUES ('" + ID + "', '" + Name + "', '" + Email + "', '" + Comment + "', NOW())"; + stmt.execute(query); + connection.close(); + }catch(Exception ex){ + System.out.println("cannot connect to database"); + } + } +%> \ No newline at end of file diff --git a/assets/css/screen.css b/SImpleBlog/web/assets/screen.css similarity index 81% rename from assets/css/screen.css rename to SImpleBlog/web/assets/screen.css index 1d8fdf3b..b15f9d5e 100644 --- a/assets/css/screen.css +++ b/SImpleBlog/web/assets/screen.css @@ -32,6 +32,20 @@ body { background: #fff; } +.table { + margin: 0 auto; +} + +ul#adminoption { + min-width: 696px; + list-style: none; + padding-top: 20px; +} + +ul#adminoption li { + display: inline; +} + /* Typography ================================================== */ @@ -92,6 +106,23 @@ cite { font-style: italic; } +.logo{ + float: left; + padding-bottom: 30px; + height: 30px; + margin-left: 0px; + letter-spacing: 1px; + font-family: 'Questrial', sans-serif; + font-size: 30px; + color: #000; + text-transform: uppercase; + text-align: left; + } + +span{ + color: red !important; + } + /* Teaser ================================================== */ @@ -166,19 +197,29 @@ a:hover { float: right; } .nav-primary li { - display: inline-block; + display: initial; margin-left: 10px; font-weight: 500; } #logo h1, -.nav-primary li, .nav-primary li a { font-family: "proxima-nova", "helvetica neue", "helvetica", sans-serif; font-weight: 700; - font-size: 13px; + font-size: 12px; + line-height: 30px; + color: #E50000; + text-transform: initial; + text-align: right; +} + +.nav-primary li { + font-family: "proxima-nova", "helvetica neue", "helvetica", sans-serif; + font-weight: 700; + font-size: 12px; line-height: 30px; color: #000; - text-transform: uppercase; + text-transform: initial; + text-align: right; } #logo h1 { @@ -187,6 +228,9 @@ a:hover { letter-spacing: 1px; font-family: 'Questrial', sans-serif; font-size: 30px; + color: #000; + text-transform: uppercase; + text-align: left; } #logo h1 span{ @@ -225,7 +269,7 @@ div.cover > img { } /* Header */ .art-header { - height: 900px; + height: 564px; /* Background image is defined in the post */ background-position: top center; background-attachment: fixed; @@ -233,7 +277,7 @@ div.cover > img { } /* Contains the time, title and subtitle for an article */ .art-header-inner { - position: fixed; + position: absolute; top: 300px; left: 50%; margin-left: -490px; @@ -275,6 +319,7 @@ div.cover > img { .art-body { position: relative; width: 100%; + top: 50px; background: #fff; z-index: 100; -webkit-box-shadow: 0 -3px 3px rgba(0,0,0,.2); @@ -381,7 +426,7 @@ div.cover > img { /* List of Articles ================================================== */ .art-list { - padding: 120px 0 0; + padding: 140px 0 0; } .art-list-body { position: relative; @@ -397,9 +442,10 @@ div.cover > img { border-bottom: none; } .art-list-title { - font-size: 26px; + font-size: 20px; line-height: 26px; font-weight: 700; + width: 300px; } .art-list-item-title-and-time { float: left; @@ -413,6 +459,17 @@ div.cover > img { text-transform: uppercase; color: #999; } + +.art-list-addpost { + font-size: 15px; + line-height: 20px; + letter-spacing: 2px; + text-transform: uppercase; + color: #999; + float: right; + margin-right: 20px; +} + .art-list-title a { color: #000; } @@ -435,6 +492,7 @@ div.cover > img { padding: 30px 0 40px; overflow: hidden; border-top: 1px solid #ccc; + z-index: 100; } .footer, .footer a { @@ -829,6 +887,30 @@ hr.featured-article:after { #contact-area { width: 600px; margin-top: 25px; + position: relative; + float: right; + height: 400px; + text-align: center; +} + +#contact-area2 { + width: 600px; + margin-top: 25px; + position: relative; + height: 267px; +} + +#contact-area2 input, #contact-area2 textarea { + padding: 5px; + width: 471px; + font-family: Helvetica, sans-serif; + margin: 0px 0px 10px 0px; + border: 2px solid #ccc; + +} +#contact-area3 input{ + font-family: Helvetica, sans-serif; + border: 2px solid #ccc; } #contact-area input, #contact-area textarea { @@ -843,13 +925,28 @@ hr.featured-article:after { height: 90px; } +#contact-area2 textarea { + height: 90px; +} + #contact-area textarea:focus, #contact-area input:focus { border: 2px solid #900; } +#contact-area2 textarea:focus, #contact-area2 input:focus { + border: 2px solid #900; +} + #contact-area input.submit-button { width: 100px; - +} + +#contact-area2 input.submit-button { + width: 100px; +} + +#contact-area3 input.submit-button { + width: 100px; } label { @@ -858,4 +955,112 @@ label { margin-right: 15px; width: 100px; padding-top: 5px; -} \ No newline at end of file +} + +#title{ + position: absolute; + top: 70px; + left: 50%; + height: 30px; + width: 980px; + padding-top: 40px; + margin-left: -490px; /* Half width of nav */ + border-bottom: 1px solid #333; + z-index: 2; + font-family: Helvetica, sans-serif; + font-size: 20px; + text-align: center; + line-height: 30px; +} + +.submitbutton{ + margin-right: 0px; + position: relative; + float: right; + right: 7px; +} + +#Konten, #Komentar, #Komentar2{ + resize: none; +} + +.editbutton{ + position: relative; + height: 28px; + width: 1px; +} + +.publishbutton{ + position: relative; + height: 28px; + width: 1px; + left: 38px; +} + +.restorebutton{ + position: relative; + height: 28px; + width: 1px; +} + +.deletebutton{ + position: relative; + height: 28px; + width: 1px; + left: 70px; +} + +#customers { + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + width: 100%; + border-collapse: collapse; +} + +#customers td, #customers th { + font-size: 1em; + border: 1px solid black; + padding: 3px 7px 2px 7px; +} + +#customers th { + font-size: 1.1em; + text-align: left; + padding-top: 5px; + padding-bottom: 4px; + background-color: gray; + color: #ffffff; +} + + +#customers tr.alt td { + color: #000000; + background-color: #EAF2D3; +} + +#checkusername{ + color: #F40034; + font-size: 18px; +} + +.usernameAlert{ + position: absolute; + top: -39px; + font-size: 17px; +} +.CreateUser{ + color:black; +} + +#contact-area2 { + text-align: center; + width: 600px; + margin-top: 25px; + position: relative; + height: 400px; +} + +#contact-area3 { + margin-top: 25px; + position: relative; + +} diff --git a/assets/img/favicon.ico b/assets/img/favicon.ico deleted file mode 100644 index 40b40ed3..00000000 Binary files a/assets/img/favicon.ico and /dev/null differ diff --git a/assets/img/pre.png b/assets/img/pre.png deleted file mode 100644 index 7f48517b..00000000 Binary files a/assets/img/pre.png and /dev/null differ diff --git a/blog.sql b/blog.sql new file mode 100644 index 00000000..a12ea50d --- /dev/null +++ b/blog.sql @@ -0,0 +1,117 @@ +-- phpMyAdmin SQL Dump +-- version 4.1.12 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1 +-- Generation Time: Dec 01, 2014 at 03:33 PM +-- Server version: 5.6.16 +-- PHP Version: 5.5.11 + +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 utf8 */; + +-- +-- Database: `blog` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `comment` +-- + +CREATE TABLE IF NOT EXISTS `comment` ( + `PostID` int(11) NOT NULL, + `CommentID` int(11) NOT NULL AUTO_INCREMENT, + `Nama` varchar(50) NOT NULL, + `Email` varchar(50) NOT NULL, + `Komentar` text NOT NULL, + `Tanggal` date NOT NULL, + PRIMARY KEY (`CommentID`), + KEY `PostID` (`PostID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; + +-- +-- Dumping data for table `comment` +-- + +INSERT INTO `comment` (`PostID`, `CommentID`, `Nama`, `Email`, `Komentar`, `Tanggal`) VALUES +(1, 1, 'Bangbang', 'bangbang@gmail.com', 'Menarik sekali user1 dapat melakukan penghapusan user dan pengembalian post yang sudah di delete yang tidak dijelaskan.', '2014-12-03'), +(2, 2, 'Kismis', 'kismis@gmail.com', 'Editor dapat melakukan edit pada post sebelum melakukan post...menarik', '2014-12-03'), +(3, 3, 'Kutilang', 'kutilang@gmail.com', 'Owner hanya dapat menambahkan post dan bahkan tidak dapat menghapus post yang telah dibuatnya...Sabar ya', '2014-12-04'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `post` +-- + +CREATE TABLE IF NOT EXISTS `post` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `Judul` text NOT NULL, + `Tanggal` date NOT NULL, + `Content` text NOT NULL, + `Author` varchar(24) NOT NULL, + `Status` varchar(20) NOT NULL, + PRIMARY KEY (`ID`), + KEY `Author` (`Author`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ; + +-- +-- Dumping data for table `post` +-- + +INSERT INTO `post` (`ID`, `Judul`, `Tanggal`, `Content`, `Author`, `Status`) VALUES +(1, 'Kisah User1', '2014-12-02', 'User1 adalah user yang memiliki role sebagai admin yang dapat membuat user baru, melakukan edit pada user, men-delete user serta mengedit post dan meng-publishkannya.', 'User1', 'Published'), +(2, 'Kisah User2', '2014-12-03', 'User2 adalaah user yang memiliki role sebagai editor yang dapat menambahkan post, melakukan edit pada post serta melakukan delete pada post', 'User2', 'Published'), +(3, 'Kisah User3', '2014-12-04', 'User3 adalah user yang memiliki role sebagai seorang owner yang hanya dapat melakukan postingan dan tidak dapat mengubah status post yang dibuat. Menyedihkan bukan?', 'User3', 'Published'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `user` +-- + +CREATE TABLE IF NOT EXISTS `user` ( + `Username` varchar(24) NOT NULL, + `Password` varchar(20) NOT NULL, + `Name` varchar(50) NOT NULL, + `email` text NOT NULL, + `Role` varchar(10) NOT NULL, + PRIMARY KEY (`Username`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Dumping data for table `user` +-- + +INSERT INTO `user` (`Username`, `Password`, `Name`, `email`, `Role`) VALUES +('User1', 'user1', 'IamUser1', 'user1@gmail.com', 'Admin'), +('User2', 'user2', 'IamUser2', 'user2@gmail.com', 'Editor'), +('User3', 'user3', 'IamUser3', 'user3@gmail.com', 'Owner'); + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `comment` +-- +ALTER TABLE `comment` + ADD CONSTRAINT `Comment_ibfk_1` FOREIGN KEY (`PostID`) REFERENCES `post` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- +-- Constraints for table `post` +-- +ALTER TABLE `post` + ADD CONSTRAINT `Post_ibfk_1` FOREIGN KEY (`Author`) REFERENCES `user` (`Username`) ON DELETE CASCADE ON UPDATE CASCADE; + +/*!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 */; diff --git a/index.html b/index.html deleted file mode 100644 index 07cff0ba..00000000 --- a/index.html +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Simple Blog - - - - - -
    - - - -
    -
    - -
    -
    - - - -
    - - - - - - - - \ No newline at end of file diff --git a/new_post.html b/new_post.html deleted file mode 100644 index fc4e18ee..00000000 --- a/new_post.html +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Simple Blog | Tambah Post - - - - - -
    - - - -
    - - -

    -

    - -
    -
    -

    Tambah Post

    - -
    -
    - - - - - - -
    - - - -
    -
    -
    -
    - -
    - - - -
    - - - - - - - - \ No newline at end of file diff --git a/post.html b/post.html deleted file mode 100644 index c0b6f9e6..00000000 --- a/post.html +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Simple Blog | Apa itu Simple Blog? - - - - - -
    - - - -
    - -
    -
    - -

    Apa itu Simple Blog?

    -

    -
    -
    - -
    -
    -
    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis aliquam minus consequuntur amet nulla eius, neque beatae, nostrum possimus, officiis eaque consectetur. Sequi sunt maiores dolore, illum quidem eos explicabo! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magnam consequuntur consequatur molestiae saepe sed, incidunt sunt inventore minima voluptatum adipisci hic, est ipsa iste. Nobis, aperiam provident quae. Reprehenderit, iste.

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores animi tenetur nam delectus eveniet iste non culpa laborum provident minima numquam excepturi rem commodi, officia accusamus eos voluptates obcaecati. Possimus?

    - -
    - -

    Komentar

    - -
    -
    - - - - - - -
    - - - -
    -
    - -
      -
    • -
      -

      Jems

      -
      2 menit lalu
      -
      -

      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis repudiandae quae natus quos alias eos repellendus a obcaecati cupiditate similique quibusdam, atque omnis illum, minus ex dolorem facilis tempora deserunt! …

      -
    • - -
    • -
      -

      Kave

      -
      1 jam lalu
      -
      -

      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis repudiandae quae natus quos alias eos repellendus a obcaecati cupiditate similique quibusdam, atque omnis illum, minus ex dolorem facilis tempora deserunt! …

      -
    • -
    -
    -
    - -
    - - - -
    - - - - - - - - \ No newline at end of file