- update to AdonisJS 6
Some checks failed
CI Pipeline / japa-tests (push) Failing after 1m15s

This commit is contained in:
Kaimbacher 2024-03-14 20:25:27 +01:00
parent f828ca4491
commit cb51a4136f
167 changed files with 21485 additions and 21212 deletions

View file

@ -1,9 +1,9 @@
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
import User from 'App/Models/User';
import { RenderResponse } from '@ioc:EidelLev/Inertia';
import TwoFactorAuthProvider from 'App/Services/TwoFactorAuthProvider';
import Hash from '@ioc:Adonis/Core/Hash';
import { schema, rules } from '@ioc:Adonis/Core/Validator';
import type { HttpContext } from '@adonisjs/core/http';
import User from '#app/Models/User';
// import { RenderResponse } from '@ioc:EidelLev/Inertia';
import TwoFactorAuthProvider from '#app/Services/TwoFactorAuthProvider';
import hash from '@adonisjs/core/services/hash';
import { schema, rules } from '@adonisjs/validator';
// Here we are generating secret and recovery codes for the user thats enabling 2FA and storing them to our database.
export default class UserController {
@ -12,7 +12,7 @@ export default class UserController {
*
* @return \Inertia\Response
*/
public async accountInfo({ inertia, auth }: HttpContextContract): RenderResponse {
public async accountInfo({ inertia, auth }: HttpContext) {
// const user = auth.user;
const user = (await User.find(auth.user?.id)) as User;
// const id = request.param('id');
@ -25,7 +25,7 @@ export default class UserController {
});
}
public async accountInfoStore({ auth, request, response, session }) {
public async accountInfoStore({ auth, request, response, session }: HttpContext) {
const passwordSchema = schema.create({
old_password: schema.string({ trim: true }, [rules.required()]),
new_password: schema.string({ trim: true }, [rules.minLength(8), rules.maxLength(255), rules.confirmed('confirm_password')]),
@ -39,7 +39,7 @@ export default class UserController {
}
try {
const user = await auth.user;
const user = await auth.user as User;
const { old_password, new_password } = request.only(['old_password', 'new_password']);
// if (!(old_password && new_password && confirm_password)) {
@ -47,9 +47,9 @@ export default class UserController {
// }
// Verify if the provided old password matches the user's current password
const isSame = await Hash.verify(user.password, old_password);
const isSame = await hash.verify(user.password, old_password);
if (!isSame) {
return response.flash({ warning: 'Old password is incorrect.' }).redirect().back();
return response.flash('warning', 'Old password is incorrect.').redirect().back();
}
// Hash the new password before updating the user's password
@ -57,7 +57,7 @@ export default class UserController {
await user.save();
// return response.status(200).send({ message: 'Password updated successfully.' });
session.flash('Password updated successfully.');
session.flash({ message: 'Password updated successfully.' });
return response.redirect().toRoute('settings.user.index');
} catch (error) {
// return response.status(500).send({ message: 'Internal server error.' });
@ -65,7 +65,7 @@ export default class UserController {
}
}
public async enableTwoFactorAuthentication({ auth, response, session }: HttpContextContract): Promise<void> {
public async enableTwoFactorAuthentication({ auth, response, session }: HttpContext): Promise<void> {
// const user: User | undefined = auth?.user;
const user = (await User.find(auth.user?.id)) as User;
@ -87,7 +87,7 @@ export default class UserController {
// });
}
public async disableTwoFactorAuthentication({ auth, response, session }): Promise<void> {
public async disableTwoFactorAuthentication({ auth, response, session }: HttpContext): Promise<void> {
const user = auth?.user;
user.twoFactorSecret = null;