update api
This commit is contained in:
parent
ff5a7f4740
commit
48da18bfdd
|
@ -32,23 +32,11 @@ public class UserDao {
|
|||
}
|
||||
|
||||
public boolean checkApprovedUser(String email) throws Exception {
|
||||
createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
User user = userDao.queryForFirst(preparedQuery);
|
||||
DatabaseHelper.closeConnection();
|
||||
return user.isApproved();
|
||||
return getUserWithEmail(email).isApproved();
|
||||
}
|
||||
|
||||
public boolean checkVerifiedUser(String email) throws Exception {
|
||||
createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
User user = userDao.queryForFirst(preparedQuery);
|
||||
DatabaseHelper.closeConnection();
|
||||
return user.isVerified();
|
||||
return getUserWithEmail(email).isVerified();
|
||||
}
|
||||
|
||||
public boolean updateUserPassword(String email, String password) throws Exception {
|
||||
|
|
|
@ -129,6 +129,31 @@ public class UserImplementation {
|
|||
return response;
|
||||
}
|
||||
|
||||
public Boolean updatePassword(String user_email, String current_password,String new_password){
|
||||
try{
|
||||
UserDao userDao = new UserDao();
|
||||
System.out.println("Get User :");
|
||||
User u = userDao.getUserWithEmail(dataEncryption.encryptData(user_email));
|
||||
System.out.println(u);
|
||||
if(u != null){
|
||||
String hash = u.getPassword();
|
||||
if(!BCrypt.checkpw(current_password, hash)){
|
||||
System.out.println("Password don't match");
|
||||
return false;
|
||||
}else{
|
||||
System.out.println("Update Password");
|
||||
userDao.updateUserPassword(dataEncryption.encryptData(user_email),hashPassword(new_password));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String hashPassword(String plainTextPassword){
|
||||
return BCrypt.hashpw(plainTextPassword,BCrypt.gensalt());
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import database.Wallet.Wallet;
|
|||
import database.Wallet.WalletDao;
|
||||
import database.user.User;
|
||||
import database.user.UserDao;
|
||||
import encryption.DataEncryption;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||
import javax.json.Json;
|
||||
|
@ -14,10 +15,9 @@ import javax.json.JsonObject;
|
|||
import javax.json.JsonReader;
|
||||
import java.io.StringReader;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class WalletImplementation {
|
||||
private DataEncryption dataEncryption = new DataEncryption();
|
||||
|
||||
public Wallet createWallet(Wallet wallet) throws Exception {
|
||||
//Map<String,String> response = new HashMap<>();
|
||||
|
@ -123,12 +123,30 @@ public class WalletImplementation {
|
|||
}
|
||||
|
||||
//delete
|
||||
public void deleteWallet(String walletHash, String userHash) throws Exception {
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
transactionWrapper.sendTransaction("deleteWallet",new String[]{walletHash});
|
||||
public void deleteWallet(String user_email, String user_hash, String user_password, String wallet_hash_source, String wallet_hash_dest) throws Exception {
|
||||
UserDao userDao = new UserDao();
|
||||
User userResponse = userDao.getUserWithEmail(dataEncryption.encryptData(user_email));
|
||||
|
||||
WalletDao walletDao = new WalletDao();
|
||||
walletDao.deleteWallet(walletHash,userHash);
|
||||
if(userResponse != null){
|
||||
String hash = userResponse.getPassword();
|
||||
//CHECK USER PASSWORD
|
||||
if(BCrypt.checkpw(user_password, hash)){
|
||||
//GET FUND OF WALLET_HASH_SOURCE
|
||||
Double w_source_balance = getWallet(wallet_hash_source).getBalance();
|
||||
|
||||
// MOVE FUND FROM WALLET SOURCE TO WALLET DEST
|
||||
if(w_source_balance!=0){
|
||||
TransactionImplementation transactionImplementation = new TransactionImplementation();
|
||||
transactionImplementation.sendTransaction(user_hash,user_password,wallet_hash_source,wallet_hash_dest,w_source_balance,"gonette");
|
||||
}
|
||||
|
||||
// DELETE WALLET SOURCE
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
transactionWrapper.sendTransaction("deleteWallet",new String[]{wallet_hash_source});
|
||||
WalletDao walletDao = new WalletDao();
|
||||
walletDao.deleteWallet(wallet_hash_source,user_hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//getAll
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package restService;
|
||||
|
||||
import database.user.User;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -10,6 +8,7 @@ import restImplementation.UserImplementation;
|
|||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/rest/user")
|
||||
|
@ -121,10 +120,22 @@ public class UserResource {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity updateUser(@RequestBody User user){
|
||||
return new ResponseEntity(null, HttpStatus.SERVICE_UNAVAILABLE);
|
||||
@RequestMapping(value = "/update/password", method = RequestMethod.POST)
|
||||
public ResponseEntity updateUser(@RequestBody Map<String,String> requestParam){
|
||||
String user_email = requestParam.get("user_email");
|
||||
String current_password = requestParam.get("current_password");
|
||||
String new_password = requestParam.get("new_password");
|
||||
System.out.println(user_email);
|
||||
System.out.println(current_password);
|
||||
System.out.println(new_password);
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
try{
|
||||
Boolean r = userImplementation.updatePassword(user_email,current_password,new_password);
|
||||
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\""+r.toString()+"\"}");
|
||||
}catch (Exception e){
|
||||
String r = "{\"response\":\"false\"}";
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -84,14 +84,17 @@ public class WalletResource {
|
|||
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||
public ResponseEntity deleteWallet(@RequestBody Map<String,String> requestParam){
|
||||
String userHash = requestParam.get("user_hash");
|
||||
String walletHash = requestParam.get("wallet_hash");
|
||||
String user_email = requestParam.get("user_email");
|
||||
String user_hash = requestParam.get("user_hash");
|
||||
String user_password = requestParam.get("user_password");
|
||||
String wallet_hash_source = requestParam.get("wallet_hash_source");
|
||||
String wallet_hash_dest = requestParam.get("wallet_hash_dest");
|
||||
WalletImplementation walletImplementation = new WalletImplementation();
|
||||
try{
|
||||
walletImplementation.deleteWallet(walletHash,userHash);
|
||||
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\"ok\"}");
|
||||
walletImplementation.deleteWallet(user_email,user_hash,user_password,wallet_hash_source,wallet_hash_dest);
|
||||
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\"true\"}");
|
||||
}catch (Exception e){
|
||||
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
||||
String r = "{\"response\":\"false\"}";
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue