Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fourth frontend features and some backend fixes #74

Merged
merged 8 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions backend/config/crypto/ca.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,18 @@ authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

[req_ext]
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
DNS.2 = authik-0.dating.se.ifmo.ru
DNS.3 = authik-1.dating.se.ifmo.ru
DNS.4 = authik-2.dating.se.ifmo.ru
DNS.5 = matchmaker-0.dating.se.ifmo.ru
DNS.6 = matchmaker-1.dating.se.ifmo.ru
DNS.7 = matchmaker-2.dating.se.ifmo.ru
DNS.8 = people-0.dating.se.ifmo.ru
DNS.9 = people-1.dating.se.ifmo.ru
DNS.10 = people-2.dating.se.ifmo.ru
DNS.11 = server.dc1.consul
5 changes: 5 additions & 0 deletions backend/config/crypto/keys.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ENV="$2"

ALIAS="itmo-dating"
ALIAS_BACKEND="$ALIAS-backend"
ALIAS_EXTERNAL="$ALIAS-external"

VALIDITY=1
PASSWORD="$ITMO_DATING_KEY_STORE_PASSWORD"
Expand Down Expand Up @@ -71,6 +72,9 @@ function generate() {
-deststoretype JKS \
-destkeystore "$ALIAS_BACKEND.jks" \
-deststorepass "$PASSWORD"

echo "Copying PKCS12 as external certificate"
cp "$ALIAS_BACKEND.p12" "$ALIAS_EXTERNAL.p12"
}

