更新
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
module.exports = {
|
||||
//获取用户所属组织信息
|
||||
async getUserToOrg(uid) {
|
||||
|
||||
},
|
||||
//获取用户所属分组信息
|
||||
async getUserToGroup(uid) {
|
||||
|
||||
},
|
||||
//获取用户权限
|
||||
async getUserToPermission(uid) {
|
||||
|
||||
},
|
||||
//获取用户角色信息
|
||||
async getUserToRole(uid) {
|
||||
|
||||
},
|
||||
//获取用户组织/分组/角色/权限
|
||||
async getUserAll(uid) {
|
||||
|
||||
},
|
||||
//获取组织下全部分组
|
||||
async getOrgToGroupAll(uid) {
|
||||
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
const crypto = require('crypto');
|
||||
module.exports = {
|
||||
// 随机数(盐值)
|
||||
getRandomSalt() {
|
||||
return Math.random().toString().slice(2, 5);
|
||||
},
|
||||
// 加密用户密码(原始密码,盐值)
|
||||
// 密码同样是123456,由于采用了随机盐值,前后运算得出的结果是不同的。
|
||||
// 这样带来的好处是,多个用户,同样的密码,攻击者需要进行多次运算才能够完全破解。
|
||||
// 同样是纯数字3位短盐值,随机盐值破解所需的运算量,是固定盐值的1000倍。
|
||||
cryptPwd(password, salt) {
|
||||
|
||||
// 密码“加盐”
|
||||
const saltPassword = password + ':' + salt;
|
||||
// 加盐密码的md5值
|
||||
const md5 = crypto.createHash('md5');
|
||||
return md5.update(saltPassword).digest('hex');
|
||||
},
|
||||
// 密码验证,如果验证通过 返回 true
|
||||
cryptPwdVerification(password, salt, user_password_md5) {
|
||||
return this.cryptPwd(password, salt) === user_password_md5;
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
secret : 'sQ6CIfqS4SqF1zZqRZbCDAT5@T]X4fCD',//秘钥
|
||||
algorithm: 'HS256',//数字签名或 MAC 算法
|
||||
expiresIn: "7d",//有效期:例如:1000, "2 days", "10h", "7d". 数值被解释为秒数。如果使用字符串,请确保提供时间单位(天、小时等),否则默认使用毫秒单位("120"等于"120ms")。
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
const config = require("./config.js");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 签发token
|
||||
* @param {object} data 加入到签名里的数据.
|
||||
* @return {string} token 令牌.
|
||||
*/
|
||||
sign: (data) => jwt.sign(data, config.secret, {algorithm: config.algorithm, expiresIn: config.expiresIn}),
|
||||
/**
|
||||
* 验证token
|
||||
* @param {string} token 令牌.
|
||||
* @return {boolean} 验证通过返回true.
|
||||
*/
|
||||
verify: (token) => jwt.verify(token, config.secret, {algorithm: config.algorithm, expiresIn: config.expiresIn}),
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* app.components.login.accountPassword
|
||||
* 账号密码登陆
|
||||
* @param {string} data.account 账号.
|
||||
* @param {string} data.password 密码.
|
||||
* @return {object} res 验证是否通过.
|
||||
*/
|
||||
module.exports = async (data) => {
|
||||
const {account, password} = data
|
||||
const User = await app.db.table("User").where({account}).find()
|
||||
if (!User) return false
|
||||
const {salt} = User
|
||||
const ver = app.components.encrypt.cryptPwdVerification(password, salt, User.password)
|
||||
return ver
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* app.components.registered.accountPassword
|
||||
* 账号密码注册
|
||||
* @param {string} data.account 账号.
|
||||
* @param {string} data.password 密码.
|
||||
* @return {boolean} 注册 是否 成功.
|
||||
*/
|
||||
module.exports = async (data) => {
|
||||
const {account, password} = data
|
||||
const salt = app.components.encrypt.getRandomSalt()
|
||||
const md5 = app.components.encrypt.cryptPwd(password, salt)
|
||||
await app.db.table("User").data({account, password: md5, salt}).save()
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user