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)
|
||||
response.redirect().toRoute('events.index')
|
||||
}
|
||||
@@ -25,8 +31,11 @@ export default class AuthController {
|
||||
public async logout({ auth, response, session }: HttpContextContract) {
|
||||
await auth.logout()
|
||||
|
||||
session.flash('errors', {
|
||||
logout: 'test'
|
||||
session.flash('gfd', {
|
||||
warning: 'test'
|
||||
})
|
||||
session.flash('login', {
|
||||
warning: "noch eine warning"
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export default class ExceptionHandler extends HttpExceptionHandler {
|
||||
* Handle failed authentication attempt
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,35 +17,58 @@
|
||||
|
||||
function displayNewMessages(messages) {
|
||||
|
||||
if (messages) {
|
||||
const stack = [messages];
|
||||
while (stack?.length > 0) {
|
||||
const currentObj = stack.pop();
|
||||
Object.keys(currentObj).forEach(key => {
|
||||
console.log(`key: ${key}, value: ${currentObj[key]}`);
|
||||
console.log(messages)
|
||||
let output = []
|
||||
|
||||
if (typeof currentObj[key] === 'object' && currentObj[key] !== null) {
|
||||
stack.push(currentObj[key]);
|
||||
}
|
||||
});
|
||||
output = flattenObject(removeValidationErrors(messages))
|
||||
|
||||
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),{
|
||||
closable: true
|
||||
})
|
||||
}*/
|
||||
})
|
||||
}
|
||||
|
||||
function removeValidationErrors(input) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user