@live-change/password-authentication-service
Advanced tools
Comparing version 0.2.7 to 0.2.12
73
index.js
@@ -1,10 +0,14 @@ | ||
const autoValidation = require('@live-change/framework/lib/processors/autoValidation') | ||
const nodemailer = require('nodemailer') | ||
const crypto = require('crypto') | ||
const app = require("@live-change/framework").app() | ||
const user = require('@live-change/user-service') | ||
const { AuthenticatedUser } = require("../user-service/model.js") | ||
const definition = app.createServiceDefinition({ | ||
name: "passwordAuthentication" | ||
name: "passwordAuthentication", | ||
use: [ user ] | ||
}) | ||
const config = definition.config | ||
const User = definition.foreignModel('user', 'User') | ||
const secretProperties = { | ||
@@ -20,2 +24,65 @@ passwordHash: { | ||
const PasswordAuthentication = definition.model({ | ||
name: 'PasswordAuthentication', | ||
userProperty: { | ||
userViews: [ | ||
{ suffix: 'Exists', fields: ['user'] } | ||
] | ||
}, | ||
properties: { | ||
...secretProperties, | ||
} | ||
}) | ||
definition.event({ | ||
name: 'passwordAuthenticationSet', | ||
async execute({ user, passwordHash }) { | ||
await PasswordAuthentication.create({ id: user, user, passwordHash }) | ||
} | ||
}) | ||
definition.action({ | ||
name: 'setPassword', | ||
waitForEvents: true, | ||
properties: { | ||
...secretProperties | ||
}, | ||
access: (params, { client }) => { | ||
return !!client.user | ||
}, | ||
async execute({ passwordHash }, { client, service }, emit) { | ||
const user = client.user | ||
const passwordAuthenticationData = await PasswordAuthentication.get(user) | ||
if(passwordAuthenticationData) throw 'exists' | ||
emit({ | ||
type: 'passwordAuthenticationSet', | ||
user, passwordHash | ||
}) | ||
} | ||
}) | ||
definition.action({ | ||
name: 'changePassword', | ||
waitForEvents: true, | ||
properties: { | ||
currentPasswordHash: secretProperties.passwordHash, | ||
...secretProperties | ||
}, | ||
access: (params, { client }) => { | ||
return !!client.user | ||
}, | ||
async execute({ currentPasswordHash, passwordHash }, { client, service }, emit) { | ||
const user = client.user | ||
const passwordAuthenticationData = await PasswordAuthentication.get(user) | ||
if(!passwordAuthenticationData) throw 'notFound' | ||
if(currentPasswordHash != passwordAuthenticationData.passwordHash) throw { properties: { | ||
currentPasswordHash: 'wrongPassword' | ||
} } | ||
emit({ | ||
type: 'passwordAuthenticationSet', | ||
user, passwordHash | ||
}) | ||
} | ||
}) | ||
for(const contactType of config.contactTypes) { | ||
@@ -22,0 +89,0 @@ const contactTypeUpperCaseName = contactType[0].toUpperCase() + contactType.slice(1) |
{ | ||
"name": "@live-change/password-authentication-service", | ||
"version": "0.2.7", | ||
"version": "0.2.12", | ||
"description": "", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "f864cf2344e08f5678d1c2171f7ce594066b2ed8" | ||
"gitHead": "a0dce761d803684a74e4cf4d50c63a0dc80dd4cf" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5449
147