small fixes here and there
[mir.git] / source / mircoders / servlet / ServletModuleOpenIndy.java
index 1c7ed36..32ad063 100755 (executable)
@@ -62,7 +62,7 @@ public class ServletModuleOpenIndy extends ServletModule
       postingFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDoneTemplate");
       postingFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDupeTemplate");
       directOp = MirConfig.getProp("DirectOpenposting").toLowerCase();
-                       passwdProtection = MirConfig.getProp("PasswdProtection").toLowerCase();
+      passwdProtection = MirConfig.getProp("PasswdProtection").toLowerCase();
       mainModule = new ModuleComment(DatabaseComment.getInstance());
       contentModule = new ModuleContent(DatabaseContent.getInstance());
       themenModule = new ModuleTopics(DatabaseTopics.getInstance());
@@ -83,18 +83,26 @@ public class ServletModuleOpenIndy extends ServletModule
   public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
   {
     String aid = req.getParameter("aid"); // the article id the comment will belong to
+    String language = req.getParameter("language");
+
     if (aid!=null && !aid.equals(""))
     {
-                       SimpleHash mergeData = new SimpleHash();
+      SimpleHash mergeData = new SimpleHash();
+
+      // onetimepasswd
+      if(passwdProtection.equals("yes")){
+        String passwd = this.createOneTimePasswd();
+        System.out.println(passwd);
+        HttpSession session = req.getSession(false);
+        session.setAttribute("passwd",passwd);
+        mergeData.put("passwd", passwd);
+      }
 
-                       // onetimepasswd
-                       if(passwdProtection.equals("yes")){
-                               String passwd = this.createOneTimePasswd();
-                               System.out.println(passwd);
-                               HttpSession session = req.getSession(false);
-                               session.setAttribute("passwd",passwd);
-                               mergeData.put("passwd", passwd);
-                       }
+      if (language!=null) {
+        HttpSession session = req.getSession(false);
+        session.setAttribute("Locale", new Locale(language, ""));
+        session.setAttribute("passwd",language);
+      }
 
       mergeData.put("aid", aid);
       deliver(req, res, mergeData, commentFormTemplate);
@@ -108,7 +116,7 @@ public class ServletModuleOpenIndy extends ServletModule
    */
 
   public void inscomment(HttpServletRequest req, HttpServletResponse res)
-       throws ServletModuleException,ServletModuleUserException
+  throws ServletModuleException,ServletModuleUserException
   {
     String aid = req.getParameter("to_media"); // the article id the comment will belong to
     if (aid!=null && !aid.equals(""))
@@ -126,19 +134,19 @@ public class ServletModuleOpenIndy extends ServletModule
         }
         withValues.put("is_published","1");
 
-                               //checking the onetimepasswd
-                               if(passwdProtection.equals("yes")){
-                                       HttpSession session = req.getSession(false);
-                                       String sessionPasswd = (String)session.getAttribute("passwd");
-                                       if ( sessionPasswd == null){
-                                               throw new ServletModuleUserException("Lost password");
-                                       }
-                                       String passwd = req.getParameter("passwd");
-                                       if ( passwd == null || (!sessionPasswd.equals(passwd))) {
-                                               throw new ServletModuleUserException("Missing password");
-                                       }
-                                       session.invalidate();
-                               }
+        //checking the onetimepasswd
+        if(passwdProtection.equals("yes")){
+          HttpSession session = req.getSession(false);
+          String sessionPasswd = (String)session.getAttribute("passwd");
+          if ( sessionPasswd == null){
+            throw new ServletModuleUserException("Lost password");
+          }
+          String passwd = req.getParameter("passwd");
+          if ( passwd == null || (!sessionPasswd.equals(passwd))) {
+            throw new ServletModuleUserException("Missing password");
+          }
+          session.invalidate();
+        }
 
         // inserting into database
         String id = mainModule.add(withValues);
@@ -174,14 +182,14 @@ public class ServletModuleOpenIndy extends ServletModule
     throws ServletModuleException {
     SimpleHash mergeData = new SimpleHash();
 
-               // onetimepasswd
-               if(passwdProtection.equals("yes")){
-                       String passwd = this.createOneTimePasswd();
-                       System.out.println(passwd);
-                       HttpSession session = req.getSession(false);
-                       session.setAttribute("passwd",passwd);
-                       mergeData.put("passwd", passwd);
-               }
+    // onetimepasswd
+    if(passwdProtection.equals("yes")){
+      String passwd = this.createOneTimePasswd();
+      System.out.println(passwd);
+      HttpSession session = req.getSession(false);
+      session.setAttribute("passwd",passwd);
+      mergeData.put("passwd", passwd);
+    }
 
     String maxMedia = MirConfig.getProp("ServletModule.OpenIndy.MaxMediaUploadItems");
     String numOfMedia = req.getParameter("medianum");
@@ -235,26 +243,26 @@ public class ServletModuleOpenIndy extends ServletModule
   {
     SimpleHash mergeData = new SimpleHash();
     boolean setMedia=false;
-               boolean setTopic = false;
+    boolean setTopic = false;
 
     try {
       WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
 
       HashMap withValues = mp.getParameters();
 
-                       //checking the onetimepasswd
-                       if(passwdProtection.equals("yes")){
-                               HttpSession session = req.getSession(false);
-                               String sessionPasswd = (String)session.getAttribute("passwd");
-                               if ( sessionPasswd == null){
-                                       throw new ServletModuleUserException("Lost password");
-                               }
-                               String passwd = (String)withValues.get("passwd");
-                               if ( passwd == null || (!sessionPasswd.equals(passwd))) {
-                                       throw new ServletModuleUserException("Missing password");
-                               }
-                               session.invalidate();
-                       }
+      //checking the onetimepasswd
+      if(passwdProtection.equals("yes")){
+        HttpSession session = req.getSession(false);
+        String sessionPasswd = (String)session.getAttribute("passwd");
+        if ( sessionPasswd == null){
+          throw new ServletModuleUserException("Lost password");
+        }
+        String passwd = (String)withValues.get("passwd");
+        if ( passwd == null || (!sessionPasswd.equals(passwd))) {
+          throw new ServletModuleUserException("Missing password");
+        }
+        session.invalidate();
+      }
 
       if ((((String)withValues.get("title")).length() == 0) ||
           (((String)withValues.get("description")).length() == 0) ||
@@ -309,7 +317,7 @@ public class ServletModuleOpenIndy extends ServletModule
 
       String[] to_topicsArr = mp.getParameterValues("to_topic");
 
-                       if (to_topicsArr != null && to_topicsArr.length > 0) {
+      if (to_topicsArr != null && to_topicsArr.length > 0) {
         try{
           DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr);
           setTopic = true;
@@ -516,15 +524,15 @@ public class ServletModuleOpenIndy extends ServletModule
         +"Error One or more files of unrecognized type. Sorry");
   }
 
-       protected String createOneTimePasswd(){
-               Random r = new Random();
-               int random = r.nextInt();
-               long l = System.currentTimeMillis();
-               l = (l*l*l*l)/random;
-               if(l<0) l = l * -1;
-               String returnString = ""+l;
-               return returnString.substring(5);
-       }
+  protected String createOneTimePasswd(){
+    Random r = new Random();
+    int random = r.nextInt();
+    long l = System.currentTimeMillis();
+    l = (l*l*l*l)/random;
+    if(l<0) l = l * -1;
+    String returnString = ""+l;
+    return returnString.substring(5);
+  }
 
 }