smth smth flashmessages
This commit is contained in:
@@ -18,6 +18,12 @@ export default class AuthController {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
session.flash({
|
||||||
|
login: {
|
||||||
|
warning: 'test'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
await auth.attempt(username, password)
|
await auth.attempt(username, password)
|
||||||
response.redirect().toRoute('events.index')
|
response.redirect().toRoute('events.index')
|
||||||
}
|
}
|
||||||
@@ -25,8 +31,11 @@ export default class AuthController {
|
|||||||
public async logout({ auth, response, session }: HttpContextContract) {
|
public async logout({ auth, response, session }: HttpContextContract) {
|
||||||
await auth.logout()
|
await auth.logout()
|
||||||
|
|
||||||
session.flash('errors', {
|
session.flash('gfd', {
|
||||||
logout: 'test'
|
warning: 'test'
|
||||||
|
})
|
||||||
|
session.flash('login', {
|
||||||
|
warning: "noch eine warning"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export default class ExceptionHandler extends HttpExceptionHandler {
|
|||||||
* Handle failed authentication attempt
|
* Handle failed authentication attempt
|
||||||
*/
|
*/
|
||||||
if (['E_INVALID_AUTH_PASSWORD', 'E_INVALID_AUTH_UID'].includes(error.code)) {
|
if (['E_INVALID_AUTH_PASSWORD', 'E_INVALID_AUTH_UID'].includes(error.code)) {
|
||||||
session.flash('errors', { login: error.message });
|
session.flash('login', { error: error.message });
|
||||||
return response.redirect().back();
|
return response.redirect().back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,35 +17,58 @@
|
|||||||
|
|
||||||
function displayNewMessages(messages) {
|
function displayNewMessages(messages) {
|
||||||
|
|
||||||
if (messages) {
|
console.log(messages)
|
||||||
const stack = [messages];
|
let output = []
|
||||||
while (stack?.length > 0) {
|
|
||||||
const currentObj = stack.pop();
|
|
||||||
Object.keys(currentObj).forEach(key => {
|
|
||||||
console.log(`key: ${key}, value: ${currentObj[key]}`);
|
|
||||||
|
|
||||||
if (typeof currentObj[key] === 'object' && currentObj[key] !== null) {
|
output = flattenObject(removeValidationErrors(messages))
|
||||||
stack.push(currentObj[key]);
|
|
||||||
}
|
console.log(output)
|
||||||
});
|
|
||||||
|
output?.forEach((item) => {
|
||||||
|
for (let key in item) {
|
||||||
|
switch (key){
|
||||||
|
case 'error':
|
||||||
|
message.error(
|
||||||
|
translateError(item[key]),
|
||||||
|
{ closable: true }
|
||||||
|
)
|
||||||
|
break
|
||||||
|
case 'warning':
|
||||||
|
message.warning(
|
||||||
|
translateError(item[key]),
|
||||||
|
{ closable: true}
|
||||||
|
)
|
||||||
|
break
|
||||||
|
case 'info':
|
||||||
|
message.info(
|
||||||
|
translateError(item[key]),
|
||||||
|
{ closable: true }
|
||||||
|
)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
message.warning(
|
||||||
|
translateError(item[key]),
|
||||||
|
{ closable: true }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
if(temp?.errors) {
|
|
||||||
for (let key in temp.errors){
|
|
||||||
message.error(translateError(temp.errors[key]),{
|
|
||||||
closable: true
|
|
||||||
})
|
|
||||||
delete temp.errors[key]
|
|
||||||
}
|
}
|
||||||
if(isEmpty(temp.errors)) delete temp['errors']
|
})
|
||||||
}
|
}
|
||||||
if(!isEmpty(temp)) {
|
|
||||||
message.error(JSON.stringify(temp),{
|
function removeValidationErrors(input) {
|
||||||
closable: true
|
if(input === null || !Object.hasOwn(input, "errors")) return input
|
||||||
})
|
|
||||||
}*/
|
const { errors: _, ...output } = input
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
function flattenObject(input) {
|
||||||
|
if (input === null) return input
|
||||||
|
|
||||||
|
return Object.values(input).map((value) => Object.entries(value)).flat().reduce((acc, [key, value]) => {
|
||||||
|
acc.push({[key]: value});
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
function translateError(errorMsg) {
|
function translateError(errorMsg) {
|
||||||
|
|||||||
Reference in New Issue
Block a user