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);
22 PreparedStatement ps = DatabaseConnection
25 "SELECT `fname`, `lname`, `dob`, `email` FROM `users` WHERE id=?");
27 ResultSet rs = ps.executeQuery();
29 name = new Name(rs.getString(1), rs.getString(2));
31 email = rs.getString(4);
34 } catch (SQLException e) {
43 public String getFname() {
46 public String getLname() {
49 public String getMname() {
52 public Name getName() {
55 public void setMname(String mname) {
56 this.name.mname = mname;
58 public String getSuffix() {
61 public void setSuffix(String suffix) {
62 this.name.suffix = suffix;
64 public Date getDob() {
67 public void setDob(Date dob) {
70 public String getEmail() {
73 public void setEmail(String email) {
76 public void setId(int id) {
79 public void setFname(String fname) {
80 this.name.fname = fname;
82 public void setLname(String lname) {
83 this.name.lname = lname;
85 public void insert(String password) throws SQLException {
87 throw new Error("refusing to insert");
89 PreparedStatement query = DatabaseConnection.getInstance().prepare(
90 "insert into `users` set `email`=?, `password`=?, "
91 + "`fname`=?, `mname`=?, `lname`=?, "
92 + "`suffix`=?, `dob`=?, `created`=NOW(), locked=0");
93 query.setString(1, email);
94 query.setString(2, PasswordHash.hash(password));
95 query.setString(3, name.fname);
96 query.setString(4, name.mname);
97 query.setString(5, name.lname);
98 query.setString(6, name.suffix);
99 query.setDate(7, new java.sql.Date(dob.getTime()));
101 id = DatabaseConnection.lastInsertId(query);
102 System.out.println("Inserted: " + id);
105 public boolean canAssure() throws SQLException {
106 if (getAssurancePoints() < 100) {
110 return hasPassedCATS();
113 public boolean hasPassedCATS() throws SQLException {
114 PreparedStatement query = DatabaseConnection.getInstance().prepare(
115 "SELECT 1 FROM `cats_passed` where `user_id`=?");
117 ResultSet rs = query.executeQuery();
124 public int getAssurancePoints() throws SQLException {
125 PreparedStatement query = DatabaseConnection
128 "SELECT sum(points) FROM `notary` where `to`=? AND `deleted`=0");
130 ResultSet rs = query.executeQuery();
133 points = rs.getInt(1);
138 public int getExperiencePoints() throws SQLException {
139 PreparedStatement query = DatabaseConnection.getInstance().prepare(
140 "SELECT count(*) FROM `notary` where `from`=? AND `deleted`=0");
142 ResultSet rs = query.executeQuery();
145 points = rs.getInt(1) * 2;
151 public boolean equals(Object obj) {
152 if (!(obj instanceof User)) {
156 return name.equals(s.name) && email.equals(s.email)
157 && dob.equals(s.dob);
159 public int getMaxAssurePoints() throws SQLException {
160 int exp = getExperiencePoints();