mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
ref: Refactoring
This commit is contained in:
parent
9011ee61da
commit
0fab6075bd
23 changed files with 96 additions and 91 deletions
|
@ -1,8 +1,8 @@
|
|||
const { getRemoteAddress } = require('../../../utils/remoteAddress');
|
||||
|
||||
const Errors = {
|
||||
INVALID_TOKEN: {
|
||||
invalidToken: 'Invalid token',
|
||||
INVALID_CODE_OR_NONCE: {
|
||||
invalidCodeOrNonce: 'Invalid code or nonce',
|
||||
},
|
||||
EMAIL_ALREADY_IN_USE: {
|
||||
emailAlreadyInUse: 'Email already in use',
|
||||
|
@ -28,7 +28,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
exits: {
|
||||
invalidToken: {
|
||||
invalidCodeOrNonce: {
|
||||
responseType: 'unauthorized',
|
||||
},
|
||||
emailAlreadyInUse: {
|
||||
|
@ -46,10 +46,10 @@ module.exports = {
|
|||
const remoteAddress = getRemoteAddress(this.req);
|
||||
|
||||
const user = await sails.helpers.users
|
||||
.getOrCreateOneByOidcToken(inputs.code, inputs.nonce)
|
||||
.intercept('invalidToken', () => {
|
||||
sails.log.warn(`Invalid token! (IP: ${remoteAddress})`);
|
||||
return Errors.INVALID_TOKEN;
|
||||
.getOrCreateOneUsingOidc(inputs.code, inputs.nonce)
|
||||
.intercept('invalidCodeOrNonce', () => {
|
||||
sails.log.warn(`Invalid code or nonce! (IP: ${remoteAddress})`);
|
||||
return Errors.INVALID_CODE_OR_NONCE;
|
||||
})
|
||||
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
|
||||
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE)
|
|
@ -1,20 +1,21 @@
|
|||
module.exports = {
|
||||
fn() {
|
||||
const oidcClient = sails.hooks.oidc.isActive() ? sails.hooks.oidc.getClient() : null;
|
||||
let oidc = null;
|
||||
if (sails.hooks.oidc.isActive()) {
|
||||
const oidcClient = sails.hooks.oidc.getClient();
|
||||
|
||||
oidc = {
|
||||
authorizationUrl: oidcClient.authorizationUrl({
|
||||
scope: sails.config.custom.oidcScopes,
|
||||
response_mode: 'fragment',
|
||||
}),
|
||||
endSessionUrl: oidcClient.issuer.end_session_endpoint ? oidcClient.endSessionUrl({}) : null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
item: {
|
||||
oidc:
|
||||
sails.config.custom.oidcIssuer !== ''
|
||||
? {
|
||||
authorizationUrl: oidcClient.authorizationUrl({
|
||||
scope: sails.config.custom.oidcScopes,
|
||||
response_mode: 'fragment',
|
||||
}),
|
||||
endSessionUrl: oidcClient.issuer.end_session_endpoint
|
||||
? oidcClient.endSessionUrl({})
|
||||
: null,
|
||||
}
|
||||
: null,
|
||||
oidc,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue