Update session

This commit is contained in:
GME 2019-04-08 21:17:35 +02:00
parent 16dd8584db
commit 2038c66f06
4 changed files with 922 additions and 14 deletions

View file

@ -0,0 +1,904 @@
{
"info": {
"_postman_id": "fe2ac183-8378-4e3d-82c9-0cd1057d2fb7",
"name": "MONNETHIC-API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "USER",
"item": [
{
"name": "CREATE",
"item": [
{
"name": "Register User",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\":\"Clara\",\n\t\"firstname\":\"Sophie\",\n\t\"email\":\"sophie.clara@gmail.com\",\n\t\"password\":\"sophieClara1234$\",\n\t\"association\":\"gonette\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/user/register",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"user",
"register"
]
},
"description": "Request to Register an User into Monnethic-Project (Blockchain and Database)"
},
"response": []
},
{
"name": "Register User To Delete",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\":\"Toto\",\n\t\"firstname\":\"tata\",\n\t\"email\":\"toto.tata@gmail.com\",\n\t\"password\":\"tototata1234$\",\n\t\"association\":\"gonette\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/user/register",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"user",
"register"
]
},
"description": "Request to Register an User into Monnethic-Project (Blockchain and Database)"
},
"response": []
},
{
"name": "Register User With Phone",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\":\"Meunier\",\n\t\"firstname\":\"Thomas\",\n\t\"email\":\"thomas.meunier@gmail.com\",\n\t\"password\":\"thomasMeunier4567$\",\n\t\"phone\":\"0102030405\",\n\t\"association\":\"gonette\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/user/register",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"user",
"register"
]
},
"description": "Request to Register an User into Monnethic-Project (Blockchain and Database)"
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "LOGIN",
"item": [
{
"name": "User-Login",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"email\":\"thomas.meunier@gmail.com\",\n\t\"password\":\"thomasPwd158$*\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/user/login",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"user",
"login"
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "GET",
"item": [
{
"name": "getUser",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"email\":\"toto.tata@gmail.com\",\n\t\"password\":\"tototata1234$\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/user/get",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"user",
"get"
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "DELETE",
"item": [
{
"name": "deleteUser",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"email\":\"toto.tata@gmail.com\",\n\t\"user_hash\":\"$2a$10$mE0RJq92SmedzuMlQvX29uXT9chqpKH/45cZ9GD7aphsMdJw9..sm\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/user/delete",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"user",
"delete"
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "APPROVE",
"item": [
{
"name": "approveUser",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"user_hash\":\"$2a$10$mE0RJq92SmedzuMlQvX29uXT9chqpKH/45cZ9GD7aphsMdJw9..sm\",\n\t\"email\":\"toto.tata@gmail.com\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/user/approve",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"user",
"approve"
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
}
],
"event": [
{
"listen": "prerequest",
"script": {
"id": "bddb7f7b-9a6f-4a71-8061-a3a1fe46fb12",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "add34646-7177-4d4f-ad9e-b3eb963d5bf8",
"type": "text/javascript",
"exec": [
""
]
}
}
]
},
{
"name": "WALLET",
"item": [
{
"name": "GET",
"item": [
{
"name": "getWallet",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/wallet/getWallet?walletHash=$2a$10$8PJyraUjMoL/h.cQjJyMZedBUlcTjPjNm4j1NuqzQBTnSe2XNuGM2",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"wallet",
"getWallet"
],
"query": [
{
"key": "walletHash",
"value": "$2a$10$8PJyraUjMoL/h.cQjJyMZedBUlcTjPjNm4j1NuqzQBTnSe2XNuGM2"
}
]
}
},
"response": []
},
{
"name": "getUserWallets",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/wallet/getUserWallets?userHash=$2a$10$GzyMhD3n05Z2lwCnoGi2dusjKrNAmHhtn5fw1xLpes5.cEV5T7lve",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"wallet",
"getUserWallets"
],
"query": [
{
"key": "userHash",
"value": "$2a$10$GzyMhD3n05Z2lwCnoGi2dusjKrNAmHhtn5fw1xLpes5.cEV5T7lve"
}
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "DELETE",
"item": [
{
"name": "deleteWallet",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"userHash\":\"\",\n\t\"walletHash\":\"$2a$10$GzyMhD3n05Z2lwCnoGi2dusjKrNAmHhtn5fw1xLpes5.cEV5T7lve\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/wallet/delete",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"wallet",
"delete"
],
"query": [
{
"key": "",
"value": "",
"disabled": true
}
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "CREATE",
"item": [
{
"name": "createWallet",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"type\":\"test\",\n\t\"user_hash\":\"$2a$10$GzyMhD3n05Z2lwCnoGi2dusjKrNAmHhtn5fw1xLpes5.cEV5T7lve\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/wallet/create",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"wallet",
"create"
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "SETBALANCE",
"item": [
{
"name": "setBalance",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"association_hash\":\"$2a$10$lPl7xCdsp.2g9fX7ytj9tONkV3PuQzG.9A9G8PfEKnIkT2KpahMme\",\n\t\"assocation_pwd\":\"asso_GonE8977&4$*-\",\n\t\"wallet_hash\":\"$2a$10$8PJyraUjMoL/h.cQjJyMZedBUlcTjPjNm4j1NuqzQBTnSe2XNuGM2\",\n\t\"amount\":1.0\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/wallet/setBalance",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"wallet",
"setBalance"
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "TRANSFER",
"item": [
{
"name": "transferWallet",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"user_hash\":\"$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0.\",\n\t\"wallet_hash\":\"$2a$10$8PJyraUjMoL/h.cQjJyMZedBUlcTjPjNm4j1NuqzQBTnSe2XNuGM2\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/wallet/transfer",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"wallet",
"transfer"
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
}
]
},
{
"name": "TRANSACTION",
"item": [
{
"name": "SEND",
"item": [
{
"name": "sendTransaction",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"source_user_hash\":\"$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0.\",\n\t\"source_user_pwd\":\"thomasPwd158$*\",\n\t\"transaction_from\":\"$2a$10$6Z4uNeOgAKhpWYGVYwPWhe6G91lIKHOCA2yYcpzS1pbJyosNNw3Gu\",\n\t\"transaction_to\":\"$2a$10$UKiTo/eqpnvlny3U5xpJ../C2WOgoxebAl3xiexAhinC8X7Jt2wY.\",\n\t\"transaction_amount\":1.0,\n\t\"transaction_unit\":\"gonette\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/transaction/send",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"transaction",
"send"
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "GET",
"item": [
{
"name": "SENT",
"item": [
{
"name": "getSent",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/transaction/get/sent?wallet_hash=$2a$10$6Z4uNeOgAKhpWYGVYwPWhe6G91lIKHOCA2yYcpzS1pbJyosNNw3Gu",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"transaction",
"get",
"sent"
],
"query": [
{
"key": "wallet_hash",
"value": "$2a$10$6Z4uNeOgAKhpWYGVYwPWhe6G91lIKHOCA2yYcpzS1pbJyosNNw3Gu"
}
]
}
},
"response": []
},
{
"name": "getAllSent",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/transaction/get/allSent?user_hash=$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0.",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"transaction",
"get",
"allSent"
],
"query": [
{
"key": "user_hash",
"value": "$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0."
}
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "RECEIVED",
"item": [
{
"name": "getAllReceived",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/transaction/get/allReceived?user_hash=$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0.",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"transaction",
"get",
"allReceived"
],
"query": [
{
"key": "user_hash",
"value": "$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0."
}
]
}
},
"response": []
},
{
"name": "getReceived",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/transaction/get/received?wallet_hash=$2a$10$6Z4uNeOgAKhpWYGVYwPWhe6G91lIKHOCA2yYcpzS1pbJyosNNw3Gu",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"transaction",
"get",
"received"
],
"query": [
{
"key": "wallet_hash",
"value": "$2a$10$6Z4uNeOgAKhpWYGVYwPWhe6G91lIKHOCA2yYcpzS1pbJyosNNw3Gu"
}
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "getLatest",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/transaction/get/latest?user_hash=$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0.",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"transaction",
"get",
"latest"
],
"query": [
{
"key": "user_hash",
"value": "$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0."
}
]
}
},
"response": []
},
{
"name": "getTransaction",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/transaction/get?wallet_hash=$2a$10$UKiTo/eqpnvlny3U5xpJ../C2WOgoxebAl3xiexAhinC8X7Jt2wY.&txID=ce65025ddddcb26f6b380d54cf9d9b090550cbacadfb63b062f9336a72eeb6bc",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"transaction",
"get"
],
"query": [
{
"key": "wallet_hash",
"value": "$2a$10$UKiTo/eqpnvlny3U5xpJ../C2WOgoxebAl3xiexAhinC8X7Jt2wY."
},
{
"key": "txID",
"value": "ce65025ddddcb26f6b380d54cf9d9b090550cbacadfb63b062f9336a72eeb6bc"
}
]
}
},
"response": []
},
{
"name": "getAll",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:10053/api/rest/transaction/getAll?user_hash=$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0.",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"transaction",
"getAll"
],
"query": [
{
"key": "user_hash",
"value": "$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0."
}
]
}
},
"response": []
}
],
"_postman_isSubFolder": true
}
]
},
{
"name": "SESSION",
"item": [
{
"name": "sessiontStart",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"user_hash\":\"$2a$10$J7B8sXULfiPfnlKRlTjqQuSrbumTyv.acB8NpxDrUQ3WmnfKdjx0.\",\n\t\"user_email\":\"thomas.meunier@gmail.com\"\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/session/start",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"session",
"start"
]
}
},
"response": []
},
{
"name": "sessionEnd",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"session_id\":1\n}"
},
"url": {
"raw": "http://localhost:10053/api/rest/session/end",
"protocol": "http",
"host": [
"localhost"
],
"port": "10053",
"path": [
"api",
"rest",
"session",
"end"
]
}
},
"response": []
}
]
}
]
}

View file

@ -7,10 +7,10 @@ import java.time.Instant;
public class SessionImplementation {
public int startSession(String userHash, String userEmail) throws Exception {
public int startSession(String user_hash, String user_email) throws Exception {
SessionDao sessionDao = new SessionDao();
UserImplementation userImplementation = new UserImplementation();
int userId = userImplementation.getUserId(userHash,userEmail);
int userId = userImplementation.getUserId(user_hash,user_email);
Session session = new Session();
session.setUser_id(userId);
@ -20,8 +20,8 @@ public class SessionImplementation {
return sessionDao.setStartSession(session);
}
public void endSession(int sessionId) throws Exception {
public void endSession(int session_id) throws Exception {
SessionDao sessionDao = new SessionDao();
sessionDao.setEndSession(sessionId);
sessionDao.setEndSession(session_id);
}
}

View file

@ -6,7 +6,6 @@ import database.user.UserDao;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.springframework.security.crypto.bcrypt.BCrypt;
import restService.UserResource;
import java.time.Instant;
import java.util.HashMap;
@ -85,9 +84,9 @@ public class UserImplementation {
}
}
public int getUserId(String userHash, String userEmail) throws Exception{
public int getUserId(String user_hash, String user_email) throws Exception{
UserDao userDao = new UserDao();
return userDao.getUserIdWithHashAndEmail(userHash,userEmail);
return userDao.getUserIdWithHashAndEmail(user_hash,user_email);
}

View file

@ -5,29 +5,34 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import restImplementation.SessionImplementation;
import java.util.Map;
@RestController
@RequestMapping(value = "/api/rest/session")
public class SessionResource {
@RequestMapping(value = "/start", method = RequestMethod.GET, params = {"userHash","userEmail"}, produces = "application/json")
@RequestMapping(value = "/start", method = RequestMethod.POST, produces = "application/json")
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity startSession(@RequestParam(value = "userHash") String userHash, @RequestParam(value = "userEmail") String userEmail){
public ResponseEntity startSession(@RequestBody Map<String,String> requestParam){
SessionImplementation sessionImplementation = new SessionImplementation();
try {
int session_id = sessionImplementation.startSession(userHash,userEmail);
return ResponseEntity.status(HttpStatus.OK).body("{\"sessionId\":"+session_id+"}");
String user_hash = requestParam.get("user_hash");
String user_email = requestParam.get("user_email");
int session_id = sessionImplementation.startSession(user_hash,user_email);
return ResponseEntity.status(HttpStatus.OK).body("{\"session_id\":"+session_id+"}");
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
}
}
@RequestMapping(value = "/end", method = RequestMethod.GET, params = {"userId"}, produces = "application/json")
@RequestMapping(value = "/end", method = RequestMethod.POST, produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity endSession(@RequestParam(value = "userId") int userId){
public ResponseEntity endSession(@RequestBody Map<String,Integer> requestParam){
SessionImplementation sessionImplementation = new SessionImplementation();
try {
sessionImplementation.endSession(userId);
int session_id = requestParam.get("session_id");
sessionImplementation.endSession(session_id);
return ResponseEntity.status(HttpStatus.OK).body("");
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());