|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
package core.user.utils;
|
|
|
|
|
|
|
|
|
|
import core.user.Administrator;
|
|
|
|
|
import core.user.User;
|
|
|
|
|
import dao.DBManagement;
|
|
|
|
|
import error.GExcptAccount;
|
|
|
|
|
import error.GExcptSQL;
|
|
|
|
|
import utils.Utils;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
@ -16,12 +18,12 @@ public interface AccountManagement {
|
|
|
|
|
"student",
|
|
|
|
|
"teacher"
|
|
|
|
|
};
|
|
|
|
|
static User login(String id, String password) throws GExcptSQL, GExcptAccount {
|
|
|
|
|
static User login(String id, String password) throws GExcptSQL, GExcptAccount, SQLException {
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
String sql = null;
|
|
|
|
|
String userType = null;
|
|
|
|
|
for(String userTable:userTables){
|
|
|
|
|
sql = "SELECT * FROM "+userTable+"WHERE id="+id;
|
|
|
|
|
sql = "SELECT * FROM "+userTable+" WHERE id=\'"+id+"\'";
|
|
|
|
|
try {
|
|
|
|
|
rs = DBManagement.query(sql);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -35,8 +37,9 @@ public interface AccountManagement {
|
|
|
|
|
if(rs==null){
|
|
|
|
|
throw new GExcptAccount("id "+id+"don't exists");
|
|
|
|
|
}
|
|
|
|
|
rs.next();
|
|
|
|
|
try {
|
|
|
|
|
if(rs.getString("password")!=password)
|
|
|
|
|
if(!rs.getString(2).equals(password))
|
|
|
|
|
throw new GExcptAccount("password wrong");
|
|
|
|
|
return createUser(userType,rs);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@ -56,7 +59,7 @@ public interface AccountManagement {
|
|
|
|
|
}
|
|
|
|
|
static User getUser(String userType){
|
|
|
|
|
try {
|
|
|
|
|
return (User)Class.forName("core.user."+userType).getDeclaredConstructor().newInstance();
|
|
|
|
|
return (Administrator)Class.forName("core.user."+ Utils.toUpperFristChar(userType)).getDeclaredConstructor().newInstance();
|
|
|
|
|
} catch (InstantiationException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|