1 package org.cacert.gigi;
3 import java.sql.PreparedStatement;
4 import java.sql.ResultSet;
5 import java.sql.SQLException;
8 import org.cacert.gigi.database.DatabaseConnection;
9 import org.cacert.gigi.util.PasswordHash;
14 Name name = new Name(null, null, null, null);
22 PreparedStatement ps = DatabaseConnection
25 "SELECT `fname`, `lname`,`mname`, `suffix`, `dob`, `email` FROM `users` WHERE id=?");
27 ResultSet rs = ps.executeQuery();
29 name = new Name(rs.getString(1), rs.getString(2),
30 rs.getString(3), rs.getString(4));
32 email = rs.getString(6);
35 } catch (SQLException e) {
44 public String getFname() {
47 public String getLname() {
50 public String getMname() {
53 public Name getName() {
56 public void setMname(String mname) {
57 this.name.mname = mname;
59 public String getSuffix() {
62 public void setSuffix(String suffix) {
63 this.name.suffix = suffix;
65 public Date getDob() {
68 public void setDob(Date dob) {
71 public String getEmail() {
74 public void setEmail(String email) {
77 public void setId(int id) {
80 public void setFname(String fname) {
81 this.name.fname = fname;
83 public void setLname(String lname) {
84 this.name.lname = lname;
86 public void insert(String password) throws SQLException {
88 throw new Error("refusing to insert");
90 PreparedStatement query = DatabaseConnection.getInstance().prepare(
91 "insert into `users` set `email`=?, `password`=?, "
92 + "`fname`=?, `mname`=?, `lname`=?, "
93 + "`suffix`=?, `dob`=?, `created`=NOW(), locked=0");
94 query.setString(1, email);
95 query.setString(2, PasswordHash.hash(password));
96 query.setString(3, name.fname);
97 query.setString(4, name.mname);
98 query.setString(5, name.lname);
99 query.setString(6, name.suffix);
100 query.setDate(7, new java.sql.Date(dob.getTime()));
102 id = DatabaseConnection.lastInsertId(query);
103 System.out.println("Inserted: " + id);
106 public boolean canAssure() throws SQLException {
107 if (getAssurancePoints() < 100) {
111 return hasPassedCATS();
114 public boolean hasPassedCATS() throws SQLException {
115 PreparedStatement query = DatabaseConnection.getInstance().prepare(
116 "SELECT 1 FROM `cats_passed` where `user_id`=?");
118 ResultSet rs = query.executeQuery();
125 public int getAssurancePoints() throws SQLException {
126 PreparedStatement query = DatabaseConnection
129 "SELECT sum(points) FROM `notary` where `to`=? AND `deleted`=0");
131 ResultSet rs = query.executeQuery();
134 points = rs.getInt(1);
139 public int getExperiencePoints() throws SQLException {
140 PreparedStatement query = DatabaseConnection.getInstance().prepare(
141 "SELECT count(*) FROM `notary` where `from`=? AND `deleted`=0");
143 ResultSet rs = query.executeQuery();
146 points = rs.getInt(1) * 2;
152 public boolean equals(Object obj) {
153 if (!(obj instanceof User)) {
157 return name.equals(s.name) && email.equals(s.email)
158 && dob.toString().equals(s.dob.toString()); // This is due to
161 public int getMaxAssurePoints() throws SQLException {
162 int exp = getExperiencePoints();