initial commit
This commit is contained in:
commit
4fc3bb0a01
202 changed files with 41729 additions and 0 deletions
27
providers/AppProvider.ts
Normal file
27
providers/AppProvider.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import type { ApplicationContract } from '@ioc:Adonis/Core/Application';
|
||||
import Hash from '@ioc:Adonis/Core/Hash';
|
||||
import { LaravelHash } from './HashDriver';
|
||||
|
||||
export default class AppProvider {
|
||||
constructor(protected app: ApplicationContract) {}
|
||||
|
||||
public register() {
|
||||
// Register your own bindings
|
||||
}
|
||||
|
||||
public async boot() {
|
||||
// IoC container is ready
|
||||
const hashInstance: typeof Hash = this.app.container.use('Adonis/Core/Hash');
|
||||
hashInstance.extend('bcrypt', () => {
|
||||
return new LaravelHash();
|
||||
});
|
||||
}
|
||||
|
||||
public async ready() {
|
||||
// App is ready
|
||||
}
|
||||
|
||||
public async shutdown() {
|
||||
// Cleanup, since app is going down
|
||||
}
|
||||
}
|
21
providers/HashDriver/index.ts
Normal file
21
providers/HashDriver/index.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { HashDriverContract } from "@ioc:Adonis/Core/Hash";
|
||||
// const bcrypt = require("bcrypt");
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
const saltRounds = 10;
|
||||
export class LaravelHash implements HashDriverContract {
|
||||
public async make(value: string) {
|
||||
const _hashedValue = bcrypt.hashSync(value, saltRounds);
|
||||
return _hashedValue;
|
||||
}
|
||||
|
||||
public async verify(hashedValue: string, plainValue: string) {
|
||||
let newHash: string;
|
||||
if (hashedValue.includes("$2y$10$")) {
|
||||
newHash = hashedValue.replace("$2y$10$", "$2a$10$");
|
||||
} else {
|
||||
newHash = hashedValue;
|
||||
}
|
||||
return await bcrypt.compareSync(plainValue, newHash);
|
||||
}
|
||||
}
|
57
providers/QueryBuilderProvider.ts
Normal file
57
providers/QueryBuilderProvider.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
import type { ApplicationContract } from '@ioc:Adonis/Core/Application';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Provider
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Your application is not ready when this file is loaded by the framework.
|
||||
| Hence, the top level imports relying on the IoC container will not work.
|
||||
| You must import them inside the life-cycle methods defined inside
|
||||
| the provider class.
|
||||
|
|
||||
| @example:
|
||||
|
|
||||
| public async ready () {
|
||||
| const Database = this.app.container.resolveBinding('Adonis/Lucid/Database')
|
||||
| const Event = this.app.container.resolveBinding('Adonis/Core/Event')
|
||||
| Event.on('db:query', Database.prettyPrint)
|
||||
| }
|
||||
|
|
||||
*/
|
||||
export default class QueryBuilderProvider {
|
||||
constructor(protected app: ApplicationContract) {}
|
||||
|
||||
public register() {
|
||||
// Register your own bindings
|
||||
}
|
||||
|
||||
public async boot() {
|
||||
// All bindings are ready, feel free to use them
|
||||
const { ModelQueryBuilder } = this.app.container.resolveBinding('Adonis/Lucid/Database');
|
||||
|
||||
ModelQueryBuilder.macro('pluck', async function (valueColumn: string, id?: string) {
|
||||
let rolesPluck = {};
|
||||
(await this).forEach((user, index) => {
|
||||
let idc;
|
||||
if (!id) {
|
||||
idc = index;
|
||||
} else {
|
||||
idc = user[id];
|
||||
}
|
||||
const value = user[valueColumn];
|
||||
// rolesPluck[idc] = user.name;
|
||||
rolesPluck[idc] = value;
|
||||
});
|
||||
return rolesPluck;
|
||||
});
|
||||
}
|
||||
|
||||
public async ready() {
|
||||
// App is ready
|
||||
}
|
||||
|
||||
public async shutdown() {
|
||||
// Cleanup, since app is going down
|
||||
}
|
||||
}
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue