]> WPIA git - gigi.git/commitdiff
Convert strange flags to Groups.
authorFelix Dörre <felix@dogcraft.de>
Wed, 24 Sep 2014 18:14:27 +0000 (20:14 +0200)
committerJanis Streib <janis@dogcraft.de>
Wed, 31 Dec 2014 01:35:39 +0000 (02:35 +0100)
doc/tableStructure.sql
src/org/cacert/gigi/dbObjects/User.java
src/org/cacert/gigi/pages/LoginPage.java
src/org/cacert/gigi/util/Notary.java

index 0b52c152ff98b58c5fbc9e41cb6b8b425c2eee0d..a6f78ed00acdcc9987c4c09e21478caf82721f9c 100644 (file)
@@ -14,13 +14,10 @@ CREATE TABLE `users` (
   `locid` int(7) NOT NULL DEFAULT '0',
   `listme` int(1) NOT NULL DEFAULT '0',
   `contactinfo` varchar(255) NOT NULL DEFAULT '',
   `locid` int(7) NOT NULL DEFAULT '0',
   `listme` int(1) NOT NULL DEFAULT '0',
   `contactinfo` varchar(255) NOT NULL DEFAULT '',
-  `admin` tinyint(1) NOT NULL DEFAULT '0',
   `language` varchar(5) NOT NULL DEFAULT '',
   `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
   `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
   `deleted` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
   `language` varchar(5) NOT NULL DEFAULT '',
   `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
   `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
   `deleted` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
-  `locked` tinyint(1) NOT NULL DEFAULT '0',
-  `assurer_blocked` tinyint(1) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`),
   KEY `ccid` (`ccid`),
   KEY `regid` (`regid`),
   PRIMARY KEY (`id`),
   KEY `ccid` (`ccid`),
   KEY `regid` (`regid`),
@@ -274,7 +271,7 @@ DROP TABLE IF EXISTS `user_groups`;
 CREATE TABLE IF NOT EXISTS `user_groups` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `user` int(11) NOT NULL,
 CREATE TABLE IF NOT EXISTS `user_groups` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `user` int(11) NOT NULL,
-  `permission` enum('supporter','arbitrator','blockedassuree','blockedassurer','ttp-assurer','ttp-applicant', 'codesigning') NOT NULL,
+  `permission` enum('supporter','arbitrator','blockedassuree','blockedassurer','blockedlogin','ttp-assurer','ttp-applicant', 'codesigning') NOT NULL,
   `granted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `deleted` timestamp NULL DEFAULT NULL,
   `grantedby` int(11) NOT NULL,
   `granted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `deleted` timestamp NULL DEFAULT NULL,
   `grantedby` int(11) NOT NULL,
index b67da929b79ced837ada340b3fa1275f595c964c..dc79fd960cf7514d8e41b65373bbff267d73d5f0 100644 (file)
@@ -124,7 +124,7 @@ public class User implements IdCachable {
         if (id != 0) {
             throw new Error("refusing to insert");
         }
         if (id != 0) {
             throw new Error("refusing to insert");
         }
-        GigiPreparedStatement query = DatabaseConnection.getInstance().prepare("insert into `users` set `email`=?, `password`=?, " + "`fname`=?, `mname`=?, `lname`=?, " + "`suffix`=?, `dob`=?, `created`=NOW(), locked=0, `language`=?");
+        GigiPreparedStatement query = DatabaseConnection.getInstance().prepare("insert into `users` set `email`=?, `password`=?, " + "`fname`=?, `mname`=?, `lname`=?, " + "`suffix`=?, `dob`=?, `created`=NOW(), `language`=?");
         query.setString(1, email);
         query.setString(2, PasswordHash.hash(password));
         query.setString(3, name.fname);
         query.setString(1, email);
         query.setString(2, PasswordHash.hash(password));
         query.setString(3, name.fname);
index ee6a6e981daaf329ae7caaca45a86bfb36babfff..e647c053bd553b75934cc833aca375dc49f279b3 100644 (file)
@@ -12,6 +12,7 @@ import javax.servlet.http.HttpSession;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.util.PasswordHash;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.util.PasswordHash;
@@ -65,7 +66,7 @@ public class LoginPage extends Page {
     private void tryAuthWithUnpw(HttpServletRequest req) {
         String un = req.getParameter("username");
         String pw = req.getParameter("password");
     private void tryAuthWithUnpw(HttpServletRequest req) {
         String un = req.getParameter("username");
         String pw = req.getParameter("password");
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `password`, `id` FROM `users` WHERE `email`=? AND locked='0' AND verified='1'");
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `password`, `id` FROM `users` WHERE `email`=? AND verified='1'");
         ps.setString(1, un);
         GigiResultSet rs = ps.executeQuery();
         if (rs.next()) {
         ps.setString(1, un);
         GigiResultSet rs = ps.executeQuery();
         if (rs.next()) {
@@ -82,7 +83,7 @@ public class LoginPage extends Page {
 
     private void tryAuthWithCertificate(HttpServletRequest req, X509Certificate x509Certificate) {
         String serial = x509Certificate.getSerialNumber().toString(16).toUpperCase();
 
     private void tryAuthWithCertificate(HttpServletRequest req, X509Certificate x509Certificate) {
         String serial = x509Certificate.getSerialNumber().toString(16).toUpperCase();
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `memid` FROM `certs` WHERE `serial`=? AND `disablelogin`='0' AND `revoked` = " + "'0000-00-00 00:00:00'");
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `memid` FROM `certs` WHERE `serial`=? AND `disablelogin`='0' AND `revoked` = '0000-00-00 00:00:00'");
         ps.setString(1, serial);
         GigiResultSet rs = ps.executeQuery();
         if (rs.next()) {
         ps.setString(1, serial);
         GigiResultSet rs = ps.executeQuery();
         if (rs.next()) {
@@ -91,7 +92,12 @@ public class LoginPage extends Page {
         rs.close();
     }
 
         rs.close();
     }
 
+    private static final Group LOGIN_BLOCKED = Group.getByString("blockedlogin");
+
     private void loginSession(HttpServletRequest req, User user) {
     private void loginSession(HttpServletRequest req, User user) {
+        if (user.isInGroup(LOGIN_BLOCKED)) {
+            return;
+        }
         req.getSession().invalidate();
         HttpSession hs = req.getSession();
         hs.setAttribute(LOGGEDIN, true);
         req.getSession().invalidate();
         HttpSession hs = req.getSession();
         hs.setAttribute(LOGGEDIN, true);
index d1f92c801caedab6526f07595b582cd02f4b51f0..2b1a2d923997d2b15c016a5a4deed5a1e898b026 100644 (file)
@@ -7,6 +7,7 @@ import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.Name;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.output.DateSelector;
 import org.cacert.gigi.dbObjects.Name;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.output.DateSelector;
@@ -42,6 +43,10 @@ public class Notary {
         }
     }
 
         }
     }
 
+    public static final Group ASSURER_BLOCKED = Group.getByString("blockedassurer");
+
+    public static final Group ASSUREE_BLOCKED = Group.getByString("blockedassuree");
+
     /**
      * This method assures another user.
      * 
     /**
      * This method assures another user.
      * 
@@ -66,7 +71,15 @@ public class Notary {
      */
     public synchronized static void assure(User assurer, User assuree, Name assureeName, Date dob, int awarded, String location, String date) throws GigiApiException {
         GigiApiException gae = new GigiApiException();
      */
     public synchronized static void assure(User assurer, User assuree, Name assureeName, Date dob, int awarded, String location, String date) throws GigiApiException {
         GigiApiException gae = new GigiApiException();
-
+        if (assuree.isInGroup(ASSUREE_BLOCKED)) {
+            gae.mergeInto(new GigiApiException("The assuree is blocked."));
+        }
+        if (assurer.isInGroup(ASSURER_BLOCKED)) {
+            gae.mergeInto(new GigiApiException("The assurer is blocked."));
+        }
+        if ( !gae.isEmpty()) {
+            throw gae;
+        }
         if (date == null || date.equals("")) {
             gae.mergeInto(new GigiApiException("You must enter the date when you met the assuree."));
         } else {
         if (date == null || date.equals("")) {
             gae.mergeInto(new GigiApiException("You must enter the date when you met the assuree."));
         } else {