]> WPIA git - gigi.git/blob - src/org/cacert/gigi/dbObjects/SupportedUser.java
ADD: Functoinality behind SE change dob and SE change name
[gigi.git] / src / org / cacert / gigi / dbObjects / SupportedUser.java
1 package org.cacert.gigi.dbObjects;
2
3 import java.sql.Date;
4
5 import org.cacert.gigi.GigiApiException;
6 import org.cacert.gigi.database.DatabaseConnection;
7 import org.cacert.gigi.database.GigiPreparedStatement;
8
9 public class SupportedUser {
10
11     private User target, supporter;
12
13     private String ticket;
14
15     public SupportedUser(User target, User supporter, String ticket) {
16         this.supporter = supporter;
17         this.target = target;
18         this.ticket = ticket;
19     }
20
21     public boolean setName(Name newName) throws GigiApiException {
22         if (newName.equals(target.getName())) {
23             return false;
24         }
25         writeSELog("SE Name change");
26         target.setName(newName);
27         return true;
28     }
29
30     public boolean setDob(Date dob) throws GigiApiException {
31         if (dob.toString().equals(target.getDoB().toString())) {
32             return false;
33         }
34         writeSELog("SE dob change");
35         target.setDoB(dob);
36         return true;
37     }
38
39     public void revokeAllCertificates() throws GigiApiException {
40         writeSELog("SE Revoke certificates");
41         Certificate[] certs = target.getCertificates(false);
42         for (int i = 0; i < certs.length; i++) {
43             certs[i].revoke();
44         }
45     }
46
47     private void writeSELog(String type) throws GigiApiException {
48         if (ticket == null) {
49             throw new GigiApiException("No ticket set!");
50         }
51         GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("INSERT INTO adminLog SET uid=?, admin=?, type=?, information=?");
52         prep.setInt(1, target.getId());
53         prep.setInt(2, supporter.getId());
54         prep.setString(3, type);
55         prep.setString(4, ticket);
56         prep.executeUpdate();
57     }
58
59     public int getId() {
60         return target.getId();
61     }
62
63     public Certificate[] getCertificates(boolean includeRevoked) {
64         return target.getCertificates(includeRevoked);
65     }
66
67     public String getTicket() {
68         return ticket;
69     }
70
71     public User getTargetUser() {
72         return target;
73     }
74
75     public void submitSupportAction() throws GigiApiException {
76         target.rawUpdateUserData();
77     }
78
79 }