public void updateUserData() throws SQLException, GigiApiException {
synchronized (Notary.class) {
if (getAssurancePoints() != 0) {
- updateUserData();
throw new GigiApiException("No change after assurance allowed.");
}
PreparedStatement update = DatabaseConnection.getInstance().prepare("UPDATE users SET fname=?, lname=?, mname=?, suffix=?, dob=? WHERE id=?");
import javax.servlet.http.HttpServletRequest;
+import org.cacert.gigi.GigiApiException;
import org.cacert.gigi.localisation.Language;
public class DateSelector implements Outputable {
out.print("\" size=\"4\" autocomplete=\"off\">");
}
- public void update(HttpServletRequest r) {
- String dayS = r.getParameter(names[0]);
- if (dayS != null) {
- day = parseIntSafe(dayS);
- }
-
- String monthS = r.getParameter(names[1]);
- if (monthS != null) {
- month = parseIntSafe(monthS);
- }
+ public void update(HttpServletRequest r) throws GigiApiException {
+ try {
+ String dayS = r.getParameter(names[0]);
+ if (dayS != null) {
+ day = Integer.parseInt(dayS);
+ }
- String yearS = r.getParameter(names[2]);
- if (yearS != null) {
- year = parseIntSafe(yearS);
- }
- }
+ String monthS = r.getParameter(names[1]);
+ if (monthS != null) {
+ month = Integer.parseInt(monthS);
+ }
- private int parseIntSafe(String dayS) {
- try {
- return Integer.parseInt(dayS);
+ String yearS = r.getParameter(names[2]);
+ if (yearS != null) {
+ year = Integer.parseInt(yearS);
+ }
} catch (NumberFormatException e) {
-
+ throw new GigiApiException("Unparsable date.");
}
- return 0;
}
public boolean isValid() {
import java.io.InputStreamReader;
import java.io.PrintWriter;
-import java.sql.Date;
import java.sql.SQLException;
-import java.util.Calendar;
import java.util.Map;
-import java.util.TimeZone;
-
import javax.servlet.http.HttpServletRequest;
import org.cacert.gigi.GigiApiException;
import org.cacert.gigi.User;
import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.CertificateValiditySelector;
import org.cacert.gigi.output.DateSelector;
import org.cacert.gigi.output.Form;
import org.cacert.gigi.output.template.Template;
public class MyDetailsForm extends Form {
+ private static Template assured = new Template(MyDetails.class.getResource("MyDetailsFormAssured.templ"));
+
private static Template templ;
static {
templ = new Template(new InputStreamReader(MyDetailsForm.class.getResourceAsStream("MyDetailsForm.templ")));
private User target;
+ private DateSelector ds;
+
public MyDetailsForm(HttpServletRequest hsr, User target) {
super(hsr);
this.target = target;
+ this.ds = new DateSelector("day", "month", "year", target.getDob());
}
@Override
target.setLname(newLname);
target.setMname(newMname);
target.setSuffix(newSuffix);
- int newYear = Integer.parseInt(req.getParameter("year"));
- int newMonth = Integer.parseInt(req.getParameter("month"));
- int newDay = Integer.parseInt(req.getParameter("day"));
- Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- cal.set(Calendar.YEAR, newYear);
- cal.set(Calendar.MONTH, newMonth);
- cal.set(Calendar.DAY_OF_MONTH, newDay);
- target.setDob(new Date(cal.getTimeInMillis()));
+ ds.update(req);
+ target.setDob(ds.getDate());
target.updateUserData();
} else {
throw new GigiApiException("No change after assurance allowed.");
vars.put("mname", target.getMname() == null ? "" : HTMLEncoder.encodeHTML(target.getMname()));
vars.put("lname", HTMLEncoder.encodeHTML(target.getLname()));
vars.put("suffix", target.getSuffix() == null ? "" : HTMLEncoder.encodeHTML(target.getSuffix()));
- DateSelector ds = new DateSelector("day", "month", "year", target.getDob());
- vars.put("DoB", ds);
vars.put("details", "");
- templ.output(out, l, vars);
+ try {
+ if (target.getAssurancePoints() == 0) {
+ vars.put("DoB", ds);
+ templ.output(out, l, vars);
+ } else {
+ vars.put("DoB", CertificateValiditySelector.getDateFormat().format(target.getDob()));
+ assured.output(out, l, vars);
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
}
}
--- /dev/null
+<table class="wrapper dataTable" width="400">
+<thead>
+ <tr>
+ <th colspan="2"><?=_My Details?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td width="125"><?=_First Name?>: </td>
+ <td width="125"><?=$fname?></td>
+ </tr>
+ <tr>
+ <td valign="top"><?=_Middle Name(s)?><br>
+ (<?=_optional?>)
+ </td>
+ <td><?=$mname?></td>
+ </tr>
+ <tr>
+ <td><?=_Last Name?>: </td>
+ <td><?=$lname?></td>
+ </tr>
+ <tr>
+ <td><?=_Suffix?><br>
+ (<?=_optional?>)</td>
+ <td><?=$suffix?></td>
+ </tr>
+ <tr>
+ <td><?=_Date of Birth?><br>
+ (<?=_dd/mm/yyyy?>)</td>
+ <td><?=$DoB?></td>
+ </tr>
+ <tr>
+ <td colspan="2" class="title"><?=_Show account history?></td>
+ </tr>
+ <tr>
+ <td colspan="2" class="title"><?=_View secret question & answers and OTP phrases?></td>
+ </tr>
+ <?=$details?>
+ <tr><td colspan="2"><input type="submit" name="processDetails" value="<?=_Update?>"></td>
+ </tr>
+ </tbody>
+</table>
import javax.servlet.http.HttpServletRequest;
import org.cacert.gigi.EmailAddress;
+import org.cacert.gigi.GigiApiException;
import org.cacert.gigi.User;
import org.cacert.gigi.database.DatabaseConnection;
import org.cacert.gigi.email.EmailProvider;
country = "1".equals(r.getParameter("country"));
regional = "1".equals(r.getParameter("regional"));
radius = "1".equals(r.getParameter("radius"));
- myDoB.update(r);
+ try {
+ myDoB.update(r);
+ } catch (GigiApiException e) {
+ }
}
@Override
String email = createUniqueName() + "@e.de";
int id = createVerifiedUser("Kurti", "Hansel", email, TEST_PASSWORD);
String cookie = login(email, TEST_PASSWORD);
- assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "lname=Hansel&fname=Kurti&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
+ assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "lname=Hansel&fname=Kurti&mname=&suffix=&day=1&month=2&year=2000&processDetails", 0));
User u = User.getById(id);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.set(Calendar.YEAR, 2000);
- cal.set(Calendar.DAY_OF_MONTH, 1);
+ cal.set(Calendar.DAY_OF_MONTH, Calendar.FEBRUARY);
cal.set(Calendar.MONTH, 1);
Date d = new Date(cal.getTimeInMillis());
assertEquals(d.toString(), u.getDob().toString());