]> WPIA git - gigi.git/blob - src/org/cacert/gigi/dbObjects/SupportedUser.java
ADD: Use a "SupportedUser" for the user details form
[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 void setName(String fname, String mname, String lname, String suffix) throws GigiApiException {
22         writeSELog("SE Name change");
23         target.setName(new Name(fname, lname, mname, suffix));
24     }
25
26     public void setDob(Date dob) throws GigiApiException {
27         writeSELog("SE dob change");
28         target.setDoB(dob);
29     }
30
31     public void revokeAllCertificates() throws GigiApiException {
32         writeSELog("SE Revoke certificates");
33         Certificate[] certs = target.getCertificates(false);
34         for (int i = 0; i < certs.length; i++) {
35             certs[i].revoke();
36         }
37     }
38
39     private void writeSELog(String type) throws GigiApiException {
40         if (ticket == null) {
41             throw new GigiApiException("No ticket set!");
42         }
43         GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("INSERT INTO adminLog SET uid=?, admin=?, type=?, information=?");
44         prep.setInt(1, target.getId());
45         prep.setInt(2, supporter.getId());
46         prep.setString(3, type);
47         prep.setString(4, ticket);
48         prep.executeUpdate();
49     }
50
51     public int getId() {
52         return target.getId();
53     }
54
55     public Certificate[] getCertificates(boolean includeRevoked) {
56         return target.getCertificates(includeRevoked);
57     }
58
59     public String getTicket() {
60         return ticket;
61     }
62
63     public User getTargetUser() {
64         return target;
65     }
66
67 }