提交 08749bcb authored 作者: vipcxj's avatar vipcxj

1.修改登录接口,使其更泛用

2.增加认证接口,使登录认证更灵活 3.修改gitignore
上级 bb29d888
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# production # production
/dist /dist
/.idea
# misc # misc
.DS_Store .DS_Store
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<w>anticon</w> <w>anticon</w>
<w>arcfour</w> <w>arcfour</w>
<w>authed</w> <w>authed</w>
<w>auths</w>
<w>dropdown</w> <w>dropdown</w>
<w>infoes</w> <w>infoes</w>
<w>infos</w> <w>infos</w>
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"fastjson_ref_resolver": "latest", "fastjson_ref_resolver": "latest",
"fingerprintjs": "^0.5.3", "fingerprintjs": "^0.5.3",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"lowdb": "^1.0.0",
"moment": "^2.18.1", "moment": "^2.18.1",
"prop-types": "^15.5.10", "prop-types": "^15.5.10",
"react": "^15.6.1", "react": "^15.6.1",
......
...@@ -10,7 +10,17 @@ export default { ...@@ -10,7 +10,17 @@ export default {
reducers: {}, reducers: {},
effects: { effects: {
*login({ payload }, { call, put }) { *login({ payload }, { call, put }) {
const result = yield call(login, payload); const loginRequest = {
type: 'userName',
data: payload.userName,
authRequest: {
type: 'password',
parameters: {
cipher: payload.password,
},
},
};
const result = yield call(login, loginRequest);
const { tokenId, authResponse, remainedAuthRequirements } = result; const { tokenId, authResponse, remainedAuthRequirements } = result;
if (authResponse.status !== 'authed' && authResponse.status !== 'skipped') { if (authResponse.status !== 'authed' && authResponse.status !== 'skipped') {
throw errors.wrongPassword(); throw errors.wrongPassword();
......
import Fingerprint from 'fingerprintjs'; /* eslint-disable no-param-reassign */
/** @module services/login */
import { getDeviceId } from '../utils/device';
import post from '../utils/post'; import post from '../utils/post';
import request from '../utils/request'; import request from '../utils/request';
import { encrypt } from '../utils/helper';
import { getToken } from '../utils/auth';
import config from '../utils/config'; import config from '../utils/config';
/**
* @typedef {Object} TokenInfo
* @property {number} [life]
* @property {boolean} [persist]
* @property {!string} productId
* @property {!string} deviceId
*/
export async function login(payload) { /**
const data = {}; * @typedef {Object} LoginRequest
data.type = payload.type; * @property {!string} type
if (data.type === 'userName') { * @property {string} [data]
data.data = payload.userName; * @property {TokenInfo} [tokenInfo]
} * @property {AuthRequest} [authRequest]
if (payload.authType === 'password') { */
data.authRequest = {
type: payload.authType, /**
parameters: { * @typedef {Object} AuthRequest
cipher: payload.password, * @property {!string} type
}, * @property {Object} [parameters]
*/
/**
* @typedef {Object} LoginResponse
* @property {!string} tokenId
* @property {?AuthResponse} authResponse
* @property {!AuthRequirements} remainedAuthRequirements
*/
/**
* @typedef {Object} AuthResponse
* @property {!string} type
* @property {!string} status
* @property {?Object} data
*/
/**
* @typedef {Object} AuthRequirements
* @property {Array.<AuthRequirement>} requirements
*/
/**
* @typedef {Object} AuthRequirement
* @property {Array.<string>} authTypes
*/
/**
* 登录
* @param {!LoginRequest} loginRequest 登录请求
* @returns {Promise.<LoginResponse>}
*/
export async function login(loginRequest) {
if (!loginRequest.tokenInfo) {
loginRequest.tokenInfo = {
productId: config.productId,
deviceId: `${getDeviceId()}`,
}; };
} }
data.tokenInfo = { return post(`${config.apiContextPath}/api/auth/login`, loginRequest, {}, {}, false);
productId: 'big-machine-web-front', }
deviceId: `${new Fingerprint({ ie_activex: true }).get()}`,
}; /**
return post(`${config.apiContextPath}/api/auth/login`, data, {}, {}, false); * 认证
* @param {{tkId: ?string, request: AuthRequest}} authRequest 认证请求
* @return {Promise.<AuthResponse>}
*/
export async function authorize(authRequest) {
if (!authRequest.tkId) {
authRequest.tkId = encrypt(await getToken());
}
return post(`${config.apiContextPath}/api/auth/authorize`, authRequest, {}, {}, false);
} }
export async function userInfo() { export async function userInfo() {
......
...@@ -45,6 +45,7 @@ const config = { ...@@ -45,6 +45,7 @@ const config = {
logo: `${_contextPath}/logo.png`, logo: `${_contextPath}/logo.png`,
contextPath: _contextPath, contextPath: _contextPath,
apiContextPath: _apiContextPath, apiContextPath: _apiContextPath,
productId: 'big-machine-web-front',
defaultDateFormat, defaultDateFormat,
defaultTimeFormat, defaultTimeFormat,
defaultDateTimeFormat, defaultDateTimeFormat,
......
import low from 'lowdb';
import LocalStorage from 'lowdb/adapters/LocalStorage';
const adapter = new LocalStorage('db');
export default low(adapter);
import Fingerprint from 'fingerprintjs';
export function getDeviceId() {
// noinspection JSUnresolvedFunction
return new Fingerprint({ ie_activex: true }).get();
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论