Add password encoding utility and update forms to use encoded passwords for secure data transmission. Enhance axios request interceptor to handle FormData content type correctly.
This commit is contained in:
@ -39,6 +39,16 @@ axios.interceptors.request.use(
|
|||||||
config.headers['Authorization'] = `Bearer ${token}`
|
config.headers['Authorization'] = `Bearer ${token}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Varsayılan application/json, FormData ile giderse sunucu [FromForm] alanları bağlayamaz.
|
||||||
|
if (config.data instanceof FormData) {
|
||||||
|
const h = config.headers as any
|
||||||
|
if (typeof h?.delete === 'function') {
|
||||||
|
h.delete('Content-Type')
|
||||||
|
}
|
||||||
|
delete h?.['Content-Type']
|
||||||
|
delete h?.['content-type']
|
||||||
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
function (error) {
|
function (error) {
|
||||||
|
|||||||
@ -58,11 +58,12 @@
|
|||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
|
|
||||||
import GuestLayout from '@/layouts/GuestLayout.vue'
|
import GuestLayout from '@/layouts/GuestLayout.vue'
|
||||||
|
import { withEncodedPasswords } from '@/utils/passwordCrypto'
|
||||||
|
|
||||||
const Login = async () => {
|
const Login = async () => {
|
||||||
if (authValidationStore.FormCheck()) {
|
if (authValidationStore.FormCheck()) {
|
||||||
let login = await dataStore.dataPost('Auth/login', {
|
let login = await dataStore.dataPost('Auth/login', {
|
||||||
data: authStore.loginData
|
data: withEncodedPasswords(authStore.loginData, ['password'])
|
||||||
})
|
})
|
||||||
Object.assign(authStore.loginData, authStore.safeLoginData)
|
Object.assign(authStore.loginData, authStore.safeLoginData)
|
||||||
if (login !== 'errorfalse') {
|
if (login !== 'errorfalse') {
|
||||||
|
|||||||
@ -363,6 +363,8 @@
|
|||||||
const uyeBilgileriStore = useUyeBilgileriStore()
|
const uyeBilgileriStore = useUyeBilgileriStore()
|
||||||
uyeBilgileriStore.ResetStore()
|
uyeBilgileriStore.ResetStore()
|
||||||
|
|
||||||
|
import { withEncodedPasswords } from '@/utils/passwordCrypto'
|
||||||
|
|
||||||
const kvkkCheck = ref([
|
const kvkkCheck = ref([
|
||||||
{
|
{
|
||||||
label: '',
|
label: '',
|
||||||
@ -413,7 +415,7 @@
|
|||||||
const handRegister = async () => {
|
const handRegister = async () => {
|
||||||
if (uyeBilgileriStore.FormCheck()) {
|
if (uyeBilgileriStore.FormCheck()) {
|
||||||
const register: any = await dataStore.dataPost('Auth/register', {
|
const register: any = await dataStore.dataPost('Auth/register', {
|
||||||
data: uyeBilgileriStore.formData
|
data: withEncodedPasswords(uyeBilgileriStore.formData, ['password', 'confirmPassword'])
|
||||||
})
|
})
|
||||||
|
|
||||||
if (register !== 'errorfalse') {
|
if (register !== 'errorfalse') {
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
import { ref, reactive } from 'vue'
|
import { ref, reactive } from 'vue'
|
||||||
import { useDataStore } from '@/stores/dataStore'
|
import { useDataStore } from '@/stores/dataStore'
|
||||||
const dataStore = useDataStore()
|
const dataStore = useDataStore()
|
||||||
|
import { withEncodedPasswords } from '@/utils/passwordCrypto'
|
||||||
import { useValidationStore } from '@/stores/validationStore'
|
import { useValidationStore } from '@/stores/validationStore'
|
||||||
const validationStore = useValidationStore()
|
const validationStore = useValidationStore()
|
||||||
import { useUsersStore } from '@/stores/usersStore'
|
import { useUsersStore } from '@/stores/usersStore'
|
||||||
@ -103,7 +104,7 @@
|
|||||||
if (FormCheck()) {
|
if (FormCheck()) {
|
||||||
let res: any
|
let res: any
|
||||||
res = await dataStore.dataPost('Auth/updatepassword/', {
|
res = await dataStore.dataPost('Auth/updatepassword/', {
|
||||||
data: formData
|
data: withEncodedPasswords(formData, ['currentPassword', 'newPassword', 'confirmNewPassword'])
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res !== 'errorfalse') {
|
if (res !== 'errorfalse') {
|
||||||
|
|||||||
@ -407,6 +407,7 @@
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
import { useDataStore } from '@/stores/dataStore'
|
import { useDataStore } from '@/stores/dataStore'
|
||||||
const dataStore = useDataStore()
|
const dataStore = useDataStore()
|
||||||
|
import { withEncodedPasswords } from '@/utils/passwordCrypto'
|
||||||
import { useUsersStore } from '@/stores/usersStore'
|
import { useUsersStore } from '@/stores/usersStore'
|
||||||
const usersStore = useUsersStore()
|
const usersStore = useUsersStore()
|
||||||
import { useGlobalStore } from '@/stores/globalStore'
|
import { useGlobalStore } from '@/stores/globalStore'
|
||||||
@ -479,7 +480,7 @@
|
|||||||
uyeBilgileriStore.formData.parentUserId = usersStore.userId
|
uyeBilgileriStore.formData.parentUserId = usersStore.userId
|
||||||
|
|
||||||
register = await dataStore.dataPost('Auth/register', {
|
register = await dataStore.dataPost('Auth/register', {
|
||||||
data: uyeBilgileriStore.formData
|
data: withEncodedPasswords(uyeBilgileriStore.formData, ['password', 'confirmPassword'])
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
register = await dataStore.dataPut(
|
register = await dataStore.dataPut(
|
||||||
|
|||||||
41
src/utils/passwordCrypto.ts
Normal file
41
src/utils/passwordCrypto.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Parola transport kodlamasi.
|
||||||
|
// Parolalarin istek govdesinde DUZ METIN gorunmesini engellemek icin Base64 ile kodlanir.
|
||||||
|
// Backend "b64:" on ekini gorunce cozer. (Not: Bu HTTPS/TLS'in yerini tutmaz, ek bir gizleme katmanidir.)
|
||||||
|
|
||||||
|
const PREFIX = 'b64:'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verilen parolayi UTF-8 guvenli sekilde Base64'e kodlar ve "b64:" on eki ekler.
|
||||||
|
* Bos/null/undefined degerler oldugu gibi (bos string) donulur.
|
||||||
|
*/
|
||||||
|
export function encodePassword(value: string | null | undefined): string {
|
||||||
|
if (value === null || value === undefined || value === '') return ''
|
||||||
|
|
||||||
|
const bytes = new TextEncoder().encode(String(value))
|
||||||
|
let binary = ''
|
||||||
|
bytes.forEach((b) => {
|
||||||
|
binary += String.fromCharCode(b)
|
||||||
|
})
|
||||||
|
|
||||||
|
return PREFIX + btoa(binary)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verilen nesnenin sig kopyasini olusturur ve belirtilen alanlari encode eder.
|
||||||
|
* Reactive store nesnelerini bozmamak icin daima yeni bir nesne doner.
|
||||||
|
*/
|
||||||
|
export function withEncodedPasswords<T extends Record<string, any>>(
|
||||||
|
data: T,
|
||||||
|
fields: string[]
|
||||||
|
): T {
|
||||||
|
const clone: Record<string, any> = { ...data }
|
||||||
|
|
||||||
|
fields.forEach((field) => {
|
||||||
|
const current = clone[field]
|
||||||
|
if (current !== null && current !== undefined && current !== '') {
|
||||||
|
clone[field] = encodePassword(current)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return clone as T
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user