1,后端注册完成

wlf
zhai_lw 6 years ago
parent 3f6fc68933
commit c8746f9e72

@ -10,6 +10,7 @@ import utils.Utils;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public interface AccountManagement { public interface AccountManagement {
@ -41,15 +42,24 @@ public interface AccountManagement {
try { try {
if(!rs.getString(2).equals(password)) if(!rs.getString(2).equals(password))
throw new GExcptAccount("password wrong"); throw new GExcptAccount("password wrong");
return createUser(userType,rs); List<String> necessaryInfo = new ArrayList<>();
for(int i=0;i<4;i++){
necessaryInfo.add(rs.getString(i));
}
return createUser(userType,necessaryInfo);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
static User register(List<String> necessaryInfo, String User){ static User register(String userType, List<String> necessaryInfo) throws GExcptSQL {
//todo String sql = "INSERT INTO "+userType+" VALUES(\'";
return null; for(String info:necessaryInfo){
sql+=info+"\', \'";
}
sql =sql.substring(0,sql.length()-3)+")";
DBManagement.update(sql);
return createUser(userType, necessaryInfo);
} }
static void logout(User user){ static void logout(User user){
//todo //todo
@ -59,7 +69,7 @@ public interface AccountManagement {
} }
static User getUser(String userType){ static User getUser(String userType){
try { try {
return (Administrator)Class.forName("core.user."+ Utils.toUpperFristChar(userType)).getDeclaredConstructor().newInstance(); return (User) Class.forName("core.user."+ Utils.toUpperFristChar(userType)).getDeclaredConstructor().newInstance();
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -73,16 +83,12 @@ public interface AccountManagement {
} }
return null; return null;
} }
static User createUser(String userType, ResultSet rs) { static User createUser(String userType, List<String> necessaryInfo) {
User user = getUser(userType); User user = getUser(userType);
try { user.setId(necessaryInfo.get(0));
user.setId(rs.getString("id")); user.setName(necessaryInfo.get(1));
user.setName(rs.getString("name")); user.setE_mail_location(necessaryInfo.get(2));
user.setE_mail_location(rs.getString("e_mail_location")); user.setPhone_number(necessaryInfo.get(3));
user.setPhone_number(rs.getString("phone_number"));
} catch (SQLException e) {
e.printStackTrace();
}
return user; return user;
} }
} }

@ -1,6 +1,8 @@
package init; package init;
import core.user.utils.AccountManagement;
import dao.DBManagement; import dao.DBManagement;
import error.GExcptSQL;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebServlet;
@ -8,6 +10,8 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@WebServlet(name = "Init") @WebServlet(name = "Init")
public class Init extends HttpServlet { public class Init extends HttpServlet {

Loading…
Cancel
Save