diff --git a/app/Controllers/Http/Admin/UsersController.ts b/app/Controllers/Http/Admin/UsersController.ts index 37d91df..3a4d330 100644 --- a/app/Controllers/Http/Admin/UsersController.ts +++ b/app/Controllers/Http/Admin/UsersController.ts @@ -4,10 +4,10 @@ import Role from 'App/Models/Role'; import type { ModelQueryBuilderContract } from '@ioc:Adonis/Lucid/Orm'; import CreateUserValidator from 'App/Validators/CreateUserValidator'; import UpdateUserValidator from 'App/Validators/UpdateUserValidator'; -import { RenderResponse } from '@ioc:EidelLev/Inertia'; +// import { RenderResponse } from '@ioc:EidelLev/Inertia'; +// import { schema, rules } from '@ioc:Adonis/Core/Validator'; +// import Hash from '@ioc:Adonis/Core/Hash'; // import { schema, rules } from '@ioc:Adonis/Core/Validator'; -import Hash from '@ioc:Adonis/Core/Hash'; -import { schema, rules } from '@ioc:Adonis/Core/Validator'; export default class UsersController { public async index({ auth, request, inertia }: HttpContextContract) { @@ -163,87 +163,6 @@ export default class UsersController { return response.redirect().toRoute('user.index'); } - /** - * Show the user a form to change their personal information & password. - * - * @return — \Inertia\Response - */ - public accountInfo({ inertia, auth }: HttpContextContract): RenderResponse { - const user = auth.user; - // const id = request.param('id'); - // const user = await User.query().where('id', id).firstOrFail(); - - return inertia.render('Admin/User/AccountInfo', { - user: user, - }); - } - - /** - * Save the modified personal information for a user. - * - * @param HttpContextContract ctx - * @return : RedirectContract - */ - public async accountInfoStoreOld({ request, response, auth, session }: HttpContextContract) { - // validate update form - await request.validate(UpdateUserValidator); - - const payload = request.only(['login', 'email']); - auth.user?.merge(payload); - const user = await auth.user?.save(); - // $user = \Auth::user()->update($request->except(['_token'])); - let message; - if (user) { - message = 'Account updated successfully.'; - } else { - message = 'Error while saving. Please try again.'; - } - - session.flash(message); - return response.redirect().toRoute('admin.account.info'); - //->with('message', __($message)); - } - - public async accountInfoStore({ auth, request, response, session }) { - 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')]), - confirm_password: schema.string({ trim: true }, [rules.required()]), - }); - try { - await request.validate({ schema: passwordSchema }); - } catch (error) { - // return response.badRequest(error.messages); - throw error; - } - - try { - const user = await auth.user; - const { old_password, new_password } = request.only(['old_password', 'new_password']); - - // if (!(old_password && new_password && confirm_password)) { - // return response.status(400).send({ warning: 'Old password and new password are required.' }); - // } - - // Verify if the provided old password matches the user's current password - const isSame = await Hash.verify(user.password, old_password); - if (!isSame) { - return response.flash({ warning: 'Old password is incorrect.' }).redirect().back(); - } - - // Hash the new password before updating the user's password - user.password = new_password; - await user.save(); - - // return response.status(200).send({ message: 'Password updated successfully.' }); - session.flash('Password updated successfully.'); - return response.redirect().toRoute('settings.user.index'); - } catch (error) { - // return response.status(500).send({ message: 'Internal server error.' }); - return response.flash('warning', `Invalid server state. Internal server error.`).redirect().back(); - } - } - // private async syncRoles(userId: number, roleIds: Array) { // const user = await User.findOrFail(userId) // // const roles: Role[] = await Role.query().whereIn('id', roleIds); diff --git a/app/Controllers/Http/Auth/UserController.ts b/app/Controllers/Http/Auth/UserController.ts index 736206e..91f3131 100644 --- a/app/Controllers/Http/Auth/UserController.ts +++ b/app/Controllers/Http/Auth/UserController.ts @@ -1,10 +1,9 @@ import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; import User from 'App/Models/User'; -// import Hash from '@ioc:Adonis/Core/Hash'; -// import InvalidCredentialException from 'App/Exceptions/InvalidCredentialException'; -// import AuthValidator from 'App/Validators/AuthValidator'; 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'; // Here we are generating secret and recovery codes for the user that’s enabling 2FA and storing them to our database. export default class UserController { @@ -26,6 +25,46 @@ export default class UserController { }); } + public async accountInfoStore({ auth, request, response, session }) { + 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')]), + confirm_password: schema.string({ trim: true }, [rules.required()]), + }); + try { + await request.validate({ schema: passwordSchema }); + } catch (error) { + // return response.badRequest(error.messages); + throw error; + } + + try { + const user = await auth.user; + const { old_password, new_password } = request.only(['old_password', 'new_password']); + + // if (!(old_password && new_password && confirm_password)) { + // return response.status(400).send({ warning: 'Old password and new password are required.' }); + // } + + // Verify if the provided old password matches the user's current password + const isSame = await Hash.verify(user.password, old_password); + if (!isSame) { + return response.flash({ warning: 'Old password is incorrect.' }).redirect().back(); + } + + // Hash the new password before updating the user's password + user.password = new_password; + await user.save(); + + // return response.status(200).send({ message: 'Password updated successfully.' }); + session.flash('Password updated successfully.'); + return response.redirect().toRoute('settings.user.index'); + } catch (error) { + // return response.status(500).send({ message: 'Internal server error.' }); + return response.flash('warning', `Invalid server state. Internal server error.`).redirect().back(); + } + } + public async enableTwoFactorAuthentication({ auth, response, session }: HttpContextContract): Promise { // const user: User | undefined = auth?.user; const user = (await User.find(auth.user?.id)) as User; diff --git a/app/Controllers/Http/Editor/deleteDoiMetadata.xml b/app/Controllers/Http/Editor/deleteDoiMetadata.xml index 3917c1e..a286c64 100644 --- a/app/Controllers/Http/Editor/deleteDoiMetadata.xml +++ b/app/Controllers/Http/Editor/deleteDoiMetadata.xml @@ -1,48 +1,3 @@ - - - - - - - - - - - - - - - - - - - - - - { // const clamscan = await (new ClamScan().init()); const opts: ClamScan.Options = { diff --git a/package-lock.json b/package-lock.json index 96acef8..19d4e23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3662,9 +3662,9 @@ } }, "node_modules/@redis/client": { - "version": "1.5.13", - "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.13.tgz", - "integrity": "sha512-epkUM9D0Sdmt93/8Ozk43PNjLi36RZzG+d/T1Gdu5AI8jvghonTeLYV69WVWdilvFo+PYxbP0TZ0saMvr6nscQ==", + "version": "1.5.14", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.14.tgz", + "integrity": "sha512-YGn0GqsRBFUQxklhY7v562VMOP0DcmlrHHs3IV1mFE3cbxe31IITUkqhBcIhVSI/2JqtWAJXg5mjV4aU+zD0HA==", "dependencies": { "cluster-key-slot": "1.1.2", "generic-pool": "3.9.0", @@ -4081,9 +4081,9 @@ } }, "node_modules/@types/express-serve-static-core": { - "version": "4.17.42", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.42.tgz", - "integrity": "sha512-ckM3jm2bf/MfB3+spLPWYPUH573plBFwpOhqQ2WottxYV85j1HQFlxmnTq57X1yHY9awZPig06hL/cLMgNWHIQ==", + "version": "4.17.43", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.43.tgz", + "integrity": "sha512-oaYtiBirUOPQGSWNGPWnzyAFJ0BP3cwvN4oWZQY+zUBwpVIGsKUkpBpSztp74drYcjavs7SKFZ4DX1V2QeN8rg==", "dev": true, "dependencies": { "@types/node": "*", @@ -4382,9 +4382,9 @@ } }, "node_modules/@types/validator": { - "version": "13.11.8", - "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.11.8.tgz", - "integrity": "sha512-c/hzNDBh7eRF+KbCf+OoZxKbnkpaK/cKp9iLQWqB7muXtM+MtL9SUUH8vCFcLn6dH1Qm05jiexK0ofWY7TfOhQ==" + "version": "13.11.9", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.11.9.tgz", + "integrity": "sha512-FCTsikRozryfayPuiI46QzH3fnrOoctTjvOYZkho9BTFLCOZ2rgZJHMOVgCOfttjPJcgOx52EpkY0CMfy87MIw==" }, "node_modules/@types/ws": { "version": "8.5.10", @@ -6298,13 +6298,17 @@ } }, "node_modules/call-bind": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", - "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.6.tgz", + "integrity": "sha512-Mj50FLHtlsoVfRfnHaZvyrooHcrlceNZdL/QBvJJVd9Ta55qCQK0gs4ss2oZDeV9zFCs6ewzYgVE5yfVmfFpVg==", "dependencies": { + "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.1", - "set-function-length": "^1.1.1" + "get-intrinsic": "^1.2.3", + "set-function-length": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -6368,9 +6372,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001583", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001583.tgz", - "integrity": "sha512-acWTYaha8xfhA/Du/z4sNZjHUWjkiuoAi2LM+T/aL+kemKQgPT1xBb/YKjlQ0Qo8gvbHsGNplrEJ+9G3gL7i4Q==", + "version": "1.0.30001584", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001584.tgz", + "integrity": "sha512-LOz7CCQ9M1G7OjJOF9/mzmqmj3jE/7VOmrfw6Mgs0E8cjOsbRXQJHsPBfmBOXDskXKrHLyyW3n7kpDW/4BsfpQ==", "dev": true, "funding": [ { @@ -7643,13 +7647,14 @@ } }, "node_modules/define-data-property": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", - "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.2.tgz", + "integrity": "sha512-SRtsSqsDbgpJBbW3pABMCOt6rQyeM8s8RiyeSN8jYG8sYmt/kGJejbydttUsnDs1tadr19tvhT4ShwMyoqAm4g==", "dependencies": { - "get-intrinsic": "^1.2.1", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.2", "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.0" + "has-property-descriptors": "^1.0.1" }, "engines": { "node": ">= 0.4" @@ -8121,9 +8126,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.655", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.655.tgz", - "integrity": "sha512-2yszojF7vIZ68adIOvzV4bku8OZad9w5H9xF3ZAMZjPuOjBarlflUkjN6DggdV+L71WZuKUfKUhov/34+G5QHg==", + "version": "1.4.657", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.657.tgz", + "integrity": "sha512-On2ymeleg6QbRuDk7wNgDdXtNqlJLM2w4Agx1D/RiTmItiL+a9oq5p7HUa2ZtkAtGBe/kil2dq/7rPfkbe0r5w==", "dev": true }, "node_modules/emittery": { @@ -8240,15 +8245,23 @@ "stackframe": "^1.3.4" } }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-module-lexer": { "version": "0.3.26", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.3.26.tgz", "integrity": "sha512-Va0Q/xqtrss45hWzP8CZJwzGSZJjDM5/MJRE3IXXnUCcVLElR9BRaE9F62BopysASyc4nM3uwhSW7FFB9nlWAA==" }, "node_modules/escalade": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", - "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", + "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", "engines": { "node": ">=6" } @@ -8981,9 +8994,9 @@ } }, "node_modules/fastq": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.0.tgz", - "integrity": "sha512-zGygtijUMT7jnk3h26kUms3BkSDp4IfIKjmnqI2tvx6nuBfiF1UqOxbnLfzdv+apBy+53oaImsKtMw/xYbW+1w==", + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", + "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", "dev": true, "dependencies": { "reusify": "^1.0.4" @@ -9384,15 +9397,19 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", - "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", "dependencies": { + "es-errors": "^1.3.0", "function-bind": "^1.1.2", "has-proto": "^1.0.1", "has-symbols": "^1.0.3", "hasown": "^2.0.0" }, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -11582,9 +11599,9 @@ "integrity": "sha512-QS9p+Q20YBxpE0dJBnF6CPURP7p1GUsxnhTxTWH5nG3A1F5w8Rg3T4Xyh5UlrFSbHp88oOciVP/0agsNLhkHdQ==" }, "node_modules/magic-string": { - "version": "0.30.6", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.6.tgz", - "integrity": "sha512-n62qCLbPjNjyo+owKtveQxZFZTBm+Ms6YoGD23Wew6Vw337PElFNifQpknPruVRQV57kVShPnLGo9vWxVhpPvA==", + "version": "0.30.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.7.tgz", + "integrity": "sha512-8vBuFF/I/+OSLRmdf2wwFCJCz+nSn0m6DPvGH1fS/KiQoSaR+sETbov0eIk9KhEKy8CYqIkIAnbohxT/4H0kuA==", "dependencies": { "@jridgewell/sourcemap-codec": "^1.4.15" }, @@ -13375,9 +13392,9 @@ } }, "node_modules/postcss": { - "version": "8.4.33", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.33.tgz", - "integrity": "sha512-Kkpbhhdjw2qQs2O2DGX+8m5OVqEcbB9HRBvuYM9pgrjEFUg30A9LmXNlTAUj4S9kgtGyrMbTzVjH7E+s5Re2yg==", + "version": "8.4.34", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.34.tgz", + "integrity": "sha512-4eLTO36woPSocqZ1zIrFD2K1v6wH7pY1uBh0JIM2KKfrVtGvPFiAku6aNOP0W1Wr9qwnaCsF0Z+CrVnryB2A8Q==", "funding": [ { "type": "opencollective", @@ -14043,9 +14060,9 @@ } }, "node_modules/prettier": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.4.tgz", - "integrity": "sha512-FWu1oLHKCrtpO1ypU6J0SbK2d9Ckwysq6bHj/uaCP26DxrPpppCLQRGVuqAxSTvhF00AcvDRyYrLNW7ocBhFFQ==", + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", "dev": true, "bin": { "prettier": "bin/prettier.cjs" @@ -14416,12 +14433,12 @@ } }, "node_modules/redis": { - "version": "4.6.12", - "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.12.tgz", - "integrity": "sha512-41Xuuko6P4uH4VPe5nE3BqXHB7a9lkFL0J29AlxKaIfD6eWO8VO/5PDF9ad2oS+mswMsfFxaM5DlE3tnXT+P8Q==", + "version": "4.6.13", + "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.13.tgz", + "integrity": "sha512-MHgkS4B+sPjCXpf+HfdetBwbRz6vCtsceTmw1pHNYJAsYxrfpOP6dz+piJWGos8wqG7qb3vj/Rrc5qOlmInUuA==", "dependencies": { "@redis/bloom": "1.2.0", - "@redis/client": "1.5.13", + "@redis/client": "1.5.14", "@redis/graph": "1.1.1", "@redis/json": "1.0.6", "@redis/search": "1.1.6", @@ -14899,9 +14916,9 @@ } }, "node_modules/semver": { - "version": "7.5.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", "dependencies": { "lru-cache": "^6.0.0" }, diff --git a/resources/js/Pages/Dashboard.vue b/resources/js/Pages/Dashboard.vue index f888b73..c4c5f4e 100644 --- a/resources/js/Pages/Dashboard.vue +++ b/resources/js/Pages/Dashboard.vue @@ -1,6 +1,6 @@