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

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

2.增加认证接口,使登录认证更灵活 3.修改gitignore
上级 bb29d888
......@@ -5,6 +5,7 @@
# production
/dist
/.idea
# misc
.DS_Store
......
......@@ -5,6 +5,7 @@
<w>anticon</w>
<w>arcfour</w>
<w>authed</w>
<w>auths</w>
<w>dropdown</w>
<w>infoes</w>
<w>infos</w>
......
......@@ -22,6 +22,7 @@
"fastjson_ref_resolver": "latest",
"fingerprintjs": "^0.5.3",
"lodash": "^4.17.4",
"lowdb": "^1.0.0",
"moment": "^2.18.1",
"prop-types": "^15.5.10",
"react": "^15.6.1",
......
......@@ -10,7 +10,17 @@ export default {
reducers: {},
effects: {
*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;
if (authResponse.status !== 'authed' && authResponse.status !== 'skipped') {
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 request from '../utils/request';
import { encrypt } from '../utils/helper';
import { getToken } from '../utils/auth';
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 = {};
data.type = payload.type;
if (data.type === 'userName') {
data.data = payload.userName;
}
if (payload.authType === 'password') {
data.authRequest = {
type: payload.authType,
parameters: {
cipher: payload.password,
},
/**
* @typedef {Object} LoginRequest
* @property {!string} type
* @property {string} [data]
* @property {TokenInfo} [tokenInfo]
* @property {AuthRequest} [authRequest]
*/
/**
* @typedef {Object} AuthRequest
* @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 = {
productId: 'big-machine-web-front',
deviceId: `${new Fingerprint({ ie_activex: true }).get()}`,
};
return post(`${config.apiContextPath}/api/auth/login`, data, {}, {}, false);
return post(`${config.apiContextPath}/api/auth/login`, loginRequest, {}, {}, 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() {
......
......@@ -45,6 +45,7 @@ const config = {
logo: `${_contextPath}/logo.png`,
contextPath: _contextPath,
apiContextPath: _apiContextPath,
productId: 'big-machine-web-front',
defaultDateFormat,
defaultTimeFormat,
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论