-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #412 from bounswe/frontend/feature/364-Implement_P…
…rofile_Page
- Loading branch information
Showing
174 changed files
with
23,406 additions
and
1,137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
name: Build Android APK | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: mobile | ||
steps: | ||
- name: 🏗 Setup repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: 🏗 Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: yarn | ||
|
||
- name: 🏗 Setup EAS | ||
uses: expo/expo-github-action@v8 | ||
with: | ||
eas-version: latest | ||
token: ${{ secrets.EXPO_TOKEN }} | ||
|
||
- name: 📦 Install dependencies | ||
run: yarn install | ||
|
||
- name: 🚀 Build app | ||
run: eas build --non-interactive -p android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nodeLinker: node-modules | ||
nodeLinker: node-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/com/group1/programminglanguagesforum/Config/CorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.group1.programminglanguagesforum.Config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
import java.util.Arrays; | ||
|
||
@Component | ||
public class CorsConfig { | ||
@Bean | ||
public CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration corsConfiguration = new CorsConfiguration(); | ||
corsConfiguration.setAllowCredentials(true); | ||
corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:*", // Allows any port from localhost | ||
"https://*.ondigitalocean.app")); // Allows the specific DigitalOcean URL; | ||
corsConfiguration.addAllowedHeader("*"); | ||
corsConfiguration.addAllowedMethod("*"); | ||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", corsConfiguration); | ||
return source; | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...nd/src/main/java/com/group1/programminglanguagesforum/Config/JwtAuthenticationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.group1.programminglanguagesforum.Config; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.group1.programminglanguagesforum.DTOs.Responses.ErrorResponse; | ||
import com.group1.programminglanguagesforum.DTOs.Responses.GenericApiResponse; | ||
import com.group1.programminglanguagesforum.Repositories.UserRepository; | ||
import com.group1.programminglanguagesforum.Services.CustomUserDetailsService; | ||
import com.group1.programminglanguagesforum.Services.JwtService; | ||
import io.jsonwebtoken.ExpiredJwtException; | ||
import io.micrometer.common.util.StringUtils; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class JwtAuthenticationFilter extends OncePerRequestFilter { | ||
private final UserRepository userRepository; | ||
private final JwtService jwtAuthenticationService; | ||
private final CustomUserDetailsService customUserDetailsService; | ||
private final ObjectMapper objectMapper; | ||
|
||
@Override | ||
protected void doFilterInternal( | ||
@NonNull HttpServletRequest request, | ||
@NonNull HttpServletResponse response, | ||
@NonNull FilterChain filterChain | ||
) throws ServletException, IOException { | ||
try { | ||
final String authorizationHeader = request.getHeader("Authorization"); | ||
final String jwt; | ||
final String username; | ||
if (StringUtils.isEmpty(authorizationHeader) || !org.springframework.util.StringUtils.startsWithIgnoreCase(authorizationHeader, "Bearer ")) { | ||
logger.info("No JWT token found in request headers"); | ||
System.out.println("Request: " + request.getMethod() + " " + request.getRequestURI()); | ||
filterChain.doFilter(request, response); | ||
System.out.println("Response Status: " + response.getStatus()); | ||
return; | ||
} | ||
jwt = authorizationHeader.substring(7); | ||
username = jwtAuthenticationService.extractUsername(jwt); | ||
if (StringUtils.isNotEmpty(username)) { | ||
UserDetails userDetails = customUserDetailsService.loadUserByUsername(username); | ||
|
||
// Authenticate the user if the token is valid | ||
if (jwtAuthenticationService.isTokenValid(jwt, userDetails)) { | ||
SecurityContext context = | ||
SecurityContextHolder.createEmptyContext(); | ||
UsernamePasswordAuthenticationToken authToken = | ||
new UsernamePasswordAuthenticationToken( | ||
userDetails, | ||
null, | ||
userDetails.getAuthorities() | ||
); | ||
authToken.setDetails( | ||
new WebAuthenticationDetailsSource().buildDetails(request) | ||
); | ||
context.setAuthentication(authToken); | ||
SecurityContextHolder.setContext(context); | ||
} | ||
} | ||
|
||
|
||
} catch (ExpiredJwtException e) { | ||
GenericApiResponse<Void> genericApiResponse = GenericApiResponse.<Void>builder() | ||
.status(HttpServletResponse.SC_UNAUTHORIZED) | ||
.message("Token has expired") | ||
.error( | ||
ErrorResponse.builder() | ||
.errorMessage("Token has expired") | ||
.stackTrace(Arrays.toString(e.getStackTrace())) | ||
.build() | ||
) | ||
.build(); | ||
|
||
response.setContentType("application/json"); | ||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ||
response.getWriter().write(objectMapper.writeValueAsString(genericApiResponse)); | ||
return; | ||
} | ||
catch (Exception e){ | ||
GenericApiResponse<Void> genericApiResponse = GenericApiResponse.<Void>builder() | ||
.status(HttpServletResponse.SC_UNAUTHORIZED) | ||
.message("Invalid token") | ||
.error( | ||
ErrorResponse.builder() | ||
.errorMessage("Invalid token") | ||
.stackTrace(Arrays.toString(e.getStackTrace())) | ||
.build() | ||
) | ||
.build(); | ||
|
||
response.setContentType("application/json"); | ||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ||
response.getWriter().write(objectMapper.writeValueAsString(genericApiResponse)); | ||
return; | ||
} | ||
filterChain.doFilter(request, response); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
backend/src/main/java/com/group1/programminglanguagesforum/Config/ModelMapperConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.group1.programminglanguagesforum.Config; | ||
|
||
import com.group1.programminglanguagesforum.DTOs.Responses.SelfProfileResponseDto; | ||
import com.group1.programminglanguagesforum.DTOs.Responses.UserProfileResponseDto; | ||
import com.group1.programminglanguagesforum.Entities.User; | ||
import org.modelmapper.ModelMapper; | ||
import org.modelmapper.PropertyMap; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class ModelMapperConfig { | ||
@Bean | ||
public ModelMapper modelMapper() { | ||
ModelMapper modelMapper = new ModelMapper(); | ||
|
||
// Define a PropertyMap to skip certain fields | ||
modelMapper.addMappings(new PropertyMap<SelfProfileResponseDto, User>() { | ||
@Override | ||
protected void configure() { | ||
skip(destination.getPassword()); | ||
skip(destination.getFollowers()); | ||
skip(destination.getFollowing()); | ||
} | ||
}); | ||
modelMapper.addMappings(new PropertyMap <UserProfileResponseDto,User>() { | ||
@Override | ||
protected void configure() { | ||
skip(destination.getPassword()); | ||
skip(destination.getFollowers()); | ||
skip(destination.getFollowing()); | ||
|
||
} | ||
}); | ||
|
||
return modelMapper; | ||
} | ||
} |
Oops, something went wrong.