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.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public interface AccountManagement {
@ -41,15 +42,24 @@ public interface AccountManagement {
try {
if(!rs.getString(2).equals(password))
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) {
e.printStackTrace();
}
return null;
}
static User register(List<String> necessaryInfo, String User){
//todo
return null;
static User register(String userType, List<String> necessaryInfo) throws GExcptSQL {
String sql = "INSERT INTO "+userType+" VALUES(\'";
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){
//todo
@ -59,7 +69,7 @@ public interface AccountManagement {
}
static User getUser(String userType){
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) {
e.printStackTrace();
} catch (IllegalAccessException e) {
@ -73,16 +83,12 @@ public interface AccountManagement {
}
return null;
}
static User createUser(String userType, ResultSet rs) {
static User createUser(String userType, List<String> necessaryInfo) {
User user = getUser(userType);
try {
user.setId(rs.getString("id"));
user.setName(rs.getString("name"));
user.setE_mail_location(rs.getString("e_mail_location"));
user.setPhone_number(rs.getString("phone_number"));
} catch (SQLException e) {
e.printStackTrace();
}
user.setId(necessaryInfo.get(0));
user.setName(necessaryInfo.get(1));
user.setE_mail_location(necessaryInfo.get(2));
user.setPhone_number(necessaryInfo.get(3));
return user;
}
}

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

Loading…
Cancel
Save