diff --git a/src/init/axios-init.ts b/src/init/axios-init.ts index ff4b907..2b1ae16 100644 --- a/src/init/axios-init.ts +++ b/src/init/axios-init.ts @@ -48,7 +48,7 @@ axios.interceptors.response.use( const token = sessionStorage.getItem(usersStore.userStorageKeys.TOKEN) if (token !== undefined) { usersStore.ResetUserData() - router.push('/login') + router.push('/giris') } } return Promise.reject(error) diff --git a/src/layouts/admin-inc/ProfileMenu.vue b/src/layouts/admin-inc/ProfileMenu.vue index a488bb0..58d08c4 100644 --- a/src/layouts/admin-inc/ProfileMenu.vue +++ b/src/layouts/admin-inc/ProfileMenu.vue @@ -71,7 +71,7 @@ let dt = await dataStore.dataPost('Auth/logout') } usersStore.ResetUserData() - router.push('/login') + router.push('/giris') } const closeProfileMenu = (e: Event) => { diff --git a/src/module/auth/routes/forgot-password.ts b/src/module/auth/routes/forgot-password.ts index 3d455dd..c47504c 100644 --- a/src/module/auth/routes/forgot-password.ts +++ b/src/module/auth/routes/forgot-password.ts @@ -1,7 +1,7 @@ import ForgotPassword from '@/module/auth/views/ForgotPassword.vue' export default { - path: '/forgot-password', + path: '/sifremi-unuttum', name: 'ForgotPassword', component: ForgotPassword, meta: { diff --git a/src/module/auth/routes/index.ts b/src/module/auth/routes/index.ts index cd19939..6580f0c 100644 --- a/src/module/auth/routes/index.ts +++ b/src/module/auth/routes/index.ts @@ -1,11 +1,6 @@ -import Login from "@/module/auth/routes/login"; -import Register from "@/module/auth/routes/register"; -import ForgotPassword from "@/module/auth/routes/forgot-password"; - -export default [ - Login, - Register, - ForgotPassword -] - +import Login from '@/module/auth/routes/login' +import Register from '@/module/auth/routes/register' +import ForgotPassword from '@/module/auth/routes/forgot-password' +import ResetPassword from '@/module/auth/routes/reset-password' +export default [Login, Register, ForgotPassword, ResetPassword] diff --git a/src/module/auth/routes/login.ts b/src/module/auth/routes/login.ts index 345cb38..02680be 100644 --- a/src/module/auth/routes/login.ts +++ b/src/module/auth/routes/login.ts @@ -1,7 +1,7 @@ import Login from '@/module/auth/views/Login.vue' export default { - path: '/login', + path: '/giris', name: 'Login', component: Login, meta: { diff --git a/src/module/auth/routes/register.ts b/src/module/auth/routes/register.ts index 4521657..0fafe7f 100644 --- a/src/module/auth/routes/register.ts +++ b/src/module/auth/routes/register.ts @@ -1,7 +1,7 @@ import Register from '@/module/auth/views/Register.vue' export default { - path: '/register', + path: '/kayit-ol', name: 'Register', component: Register, meta: { diff --git a/src/module/auth/routes/reset-password.ts b/src/module/auth/routes/reset-password.ts new file mode 100644 index 0000000..27c57e4 --- /dev/null +++ b/src/module/auth/routes/reset-password.ts @@ -0,0 +1,10 @@ +import ResetPassword from '@/module/auth/views/ResetPassword.vue' + +export default { + path: '/sifreyi-sifirla', + name: 'ResetPassword', + component: ResetPassword, + meta: { + authpage: true + } +} diff --git a/src/module/auth/services/authService.ts b/src/module/auth/services/authService.ts index 0d8fe98..7b52a17 100644 --- a/src/module/auth/services/authService.ts +++ b/src/module/auth/services/authService.ts @@ -1,17 +1,59 @@ import { defineStore } from 'pinia' import { useDataStore } from '@/stores/dataStore' import { useAuthStore } from '../stores/authStore' +import { useAuthValidationStore } from '../validation/authValidationStore' +import { useUsersStore } from '@/stores/usersStore' +import router from '@/router' -export const useAppService = defineStore('appService', () => { +export const useAuthService = defineStore('authService', () => { const dataStore = useDataStore() const authStore = useAuthStore() + const authValidationStore = useAuthValidationStore() + const usersStore = useUsersStore() - const GetAAuthRoleList = async () => { - if (authStore.rolesList.length === 0) { - let data = await dataStore.dataGet('Auth/rolelistesi') - authStore.rolesList = data + const Login = async () => { + if (authValidationStore.LoginFormCheck()) { + let login = await dataStore.dataPost('Auth/login', { + data: authStore.loginData + }) + Object.assign(authStore.loginData, authStore.safeLoginData) + if (login !== 'errorfalse') { + await usersStore.SetUserSessionData(login) + await usersStore.SetUserData() + + if (usersStore.isPanelUser) { + router.push('/') + } else { + if (usersStore.userStatus === 0 || usersStore.userStatus === null) { + router.push('/profil') + } else { + router.push('/') + } + } + } else { + authValidationStore.loginMessageType = 'alert' + authValidationStore.loginMessage = + 'Kullanıcı adı veya şifrenizi yanlış girdiniz. Lütfen kontrol edip tekrar deneyiniz.' + authValidationStore.isLoginMessage = true + } + } else { + authValidationStore.isLoginFormValid = true } } - return {GetAAuthRoleList} + const ResetPassword = async () => { + if (authValidationStore.ResetPasswordFormCheck()) { + let dt: any + + dt = await dataStore.dataPost('ResetPassword', { + data: authStore.resetPasswordForm + }) + if (dt !== 'errorfalse') { + } + } else { + authValidationStore.isResetPasswordFormValid = true + } + } + + return { Login, ResetPassword } }) diff --git a/src/module/auth/stores/authStore.ts b/src/module/auth/stores/authStore.ts index 1dfaa24..72f68e0 100644 --- a/src/module/auth/stores/authStore.ts +++ b/src/module/auth/stores/authStore.ts @@ -1,12 +1,19 @@ import { defineStore } from 'pinia' -import { ref,reactive } from 'vue' +import { ref, reactive } from 'vue' export const useAuthStore = defineStore('authStore', () => { const loginData = reactive>({ username: '', password: '' }) const safeLoginData = reactive>({}) const rolesList = ref[]>([]) + const resetCheckData = ref('') + + const resetPasswordForm = reactive>({ + newPassword: '', + newPasswordRepeat: '', + check: '' + }) Object.assign(safeLoginData, loginData) - return { loginData, safeLoginData, rolesList } + return { loginData, safeLoginData, rolesList, resetPasswordForm, resetCheckData } }) diff --git a/src/module/auth/stores/authValidationStore.ts b/src/module/auth/stores/authValidationStore.ts deleted file mode 100644 index ba157c7..0000000 --- a/src/module/auth/stores/authValidationStore.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { defineStore } from 'pinia' -import { ref, reactive } from 'vue' -import { useAuthStore } from './authStore' -import { useValidationStore } from '@/stores/validationStore' - -export const useAuthValidationStore = defineStore('authValidationStore', () => { - const authStore = useAuthStore() - const validationStore = useValidationStore() - - const isFormValid = ref(true) - const isLoginMessage = ref(false) - const loginMessageType = ref('success') - const loginMessage = ref('') - const registerMessage = ref('') - const invalidTexts = reactive>({}) - - const FormCheck = (): boolean => { - Object.assign(invalidTexts, {}) - - validationStore.IsFieldEmpty( - authStore.loginData, - invalidTexts, - 'username', - 'Kullanıcı adı alanını doldurmalısınız. Örn: isim@alanadi.td' - ) - validationStore.IsFieldEmpty( - authStore.loginData, - invalidTexts, - 'password', - 'Lütfen şifrenizi giriniz.' - ) - - isFormValid.value = Object.keys(invalidTexts).length === 0 - return isFormValid.value - } - - return { - isFormValid, - invalidTexts, - isLoginMessage, - loginMessageType, - loginMessage, - registerMessage, - FormCheck - } -}) diff --git a/src/module/auth/validation/authValidationStore.ts b/src/module/auth/validation/authValidationStore.ts new file mode 100644 index 0000000..961a089 --- /dev/null +++ b/src/module/auth/validation/authValidationStore.ts @@ -0,0 +1,89 @@ +import { defineStore } from 'pinia' +import { ref, reactive } from 'vue' +import { useValidationStore } from '@/stores/validationStore' +import { useAuthStore } from '../stores/authStore' + +export const useAuthValidationStore = defineStore('authValidationStore', () => { + const validationStore = useValidationStore() + const authStore = useAuthStore() + + const isLoginMessage = ref(false) + const loginMessageType = ref('success') + const loginMessage = ref('') + const registerMessage = ref('') + + const loginInvalidTexts = reactive>({}) + const isLoginFormValid = ref(true) + const resetPasswordFormChanged = ref(false) + const isResetPasswordFormValid = ref(true) + const resetPasswordInvalidTexts = reactive>({}) + + const LoginFormCheck = (): boolean => { + Object.assign(loginInvalidTexts, {}) + + validationStore.IsFieldEmpty( + authStore.loginData, + loginInvalidTexts, + 'username', + 'Kullanıcı adı alanını doldurmalısınız. Örn: isim@alanadi.td' + ) + validationStore.IsFieldEmpty( + authStore.loginData, + loginInvalidTexts, + 'password', + 'Lütfen şifrenizi giriniz.' + ) + + isLoginFormValid.value = Object.keys(loginInvalidTexts).length === 0 + return isLoginFormValid.value + } + + const ResetPasswordFormCheck = (): boolean => { + Object.assign(resetPasswordInvalidTexts, {}) + + validationStore.IsFieldEmpty( + authStore.resetPasswordForm, + resetPasswordInvalidTexts, + 'newPassword', + 'Lütfen yeni şifrenizi giriniz.' + ) + + validationStore.IsFieldEmpty( + authStore.resetPasswordForm, + resetPasswordInvalidTexts, + 'newPasswordRepeat', + 'Lütfen yeni şifrenizi tekrar giriniz.' + ) + + if ( + !validationStore.checkEmpty(authStore.resetPasswordForm.newPassword) && + !validationStore.checkEmpty(authStore.resetPasswordForm.newPasswordRepeat) + ) { + if ( + authStore.resetPasswordForm.newPassword !== + authStore.resetPasswordForm.newPasswordRepeat + ) { + isResetPasswordFormValid.value = false + resetPasswordInvalidTexts.newPasswordRepeat = + 'Şifrenizi tekrar doğru girdiğinizden emin olunuz.' + } + } + + isResetPasswordFormValid.value = Object.keys(resetPasswordInvalidTexts).length === 0 + return isResetPasswordFormValid.value + } + + return { + isLoginMessage, + loginMessageType, + loginMessage, + loginInvalidTexts, + registerMessage, + isLoginFormValid, + resetPasswordFormChanged, + isResetPasswordFormValid, + resetPasswordInvalidTexts, + LoginFormCheck, + ResetPasswordFormCheck + } +}) diff --git a/src/module/auth/views/ForgotPassword.vue b/src/module/auth/views/ForgotPassword.vue index 2a25e5c..eac51ea 100644 --- a/src/module/auth/views/ForgotPassword.vue +++ b/src/module/auth/views/ForgotPassword.vue @@ -24,7 +24,7 @@ diff --git a/src/module/auth/views/Login.vue b/src/module/auth/views/Login.vue index 4541a7e..87777f2 100644 --- a/src/module/auth/views/Login.vue +++ b/src/module/auth/views/Login.vue @@ -3,14 +3,12 @@ diff --git a/src/module/auth/views/Register.vue b/src/module/auth/views/Register.vue index d7cd991..be5a4d3 100644 --- a/src/module/auth/views/Register.vue +++ b/src/module/auth/views/Register.vue @@ -339,7 +339,7 @@ @@ -355,7 +355,7 @@ const globalDataStore = useGlobalDataStore() import { useValidationStore } from '@/stores/validationStore' const validationStore = useValidationStore() - import { useAuthValidationStore } from '../stores/authValidationStore' + import { useAuthValidationStore } from '../validation/authValidationStore' const authValidationStore = useAuthValidationStore() import router from '@/router' @@ -413,7 +413,7 @@ 'Başarıyla kayıt oldunuz. Kullanıcı adı ve şifreniz ile giriş yapabilirsiniz.' authValidationStore.isLoginMessage = true - router.push('/login') + router.push('/giris') } } else { uyeBilgileriStore.isFormValid = true diff --git a/src/module/auth/views/ResetPassword.vue b/src/module/auth/views/ResetPassword.vue new file mode 100644 index 0000000..685aa91 --- /dev/null +++ b/src/module/auth/views/ResetPassword.vue @@ -0,0 +1,62 @@ + + diff --git a/src/router/index.ts b/src/router/index.ts index b5afbd7..c83327b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -39,7 +39,7 @@ router.beforeEach((to, from) => { const usersStore = useUsersStore() if (to.meta.authRequired && !usersStore.userIsAuth && from.name !== 'Login') { - router.push('/login') + router.push('/giris') } })