Merge branch 'features1.4/user' into develop-1.4
This commit is contained in:
commit
4ea0fdd202
|
@ -2,7 +2,7 @@
|
|||
|
||||
-- DROP SEQUENCE public."T_USER_user_id_seq";
|
||||
|
||||
CREATE SEQUENCE public."T_USER_user_id_seq";
|
||||
CREATE SEQUENCE public."t_user_id_seq";
|
||||
|
||||
ALTER SEQUENCE public."T_USER_user_id_seq"
|
||||
ALTER SEQUENCE public."t_user_id_seq"
|
||||
OWNER TO monnethicadmin;
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
CREATE TABLE public."T_USER"
|
||||
(
|
||||
user_id integer NOT NULL DEFAULT nextval('"T_USER_user_id_seq"'::regclass),
|
||||
user_id integer NOT NULL DEFAULT nextval('"t_user_id_seq"'::regclass),
|
||||
name character varying(255) COLLATE pg_catalog."default" NOT NULL,
|
||||
firstname character varying(255) COLLATE pg_catalog."default" NOT NULL,
|
||||
email character varying(255) COLLATE pg_catalog."default" NOT NULL,
|
||||
|
|
|
@ -36,6 +36,11 @@ public class User {
|
|||
public User() {
|
||||
}
|
||||
|
||||
public User(String email, String user_hash){
|
||||
this.email = email;
|
||||
this.user_hash = user_hash;
|
||||
}
|
||||
|
||||
public User(String name, String firstname, String email, String password, String association) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
|
|
|
@ -2,6 +2,7 @@ package database.user;
|
|||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.stmt.DeleteBuilder;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.UpdateBuilder;
|
||||
|
@ -62,6 +63,13 @@ public class UserDao {
|
|||
}
|
||||
}
|
||||
|
||||
public void deleteUser(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
DeleteBuilder<User, String> deleteBuilder = userDao.deleteBuilder();
|
||||
deleteBuilder.where().eq("email",email);
|
||||
deleteBuilder.delete();
|
||||
}
|
||||
|
||||
private boolean verifyUserExist(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
|
@ -98,7 +106,7 @@ public class UserDao {
|
|||
}
|
||||
|
||||
|
||||
public void approveUser (String email) throws Exception{
|
||||
public void approveUser (String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
UpdateBuilder<User, String> updateBuilder = userDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("approved",true);
|
||||
|
|
|
@ -3,6 +3,7 @@ package restImplementation;
|
|||
import blockchain.query.TransactionWrapper;
|
||||
import database.user.User;
|
||||
import database.user.UserDao;
|
||||
import org.hyperledger.fabric.sdk.BlockEvent;
|
||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||
|
||||
import java.time.Instant;
|
||||
|
@ -17,6 +18,7 @@ public class UserImplementation {
|
|||
|
||||
//CREATE USER HASH. TEMPORARY USER HASH IS : name+email+firstname+association
|
||||
user.setUser_hash(hashPassword(user.getName()+user.getEmail()+user.getFirstname()+user.getAssociation()));
|
||||
System.out.println("user hash: "+user.getUser_hash());
|
||||
|
||||
//REGISTER IN BLOCKCHAIN
|
||||
if(user.getPhone()==null){
|
||||
|
@ -48,6 +50,23 @@ public class UserImplementation {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void approveUser(User user) throws Exception{
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
UserDao userDao = new UserDao();
|
||||
transactionWrapper.sendTransaction("setUserPermission",new String[]{user.getUser_hash()});
|
||||
userDao.approveUser(user.getEmail());
|
||||
}
|
||||
|
||||
|
||||
public void deleteUser(User user) throws Exception {
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
transactionWrapper.sendTransaction("deleteUser",new String[]{user.getUser_hash()});
|
||||
UserDao userDao = new UserDao();
|
||||
userDao.deleteUser(user.getEmail());
|
||||
}
|
||||
|
||||
|
||||
public User getUser(String email, String password) throws Exception{
|
||||
UserDao userDao = new UserDao();
|
||||
User user1 = userDao.getUser(email);
|
||||
|
@ -63,18 +82,20 @@ public class UserImplementation {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String,String> userLogger(User user) throws Exception {
|
||||
UserDao userDao = new UserDao();
|
||||
Map<String,String> response = new HashMap<>();
|
||||
|
||||
User userResponse = userDao.getUser(user.getEmail());
|
||||
|
||||
if(userResponse != null){
|
||||
String hash = userResponse.getPassword();
|
||||
|
||||
if(!BCrypt.checkpw(user.getPassword(), hash)){
|
||||
response.put("response","Not Allowed");
|
||||
}else{
|
||||
response.put("response","Ok");
|
||||
response.put("response","true");
|
||||
response.put("userHash",userResponse.getUser_hash());
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -22,6 +22,12 @@ public class UserResource {
|
|||
Map<String,String> userHashResponse = userImplementation.registerUser(user);
|
||||
|
||||
if(Boolean.parseBoolean(userHashResponse.get("response"))){
|
||||
|
||||
//TEMPORARY AUTOMATIC APPROVE
|
||||
user.setUser_hash(userHashResponse.get("userHash"));
|
||||
userImplementation.approveUser(user);
|
||||
//
|
||||
|
||||
StringResponse responseS = new StringResponse("Ok",userHashResponse.get("userHash"));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(responseS);
|
||||
}else {
|
||||
|
@ -35,6 +41,21 @@ public class UserResource {
|
|||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/approve", method = RequestMethod.POST,produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<StringResponse> approveUser(@Valid @RequestBody User user){
|
||||
try{
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
userImplementation.approveUser(user);
|
||||
StringResponse response = new StringResponse("Ok",user.getUser_hash());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(response);
|
||||
}catch (Exception e){
|
||||
StringResponse response = new StringResponse("Error: "+e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST,produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<StringResponse> login(@Valid @RequestBody User user){
|
||||
|
@ -89,19 +110,21 @@ public class UserResource {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
@PostMapping(value = "/delete", produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<StringResponse> removeUser(@Valid @RequestBody User user){
|
||||
try{
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
|
||||
userImplementation.deleteUser(user);
|
||||
StringResponse responseS = new StringResponse("Ok");
|
||||
return ResponseEntity.status(HttpStatus.OK).body(responseS);
|
||||
}catch (Exception e){
|
||||
StringResponse responseS = new StringResponse(e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@PostMapping(value = "/update")
|
||||
|
|
|
@ -19,7 +19,7 @@ public class DeleteUserTest {
|
|||
try{
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String functionName = "deleteUser";
|
||||
String[] args = new String[]{"$2a$10$6vjtplKcFKKaE0HKGd.8VOJi0xugc5Ojbf9m5LqyZ8mzU5nfcxt5."};
|
||||
String[] args = new String[]{"$2a$10$04YjBhcKPG.DD8abC/AnhOwTIbYH1x0Gr78XXVhAd6551c3Cb21i2"};
|
||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||
}catch (Exception e){
|
||||
|
|
|
@ -22,7 +22,7 @@ public class ReadUserTest {
|
|||
try{
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String functionName = "readUser";
|
||||
String[] args = new String[]{"$2a$10$6vjtplKcFKKaE0HKGd.8VOJi0xugc5Ojbf9m5LqyZ8mzU5nfcxt5."};
|
||||
String[] args = new String[]{"$2a$10$N1C1lPeVMZ6oY4hSyX2cbuKBoGtJ0yWSXIgBaZ1RsI8QfaoTHCYi2"};
|
||||
String response = queryWrapper.sendQuery(functionName,args);
|
||||
if(response != null){
|
||||
JsonReader reader = Json.createReader(new StringReader(response));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package restImplementation;
|
||||
|
||||
import database.user.User;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@ -11,8 +12,10 @@ import java.util.Map;
|
|||
public class UserImplementationTest {
|
||||
private static Logger logger = Logger.getLogger(UserImplementationTest.class);
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void RegisterUserWithoutPhone() {
|
||||
BasicConfigurator.configure();
|
||||
User userTest = new User("TotoName","TotoFirstName","TotoEmail@gmail.com","totoPassword1234$","gonette");
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
|
||||
|
@ -26,14 +29,12 @@ public class UserImplementationTest {
|
|||
} catch (Exception e){
|
||||
logger.warn("Error: "+e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void RegisterUserWithPhone() {
|
||||
BasicConfigurator.configure();
|
||||
User userTest = new User("TataName","TataFirstName","TataEmail@gmail.com","tataPassword1234$","0607080900","gonette");
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
|
||||
|
@ -48,6 +49,55 @@ public class UserImplementationTest {
|
|||
logger.warn("Error: "+e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void userLoggerTest(){
|
||||
BasicConfigurator.configure();
|
||||
User userTest = new User("TataName","TataFirstName","TataEmail@gmail.com","tataPassword1234$","0607080900","gonette");
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
try{
|
||||
Map<String,String> responseTest = userImplementation.userLogger(userTest);
|
||||
if(Boolean.parseBoolean(responseTest.get("response"))){
|
||||
StringResponse responseS = new StringResponse("Ok",responseTest.get("userHash"));
|
||||
logger.info("StringResponse is: "+responseS.getResponse()+". User hash: "+responseS.getUserHash());
|
||||
}
|
||||
} catch (Exception e){
|
||||
logger.warn("Error: "+e);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void approveUserTest() {
|
||||
BasicConfigurator.configure();
|
||||
User userTest = new User("TotoEmail@gmail.com","$2a$10$Hx5w0c6WM0gJkd0/ZKXZsOyes7UdxYm95TVdG2cBwNjtTk007WKuS");
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
try {
|
||||
userImplementation.approveUser(userTest);
|
||||
}catch (Exception e){
|
||||
logger.warn("Error: "+e);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void deleteUserTest(){
|
||||
BasicConfigurator.configure();
|
||||
User userTest = new User("TataEmail@gmail.com","$2a$10$N1C1lPeVMZ6oY4hSyX2cbuKBoGtJ0yWSXIgBaZ1RsI8QfaoTHCYi2");
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
try{
|
||||
userImplementation.deleteUser(userTest);
|
||||
} catch (Exception e){
|
||||
logger.warn("Error: "+e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue