Skip to content

Commit

Permalink
Fixed the SSL issues
Browse files Browse the repository at this point in the history
  • Loading branch information
N7ghtm4r3 committed Dec 7, 2023
1 parent c15b9f5 commit 163b1b1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pandoro

**v1.0.0**
**v1.0.1**

This project, based on Java and the
Spring Boot framework, is an open source management software useful in managing your personal projects and group
Expand All @@ -19,15 +19,15 @@ Add the JitPack repository to your build file

```gradle
dependencies {
implementation 'com.tecknobit.pandoro:Pandoro:1.0.0'
implementation 'com.tecknobit.pandoro:Pandoro:1.0.1'
}
```
#### Gradle (Kotlin)
```gradle
dependencies {
implementation("com.tecknobit.pandoro:Pandoro:1.0.0")
implementation("com.tecknobit.pandoro:Pandoro:1.0.1")
}
```
Expand All @@ -52,7 +52,7 @@ Add the JitPack repository to your build file
<dependency>
<groupId>com.github.N7ghtm4r3</groupId>
<artifactId>Pandoro</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>
```

Expand All @@ -69,9 +69,9 @@ steps:
- Mobile
- <a href="https://github.com/N7ghtm4r3/Pandoro-Android#readme">Android</a>
- iOS -> planned
- <a href="https://github.com/N7ghtm4r3/Pandoro-Desktop/releases/tag/1.0.0">Pandoro desktop version</a>
- <a href="https://github.com/N7ghtm4r3/Pandoro-Desktop/releases/tag/1.0.1">Pandoro desktop version</a>
- <a href="https://github.com/Rhythmss/pandoro-webapp">Pandoro webapp version</a>
- <a href="https://github.com/N7ghtm4r3/Pandoro/releases/tag/1.0.0">Backend service "out-of-the-box"</a>
- <a href="https://github.com/N7ghtm4r3/Pandoro/releases/tag/1.0.1">Backend service "out-of-the-box"</a>

## Usages

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import com.tecknobit.apimanager.apis.ServerProtector.SERVER_SECRET_KEY
import com.tecknobit.apimanager.apis.sockets.SocketManager
import com.tecknobit.apimanager.formatters.JsonHelper
import com.tecknobit.pandoro.controllers.*
import com.tecknobit.pandoro.controllers.PandoroController.BASE_ENDPOINT
import com.tecknobit.pandoro.controllers.PandoroController.IDENTIFIER_KEY
import com.tecknobit.pandoro.records.users.GroupMember.Role
import com.tecknobit.pandoro.services.GroupsHelper
import com.tecknobit.pandoro.services.ProjectsHelper
import com.tecknobit.pandoro.services.UsersHelper
import com.tecknobit.pandoro.services.UsersHelper.PROFILE_PIC_KEY
import com.tecknobit.pandoro.services.UsersHelper.TOKEN_KEY
import org.json.JSONObject
import org.springframework.core.io.FileSystemResource
import org.springframework.http.HttpEntity
Expand All @@ -26,7 +30,7 @@ import org.springframework.web.client.RestTemplate
import java.io.File

/**
* The **BaseRequester** class is useful to communicate with the Pandoro's backend
* The **Requester** class is useful to communicate with the Pandoro's backend
*
* @param host: the host where is running the Pandoro's backend
* @param userId: the user identifier
Expand All @@ -35,12 +39,22 @@ import java.io.File
* @author N7ghtm4r3 - Tecknobit
*/
@Structure
abstract class BaseRequester(
open class Requester(
private val host: String,
open var userId: String? = null,
open var userToken: String? = null
) {

/**
* **apiRequest** -> the instance to communicate and make the requests to the backend
*/
protected val apiRequest: APIRequest = APIRequest()

/**
* **headers** -> the headers of the requests
*/
protected val headers: APIRequest.Headers = APIRequest.Headers()

/**
* **errorResponse** -> the default error response to send when the request throws an [Exception]
*/
Expand All @@ -54,12 +68,21 @@ abstract class BaseRequester(
*/
protected var lastResponse: JsonHelper? = null

init {
setAuthHeaders()
}

/**
* Function to set the headers for the authentication of the user
*
* No-any params required
*/
protected abstract fun setAuthHeaders()
protected fun setAuthHeaders() {
if (userId != null && userToken != null) {
headers.addHeader(IDENTIFIER_KEY, userId)
headers.addHeader(TOKEN_KEY, userToken)
}
}

/**
* Function to execute the request to sign up in the Pandoro's system
Expand Down Expand Up @@ -120,8 +143,8 @@ abstract class BaseRequester(
*/
private fun setAuthCredentials(response: JSONObject) {
val hResponse = JsonHelper(response)
userId = hResponse.getString(PandoroController.IDENTIFIER_KEY)
userToken = hResponse.getString(UsersHelper.TOKEN_KEY)
userId = hResponse.getString(IDENTIFIER_KEY)
userToken = hResponse.getString(TOKEN_KEY)
setAuthHeaders()
}

Expand All @@ -137,13 +160,13 @@ abstract class BaseRequester(
open fun execChangeProfilePic(profilePic: File): JSONObject {
val headers = HttpHeaders()
headers.contentType = MediaType.MULTIPART_FORM_DATA
headers.add(UsersHelper.TOKEN_KEY, userToken)
headers.add(TOKEN_KEY, userToken)
val body: MultiValueMap<String, Any> = LinkedMultiValueMap()
body.add(UsersHelper.PROFILE_PIC_KEY, FileSystemResource(profilePic))
body.add(PROFILE_PIC_KEY, FileSystemResource(profilePic))
val requestEntity: HttpEntity<Any?> = HttpEntity<Any?>(body, headers)
val restTemplate = RestTemplate()
val response = restTemplate.postForEntity(
host + PandoroController.BASE_ENDPOINT + UsersController.USERS_ENDPOINT + "/$userId/" +
host + BASE_ENDPOINT + UsersController.USERS_ENDPOINT + "/$userId/" +
UsersController.CHANGE_PROFILE_PIC_ENDPOINT, requestEntity, String::class.java
).body
lastResponse = JsonHelper(response)
Expand Down Expand Up @@ -705,7 +728,7 @@ abstract class BaseRequester(
role: Role
): JSONObject {
val payload = PandoroPayload()
payload.addParam(PandoroController.IDENTIFIER_KEY, memberId)
payload.addParam(IDENTIFIER_KEY, memberId)
payload.addParam(GroupsHelper.MEMBER_ROLE_KEY, role)
return execPatch(
createGroupsEndpoint(GroupsController.CHANGE_MEMBER_ROLE_ENDPOINT, groupId),
Expand Down Expand Up @@ -1154,13 +1177,34 @@ abstract class BaseRequester(
* @param payload: the payload of the request, default null
* @param jsonPayload: whether the payload must be formatted as JSON, default true
*/
protected abstract fun execRequest(
@Synchronized
open fun execRequest(
contentType: String,
endpoint: String,
requestMethod: APIRequest.RequestMethod,
payload: PandoroPayload? = null,
jsonPayload: Boolean = true
): String
): String {
headers.addHeader("Content-Type", contentType)
if (host.startsWith("https"))
apiRequest.validateSelfSignedCertificate()
return try {
val requestUrl = host + BASE_ENDPOINT + endpoint
if (payload != null) {
if (jsonPayload)
apiRequest.sendJSONPayloadedAPIRequest(requestUrl, requestMethod, headers, payload)
else
apiRequest.sendPayloadedAPIRequest(requestUrl, requestMethod, headers, payload)
} else
apiRequest.sendAPIRequest(requestUrl, requestMethod, headers)
val response = apiRequest.response
lastResponse = JsonHelper(response)
response
} catch (e: Exception) {
lastResponse = JsonHelper(errorResponse)
errorResponse
}
}

/**
* The **PandoroPayload** class is useful to create the payload for the requests to the Pandoro's backend
Expand Down

0 comments on commit 163b1b1

Please sign in to comment.