function copy() {
Expand All @@ -92,6 +96,7 @@ function distribute() {

echo "Copying package to the gateway..."
copy "$GATEWAY_INSTALL_PATH" "$ALIAS_BACKEND.p12"
copy "$GATEWAY_INSTALL_PATH" "$ALIAS_EXTERNAL.p12"

echo "Copying keys to the consul..."
copy "$CONSUL_INSTALL_PATH" "$ALIAS_BACKEND.key"
Expand Down
2 changes: 2 additions & 0 deletions backend/consul/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ RUN chmod -R 755 /consul/config && \
chmod 644 /consul/config/itmo-dating-backend.crt && \
chmod 644 /consul/config/itmo-dating-backend-ca.crt && \
chmod 644 /consul/config/consul.hcl

CMD ["sh", "./consul/run.sh"]
4 changes: 4 additions & 0 deletions backend/consul/config/consul.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ acl {
enable_token_persistence = true
}

limits {
http_max_conns_per_client = 400
}

data_dir = "/opt/consul/data"

ui = true
Expand Down
3 changes: 1 addition & 2 deletions backend/consul/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh

consul agent -config-file=/consul/config/consul.hcl -bootstrap-expect=1 \
| grep -v "This request used the token query parameter which is deprecated and will be removed"
consul agent -config-file=/consul/config/consul.hcl -bootstrap-expect=1 | grep -v "This request used the token query parameter which is deprecated and will be removed"
2 changes: 1 addition & 1 deletion backend/gateway/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies {

implementation(libs.org.springframework.boot.spring.boot)
implementation(libs.org.springframework.cloud.spring.cloud.starter.gateway)

implementation(libs.org.springframework.spring.web)
implementation(libs.org.springdoc.springdoc.openapi.starter.webflux.ui)

testImplementation(libs.org.springframework.boot.spring.boot.starter.test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import javax.net.ssl.KeyManagerFactory
import javax.net.ssl.TrustManagerFactory

@Configuration
class SSLContextConfig(
@Value("\${server.ssl.key-store-type}")
class ClientSSLContextConfig(
@Value("\${client.ssl.key-store-type}")
private val keyStoreType: String,

@Value("\${server.ssl.key-store}")
@Value("\${client.ssl.key-store}")
private val keyStore: Resource,

@Value("\${server.ssl.key-store-password}")
@Value("\${client.ssl.key-store-password}")
private val keyStorePassword: String,

@Value("\${server.ssl.protocol}")
@Value("\${client.ssl.protocol}")
private val sslProtocol: String,
) {
@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.ifmo.se.dating.spring.api
package ru.ifmo.se.dating.gateway

import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus
Expand All @@ -13,11 +13,15 @@ class CorsFilter : WebFilter {
// FIXME
override fun filter(ctx: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
ctx.response.headers.add("Access-Control-Allow-Origin", "*")
ctx.response.headers.add("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS")
ctx.response.headers.add(
"Access-Control-Allow-Methods",
"GET, PUT, POST, PATCH, DELETE, OPTIONS"
)
ctx.response.headers.add(
"Access-Control-Allow-Headers",
"DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With," +
"If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range"
// "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With," +
// "If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Authorization"
"*"
)
if (ctx.request.method == HttpMethod.OPTIONS) {
ctx.response.headers.add("Access-Control-Max-Age", "1728000")
Expand Down
8 changes: 7 additions & 1 deletion backend/gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@ server:
ssl:
enabled: true
key-store-type: PKCS12
key-store: classpath:keystore/itmo-dating-backend.p12
key-store: classpath:keystore/itmo-dating-external.p12
key-store-password: ${KEY_STORE_PASSWORD}
protocol: TLSv1.3
enabled-protocols: TLSv1.3
client:
ssl:
key-store-type: PKCS12
key-store: classpath:keystore/itmo-dating-backend.p12
key-store-password: ${KEY_STORE_PASSWORD}
protocol: TLSv1.3
Comment on lines +102 to +107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хммм, а может быть это даже можно в какой-то общий для всех модуль унести, потому что я для работы WebClient сам велосипедно SSLContext собираю. Может быть, эта штука сделает так, чтобы оно работало само.

springdoc:
swagger-ui:
path: /swagger-ui.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SecurityInitializer :
override fun initialize(ctx: ConfigurableApplicationContext) {
TestPropertyValues.of(
"server.ssl.key-store-password=$keyStorePassword",
"client.ssl.key-store-password=$keyStorePassword",
).applyTo(ctx.environment)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class MatchmakerSecuredPaths : SpringSecuredPaths {
Path("/api/**"),
Not(Path("/api/people/{person_id}", HttpMethod.PUT)),
Not(Path("/api/monitoring/healthcheck", HttpMethod.GET)),
Not(Path("/api/suggestions", HttpMethod.OPTIONS)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут, наверное, нужно сделать какой-нибудь wildcard и все OPTIONS разрешить возмоооожно.

)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ spring:
instance-id: instance-${HOSTNAME}
heartbeat:
enabled: true
ttl: 30
catalog-services-watch-delay: 5000
management:
health:
consul:
Expand Down
1 change: 0 additions & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ services:
image: ghcr.io/secs-dev/itmo-dating-consul:latest
build:
context: ./backend/consul
command: sh ./consul/run.sh
hostname: server.dc1.consul
ports:
- "127.0.0.1:8500:8500/tcp"
Expand Down
9 changes: 9 additions & 0 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,14 @@ module.exports = {
plugins: ['@typescript-eslint', 'react'],
rules: {
'react/react-in-jsx-scope': 0,
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'warn', // or "error"
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
},
}
2 changes: 1 addition & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY package*.json ./

RUN npm install

# COPY .cert ./.cert
COPY .cert ./.cert

COPY dist ./dist

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/app/routes/ui/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Route } from 'atomic-router-react'
import { routes } from '../api'
import { Registration, Home, Main } from '@/pages'
import { Registration, Main } from '@/pages'
import { Welcome } from '@/pages/welcome/ui/Welcome.tsx'

export const Routes = () => (
<>
<Route route={routes.home} view={Home} />
<Route route={routes.home} view={Welcome} />
<Route route={routes.registration} view={Registration} />
<Route route={routes.main} view={Main} />
</>
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/entities/person-patch/model/PersonPatch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface PersonPatch {
status: string
firstName: string
lastName: string
interests: Topic[]
height: number
birthday: string
facultyId: number
locationId: number
status: string | null
firstName: string | null
lastName: string | null
interests: Topic[] | null
height: number | null
birthday: string | null
facultyId: number | null
locationId: number | null
}

export interface Topic {
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/entities/person/model/Person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ export interface Person {
faculty: string
location: Location
}

export interface PersonLegacy {
status: string
userId: number
firstName: string
zodiac: string
lastName: string
interests: Interest[]
height: number
birthday: Date
facultyId: number
locationId: number
}
4 changes: 4 additions & 0 deletions frontend/src/entities/registration-data/model/Coordinates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Coordinates {
latitude: number
longitude: number
}
7 changes: 7 additions & 0 deletions frontend/src/entities/registration-data/model/Location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Coordinates } from './Coordinates.ts'

export interface Location {
id: number
name: string
coordinates: Coordinates
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { Interest } from './interest.ts'
import { Picture } from './picture.ts'

export type RegistrationData = {
tgId: string
name: string
surname: string
height: number
faculty: string
birthday: Date
pictures: Picture[]
interests: Interest[]
tgId: string | null
name: string | null
surname: string | null
height: number | null
facultyId: number | null
birthday: Date | null
pictures: Picture[] | null
interests: Interest[] | null
locationId: number | null
}
4 changes: 4 additions & 0 deletions frontend/src/entities/registration-data/model/faculty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Faculty {
id: number
longName: string
}
28 changes: 28 additions & 0 deletions frontend/src/features/authentication/api/authFx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import { AuthState, initialAuthState } from '@/entities'
import { backendAuthikUrl } from '@/shared/api'

export const $authStore = createStore<AuthState>(initialAuthState)
export const $userIdStore = createStore<number | null>(null)

export const $userRegisteredStore = createStore<boolean>(false)

persist({ store: $authStore, key: 'authStore' })
persist({ store: $userIdStore, key: 'userIdStore' })
persist({ store: $userRegisteredStore, key: 'userRegisteredStore' })

export const authFx = createEffect<AuthRequest, AuthState, Error>({
handler: async (authReq) => {
Expand Down Expand Up @@ -49,3 +54,26 @@ $authStore.on(authFx.failData, (_, error) => ({
loading: false,
error: error.message,
}))

export const userIdFx = createEffect<number | null, number | null, Error>({
handler: async (x) => {
if (x == null) throw Error('x is null')
return x
},
})

export const userRegisteredFx = createEffect<boolean, boolean, Error>({
handler: async (x) => {
if (!x) throw Error('user not registered')
return x
},
})

$userIdStore.on(userIdFx.doneData, (_, result) => result)
$userIdStore.on(userIdFx.failData, (_, __) => {
return null
})
$userRegisteredStore.on(userRegisteredFx.doneData, (_, result) => result)
$userRegisteredStore.on(userRegisteredFx.failData, (_, __) => {
return false
})
23 changes: 23 additions & 0 deletions frontend/src/features/get-faculties/api/getFaculties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import axios from 'axios'
import React from 'react'
import { backendPeopleUrl } from '@/shared/api'
import { Faculty } from '@/entities/registration-data/model/faculty.ts'

export function getFaculties(
setFaculties: React.Dispatch<React.SetStateAction<Array<Faculty>>>,
) {
const url = `${backendPeopleUrl}/api/faculties`

axios
.get(url)
.then((response) => {
console.log(response.data)
//FIXME after integration with backend
setFaculties(response.data)
})
.catch((error) => {
console.error('Error getting faculties: ', error)
//TODO remove after integration with backend
setFaculties([{ id: 1, longName: 'piict' }])
Comment on lines +19 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это уже можно убрать?

})
}
32 changes: 32 additions & 0 deletions frontend/src/features/get-locations/api/getLocations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import axios from 'axios'
import React from 'react'
import { backendPeopleUrl } from '@/shared/api'
import { Location } from '@/entities/registration-data/model/Location.ts'

export function getLocations(
setLocations: React.Dispatch<React.SetStateAction<Array<Location>>>,
) {
const url = `${backendPeopleUrl}/api/locations`

axios
.get(url)
.then((response) => {
console.log(response.data)
//FIXME after integration with backend
setLocations(response.data)
})
.catch((error) => {
console.error('Error getting locations: ', error)
//TODO remove after integration with backend
setLocations([
{
id: 1,
name: 'ITMO University, Kronverkskiy Avenue',
coordinates: {
latitude: 59.957478,
longitude: 30.308014,
},
},
])
Comment on lines +19 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это уже можно убрать?

})
}
Loading
Loading