From: Felix Dörre Date: Wed, 24 Sep 2014 18:14:27 +0000 (+0200) Subject: Convert strange flags to Groups. X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=30a66c84a3f33e99bd5cbfe50b25a83acfbf5425 Convert strange flags to Groups. --- diff --git a/doc/tableStructure.sql b/doc/tableStructure.sql index 0b52c152..a6f78ed0 100644 --- a/doc/tableStructure.sql +++ b/doc/tableStructure.sql @@ -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 '', - `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', - `locked` tinyint(1) NOT NULL DEFAULT '0', - `assurer_blocked` tinyint(1) NOT NULL DEFAULT '0', 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, - `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, diff --git a/src/org/cacert/gigi/dbObjects/User.java b/src/org/cacert/gigi/dbObjects/User.java index b67da929..dc79fd96 100644 --- a/src/org/cacert/gigi/dbObjects/User.java +++ b/src/org/cacert/gigi/dbObjects/User.java @@ -124,7 +124,7 @@ public class User implements IdCachable { 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); diff --git a/src/org/cacert/gigi/pages/LoginPage.java b/src/org/cacert/gigi/pages/LoginPage.java index ee6a6e98..e647c053 100644 --- a/src/org/cacert/gigi/pages/LoginPage.java +++ b/src/org/cacert/gigi/pages/LoginPage.java @@ -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.dbObjects.Group; 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"); - 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()) { @@ -82,7 +83,7 @@ public class LoginPage extends Page { 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()) { @@ -91,7 +92,12 @@ public class LoginPage extends Page { rs.close(); } + private static final Group LOGIN_BLOCKED = Group.getByString("blockedlogin"); + private void loginSession(HttpServletRequest req, User user) { + if (user.isInGroup(LOGIN_BLOCKED)) { + return; + } req.getSession().invalidate(); HttpSession hs = req.getSession(); hs.setAttribute(LOGGEDIN, true); diff --git a/src/org/cacert/gigi/util/Notary.java b/src/org/cacert/gigi/util/Notary.java index d1f92c80..2b1a2d92 100644 --- a/src/org/cacert/gigi/util/Notary.java +++ b/src/org/cacert/gigi/util/Notary.java @@ -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.dbObjects.Group; 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. * @@ -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(); - + 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 {