• R/O
  • SSH
  • HTTPS

webserver: Commit


Commit MetaInfo

Revision56 (tree)
Time2010-10-25 00:51:27
Authorhoritaku

Log Message

edit

Change Summary

Incremental Difference

--- branch/Basic 0.2x/reflectAction/refrect_action/ContentData.java (revision 55)
+++ branch/Basic 0.2x/reflectAction/refrect_action/ContentData.java (revision 56)
@@ -1,5 +1,6 @@
11 package refrect_action;
22
3+import java.net.URLDecoder;
34 import java.util.HashMap;
45 import java.util.List;
56
@@ -15,13 +16,40 @@
1516 public HttpResponse execute(HttpRequest request) throws Exception {
1617 HttpResponse res = new HttpResponse();
1718 METHOD method = request.getMethod();
18- int index = Integer.parseInt(request.getGetParams().get("idx"));
1919 ContentsBiz biz = new ContentsBiz();
2020 res.addHeader("Cache-Control", "no-cache");
2121 if(method == METHOD.GET) {
22+ String idx = request.getGetParams().get("idx");
23+ if(idx == null || "".equals(idx)) {
24+ res.setStatusCore(400);
25+ return res;
26+ }
27+ int index = Integer.parseInt(idx);
2228 HashMap<String,String> map = biz.getData(index);
2329 String data = JSonUtil.mapToJSON(map);
2430 res.setResponseStr(data);
31+ } else if(method == METHOD.POST) {
32+ String body = request.getPostParams().get("body");
33+ String title = request.getPostParams().get("title");
34+ if(title == null || "".equals(title)) {
35+ res.setStatusCore(400);
36+ res.setResponseStr("title is null");
37+ return res;
38+ }
39+ if(body == null || "".equals(body)) {
40+ res.setStatusCore(400);
41+ res.setResponseStr("body is null");
42+ return res;
43+ }
44+ body = URLDecoder.decode(body, "UTF-8");
45+ title = URLDecoder.decode(title, "UTF-8");
46+ HashMap<String, String > data = new HashMap<String, String>();
47+ data.put("body", body);
48+ data.put("title", title);
49+ int ret = biz.insertData(data);
50+ res.setStatusCore(201);
51+ res.addHeader("Location", "content_show.html?idx=" + ret);
52+ res.setResponseStr("content_show.html?idx=" + ret);
2553 }
2654 return res;
2755 }
--- branch/Basic 0.2x/reflectAction/refrect_action/LoginCheck.java (revision 55)
+++ branch/Basic 0.2x/reflectAction/refrect_action/LoginCheck.java (revision 56)
@@ -1,17 +1,29 @@
11 package refrect_action;
22
3+import java.security.NoSuchAlgorithmException;
4+
5+import lib.crypt.CodeMD5;
6+import extension.file.EasyIni;
37 import servercore.http.HttpRequest;
48 import servercore.http.HttpResponse;
9+import servercore.http.HttpServer;
510 import servercore.servelet.reflect.Action;
611
712 public class LoginCheck extends Action{
813
9- public HttpResponse execute(HttpRequest request) {
14+ public HttpResponse execute(HttpRequest request) throws NoSuchAlgorithmException {
15+ EasyIni ini = new EasyIni("./config/user_pass.ini");
16+
1017 HttpResponse res = new HttpResponse();
1118 res.addHeader("Cache-Control", "no-cache");
1219 String uid = request.getPostParams().get("user_id");
1320 String pass = request.getPostParams().get("password");
14- if("tak".equals(uid) && "tak".equals(pass)) {
21+ String ini_pass = ini.getPro(uid);
22+ String md5_pass = null;
23+ if(ini_pass != null) {
24+ md5_pass = CodeMD5.crypt(uid + ":" + pass);
25+ }
26+ if(ini_pass != null && ini_pass.equals(md5_pass)) {
1527 res.addHeader("Set-Cookie", "SESSIONID=cookieok");
1628 res.setStatusCore(204);
1729 } else {
--- branch/Basic 0.2x/models/models/ContentsBiz.java (revision 55)
+++ branch/Basic 0.2x/models/models/ContentsBiz.java (revision 56)
@@ -37,4 +37,27 @@
3737 return data;
3838 }
3939
40+ public int insertData(HashMap<String,String> data) throws Exception {
41+ String[] culmname = {"mx"};
42+ String body = data.get("body");
43+ body = body.replaceAll("\\'", "''");
44+ String title = data.get("title");
45+ title = title.replaceAll("\\'", "''");
46+ TableDataQuery query = new TableDataQuery(ConstUtil.Test01);
47+ String sql = "insert into textfeeds (title, text) values" +
48+ " ('" + title + "', '" + body + "')";
49+ String check_sql = "select max(text_index) as mx from textfeeds";
50+ int max_index = 0;
51+ try {
52+ query.getConnection();
53+ int ret = query.executeUpdate(sql);
54+ query.setColumnName(culmname);
55+ String max = query.executeQuery(check_sql).get(0).get("mx");
56+ max_index = Integer.parseInt(max);
57+ query.executeUpdate("commit");
58+ } finally {
59+ query.closeConnection();
60+ }
61+ return max_index;
62+ }
4063 }
--- branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 55)
+++ branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 56)
@@ -36,6 +36,8 @@
3636 String LastMod = editTimeZone(res.getLastModified());
3737 if(res.getStatusCore() == 200) {
3838 resStr += "HTTP/1.1 200 OK\r\n";
39+ } else if(res.getStatusCore() == 201) {
40+ resStr += "HTTP/1.1 201 Created\r\n";
3941 } else if(res.getStatusCore() == 204) {
4042 resStr += "HTTP/1.1 204 No Content\r\n";
4143 } else if(res.getStatusCore() == 301) {
--- branch/Basic 0.2x/src/servercore/job/GeneratePage.java (revision 55)
+++ branch/Basic 0.2x/src/servercore/job/GeneratePage.java (revision 56)
@@ -42,6 +42,7 @@
4242 res.setStatusCore(404);
4343 } catch (Exception e) {
4444 res.setStatusCore(500);
45+ e = (Exception)e.getCause();
4546 String msg = e.getMessage() == null ? e.toString() : e.getMessage();
4647 res.setResponseStr(msg);
4748 e.printStackTrace();
Show on old repository browser