mirror of
https://github.com/YMFE/yapi.git
synced 2025-02-23 13:59:28 +08:00
t puMerge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
9b6ac607f3
@ -1,7 +1,9 @@
|
||||
import LoginRedux from './reducer/Login/Login_redux.js'
|
||||
import group from './reducer/group/group.js'
|
||||
import Interface from './reducer/interface/interface.js'
|
||||
|
||||
export default {
|
||||
group,
|
||||
LoginRedux,
|
||||
group
|
||||
Interface,
|
||||
}
|
||||
|
6
client/actionTypes.js
Normal file
6
client/actionTypes.js
Normal file
@ -0,0 +1,6 @@
|
||||
// Interface
|
||||
export const FETCH_INTERFACE_DATA = 'FETCH_INTERFACE_DATA';
|
||||
|
||||
// Home
|
||||
export const FETCH_HOME_DATA = 'FETCH_INTERFACE_DATA';
|
||||
|
33
client/actions/interface.js
Normal file
33
client/actions/interface.js
Normal file
@ -0,0 +1,33 @@
|
||||
import {
|
||||
FETCH_INTERFACE_DATA,
|
||||
} from '../actionTypes.js';
|
||||
|
||||
export function fetchAuditIcons () {
|
||||
const data = [{
|
||||
key: '1',
|
||||
name: 'John Brown',
|
||||
age: 32,
|
||||
address: 'New York No. 1 Lake Park',
|
||||
date: '2015-11-11 13:00:15',
|
||||
features: '3',
|
||||
}, {
|
||||
key: '2',
|
||||
name: 'Jim Green',
|
||||
age: 42,
|
||||
address: 'London No. 1 Lake Park',
|
||||
date: '2015-11-11 13:00:15',
|
||||
features: '3',
|
||||
}, {
|
||||
key: '3',
|
||||
name: 'Joe Black',
|
||||
age: 32,
|
||||
address: 'Sidney No. 1 Lake Park',
|
||||
date: '2015-11-11 13:00:15',
|
||||
features: '3',
|
||||
}]
|
||||
|
||||
return {
|
||||
type: FETCH_INTERFACE_DATA,
|
||||
payload: data,
|
||||
};
|
||||
}
|
45
client/containers/Interface/Interface.js
Normal file
45
client/containers/Interface/Interface.js
Normal file
@ -0,0 +1,45 @@
|
||||
import './Interface.scss'
|
||||
import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
import InterfaceList from './InterfaceList/InterfaceList.js'
|
||||
import InterfaceTable from './InterfaceTable/InterfaceTable.js'
|
||||
import { fetchAuditIcons } from '../../actions/interface.js'
|
||||
|
||||
@connect(
|
||||
state => {
|
||||
return {
|
||||
interfaceData: state.data,
|
||||
}
|
||||
},
|
||||
{
|
||||
fetchAuditIcons,
|
||||
}
|
||||
)
|
||||
|
||||
class Interface extends Component {
|
||||
static propTypes = {
|
||||
fetchAuditIcons: PropTypes.func,
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
componentWillMount () {
|
||||
this.props.fetchAuditIcons()
|
||||
}
|
||||
|
||||
render () {
|
||||
const data = this.props.fetchAuditIcons().payload
|
||||
|
||||
return (
|
||||
<section className="interface-box">
|
||||
<InterfaceList />
|
||||
<InterfaceTable data={data} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Interface
|
38
client/containers/Interface/Interface.scss
Normal file
38
client/containers/Interface/Interface.scss
Normal file
@ -0,0 +1,38 @@
|
||||
/* .interface-box.css */
|
||||
.interface-box {
|
||||
max-width: 11rem;
|
||||
display: -webkit-box;
|
||||
-webkit-box-flex: 1;
|
||||
margin: 15px auto 0 auto;
|
||||
font-size: 0.14rem;
|
||||
|
||||
.interface-list {
|
||||
width: 216px;
|
||||
line-height: 45px;
|
||||
background: #f9fafe;
|
||||
|
||||
li {
|
||||
padding: 0 0 0 30px;
|
||||
color: #344562;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover, &.active {
|
||||
background: #657289;
|
||||
color: #FFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.interface-table {
|
||||
-webkit-box-flex: 1;
|
||||
margin: 0 0 0 20px;
|
||||
|
||||
.ant-table-wrapper table {
|
||||
font-size: .14rem;
|
||||
|
||||
button {
|
||||
margin: 0 10px 0 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
client/containers/Interface/InterfaceList/InterfaceList.js
Normal file
18
client/containers/Interface/InterfaceList/InterfaceList.js
Normal file
@ -0,0 +1,18 @@
|
||||
import React, { Component } from 'react'
|
||||
|
||||
class InterfaceList extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<ul className="interface-list">
|
||||
<li className="active">添加接口</li>
|
||||
<li>管理项目成员</li>
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default InterfaceList
|
55
client/containers/Interface/InterfaceTable/InterfaceTable.js
Normal file
55
client/containers/Interface/InterfaceTable/InterfaceTable.js
Normal file
@ -0,0 +1,55 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Table, Button } from 'antd'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
class InterfaceTable extends Component {
|
||||
static propTypes = {
|
||||
data: PropTypes.array,
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
render () {
|
||||
const columns = [{
|
||||
title: '接口名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
}, {
|
||||
title: '接口URL',
|
||||
dataIndex: 'age',
|
||||
key: 'age',
|
||||
}, {
|
||||
title: '操作者',
|
||||
dataIndex: 'address',
|
||||
key: 'address',
|
||||
}, {
|
||||
title: '更新日期',
|
||||
dataIndex: 'date',
|
||||
key: 'date',
|
||||
}, {
|
||||
title: '功能',
|
||||
'key': 'action',
|
||||
render: () => {
|
||||
return (
|
||||
<span>
|
||||
<Button type="primary">Primary</Button>
|
||||
<Button type="primary">Primary</Button>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
}]
|
||||
|
||||
const data = this.props.data;
|
||||
console.log(this.props.data)
|
||||
|
||||
return (
|
||||
<section className="interface-table">
|
||||
<Table columns={columns} dataSource={data} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default InterfaceTable
|
@ -1,24 +0,0 @@
|
||||
import { connect } from 'react-redux'
|
||||
import Login from './Login.js'
|
||||
|
||||
// Action
|
||||
const increaseAction = { type: 'increase' }
|
||||
|
||||
function mapStateToProps() {
|
||||
return {
|
||||
per: '测试数据'
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
onIncreaseClick: () => dispatch(increaseAction)
|
||||
}
|
||||
}
|
||||
|
||||
const App = connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(Login)
|
||||
|
||||
export default App
|
@ -1,9 +1,11 @@
|
||||
import Home from './Home/Home.js'
|
||||
import Login from './Login/Login.js'
|
||||
import ProjectGroups from './ProjectGroups/ProjectGroups.js'
|
||||
import Interface from './Interface/Interface.js'
|
||||
|
||||
export {
|
||||
Home,
|
||||
Login,
|
||||
ProjectGroups,
|
||||
Interface,
|
||||
}
|
||||
|
16
client/reducer/interface/interface.js
Normal file
16
client/reducer/interface/interface.js
Normal file
@ -0,0 +1,16 @@
|
||||
import {
|
||||
FETCH_INTERFACE_DATA,
|
||||
} from '../../actionTypes.js'
|
||||
|
||||
export default (state = 3333, action) => {
|
||||
switch (action.type) {
|
||||
case FETCH_INTERFACE_DATA: {
|
||||
return {
|
||||
...state,
|
||||
icons: action.payload.data,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import { Route, HashRouter } from 'react-router-dom'
|
||||
import { Home, Login, ProjectGroups } from './containers/index'
|
||||
import { Home, Login, ProjectGroups, Interface } from './containers/index'
|
||||
|
||||
export default () => {
|
||||
return (
|
||||
@ -9,6 +9,7 @@ export default () => {
|
||||
<Route path="/" component={ Home } />
|
||||
<Route path="/Login" component={ Login } />
|
||||
<Route path="/ProjectGroups" component={ ProjectGroups } />
|
||||
<Route path="/Interface" component={ Interface } />
|
||||
</div>
|
||||
</HashRouter>
|
||||
)
|
||||
|
@ -2,7 +2,8 @@
|
||||
@import '~antd/dist/antd.css';
|
||||
|
||||
html {
|
||||
font-size:625%
|
||||
font-size:625%;
|
||||
background: #f1f3f6;
|
||||
}
|
||||
html, body {
|
||||
font-family: tahoma, 'Microsoft Yahei';
|
||||
|
832
doc/build/api.html
vendored
832
doc/build/api.html
vendored
@ -93,8 +93,35 @@
|
||||
|
||||
<a href="#user">user</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<ul class="nav docs-sidenav-extend" >
|
||||
|
||||
<li >
|
||||
<a href="#-user-login">/user/login</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-logout">/user/logout</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-reg">/user/reg</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-list">/user/list</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-list">/user/list</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-del">/user/del</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- <li > -->
|
||||
<li >
|
||||
|
||||
@ -138,14 +165,27 @@
|
||||
|
||||
<a href="#interface">interface</a>
|
||||
</li>
|
||||
|
||||
|
||||
<ul class="nav docs-sidenav-extend" >
|
||||
|
||||
<li >
|
||||
|
||||
<a href="#-interface-add">/interface/add</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-interface-get">/interface/get</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-interface-list">/interface/list</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-interface-up">/interface/up</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-interface-del">/interface/del</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
@ -178,7 +218,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#12" target="_blank">./server/controllers/group.js:12</a>
|
||||
<a href="./static/server/controllers/group.js.html#13" target="_blank">./server/controllers/group.js:13</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -261,7 +301,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#51" target="_blank">./server/controllers/group.js:51</a>
|
||||
<a href="./static/server/controllers/group.js.html#52" target="_blank">./server/controllers/group.js:52</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -323,7 +363,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#71" target="_blank">./server/controllers/group.js:71</a>
|
||||
<a href="./static/server/controllers/group.js.html#72" target="_blank">./server/controllers/group.js:72</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -395,7 +435,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#93" target="_blank">./server/controllers/group.js:93</a>
|
||||
<a href="./static/server/controllers/group.js.html#103" target="_blank">./server/controllers/group.js:103</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -477,6 +517,371 @@
|
||||
|
||||
<h2 id="user" class="page-header subject">user<a class="hashlink" href="#user">#</a></h2>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-login" class="page-header subject">
|
||||
/user/login
|
||||
|
||||
<span class="ui-badge">POST</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-login">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
用户登录接口
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#11" target="_blank">./server/controllers/user.js:11</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
<div class="docs-table">
|
||||
<table class="yo-table yo-table-border">
|
||||
<colgroup>
|
||||
<col class="c1">
|
||||
<col class="c2">
|
||||
<col class="c3">
|
||||
<col class="c4">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="active">
|
||||
<th>参数名</th>
|
||||
<th>类型</th>
|
||||
<th>描述</th>
|
||||
<th>必选</th>
|
||||
<th>支持版本</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>email</td>
|
||||
<td>String</td>
|
||||
<td>email名称,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>password</td>
|
||||
<td>String</td>
|
||||
<td>密码,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div>示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
|
||||
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"logout success..."</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">101</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"email"</span><span class="token punctuation">:</span> <span class="token string">"admin@admin.com"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1499762848</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1499762848</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-logout" class="page-header subject">
|
||||
/user/logout
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-logout">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
退出登录接口
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#62" target="_blank">./server/controllers/user.js:62</a>
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
<div>示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
|
||||
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"success"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token string">"ok"</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-reg" class="page-header subject">
|
||||
/user/reg
|
||||
|
||||
<span class="ui-badge">POST</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-reg">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
用户注册接口
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#79" target="_blank">./server/controllers/user.js:79</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
<div class="docs-table">
|
||||
<table class="yo-table yo-table-border">
|
||||
<colgroup>
|
||||
<col class="c1">
|
||||
<col class="c2">
|
||||
<col class="c3">
|
||||
<col class="c4">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="active">
|
||||
<th>参数名</th>
|
||||
<th>类型</th>
|
||||
<th>描述</th>
|
||||
<th>必选</th>
|
||||
<th>支持版本</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>email</td>
|
||||
<td>String</td>
|
||||
<td>email名称,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>password</td>
|
||||
<td>String</td>
|
||||
<td>密码,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>username</td>
|
||||
<td>String</td>
|
||||
<td>用户名</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div>示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
|
||||
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"logout success..."</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">101</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"email"</span><span class="token punctuation">:</span> <span class="token string">"admin@admin.com"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1499762848</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1499762848</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-list" class="page-header subject">
|
||||
/user/list
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-list">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
获取用户列表
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#136" target="_blank">./server/controllers/user.js:136</a>
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-list" class="page-header subject">
|
||||
/user/list
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-list">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
获取用户列表
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#159" target="_blank">./server/controllers/user.js:159</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
<div class="docs-table">
|
||||
<table class="yo-table yo-table-border">
|
||||
<colgroup>
|
||||
<col class="c1">
|
||||
<col class="c2">
|
||||
<col class="c3">
|
||||
<col class="c4">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="active">
|
||||
<th>参数名</th>
|
||||
<th>类型</th>
|
||||
<th>描述</th>
|
||||
<th>必选</th>
|
||||
<th>支持版本</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td></td>
|
||||
<td>用户uid</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-del" class="page-header subject">
|
||||
/user/del
|
||||
|
||||
<span class="ui-badge">POST</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-del">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
获取用户列表,只有admin用户才有此权限
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#184" target="_blank">./server/controllers/user.js:184</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
<div class="docs-table">
|
||||
<table class="yo-table yo-table-border">
|
||||
<colgroup>
|
||||
<col class="c1">
|
||||
<col class="c2">
|
||||
<col class="c3">
|
||||
<col class="c4">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="active">
|
||||
<th>参数名</th>
|
||||
<th>类型</th>
|
||||
<th>描述</th>
|
||||
<th>必选</th>
|
||||
<th>支持版本</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td></td>
|
||||
<td>用户uid</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<h2 id="project" class="page-header subject">project<a class="hashlink" href="#project">#</a></h2>
|
||||
|
||||
@ -498,7 +903,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#11" target="_blank">./server/controllers/project.js:11</a>
|
||||
<a href="./static/server/controllers/project.js.html#12" target="_blank">./server/controllers/project.js:12</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -627,7 +1032,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#73" target="_blank">./server/controllers/project.js:73</a>
|
||||
<a href="./static/server/controllers/project.js.html#74" target="_blank">./server/controllers/project.js:74</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -711,7 +1116,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#105" target="_blank">./server/controllers/project.js:105</a>
|
||||
<a href="./static/server/controllers/project.js.html#106" target="_blank">./server/controllers/project.js:106</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -795,7 +1200,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#137" target="_blank">./server/controllers/project.js:137</a>
|
||||
<a href="./static/server/controllers/project.js.html#138" target="_blank">./server/controllers/project.js:138</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -878,7 +1283,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#161" target="_blank">./server/controllers/project.js:161</a>
|
||||
<a href="./static/server/controllers/project.js.html#162" target="_blank">./server/controllers/project.js:162</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -978,7 +1383,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#185" target="_blank">./server/controllers/project.js:185</a>
|
||||
<a href="./static/server/controllers/project.js.html#186" target="_blank">./server/controllers/project.js:186</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1050,7 +1455,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#212" target="_blank">./server/controllers/project.js:212</a>
|
||||
<a href="./static/server/controllers/project.js.html#219" target="_blank">./server/controllers/project.js:219</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1482,18 +1887,15 @@
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<h2 id="user" class="page-header subject">user<a class="hashlink" href="#user">#</a></h2>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-login" class="page-header subject">
|
||||
/user/login
|
||||
<h3 id="-interface-get" class="page-header subject">
|
||||
/interface/get
|
||||
|
||||
<span class="ui-badge">POST</span>
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-login">#</a>
|
||||
<a class="hashlink" href="#-interface-get">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
@ -1501,6 +1903,12 @@
|
||||
添加项目分组
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#77" target="_blank">./server/controllers/interface.js:77</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
@ -1523,21 +1931,9 @@
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>username</td>
|
||||
<td>String</td>
|
||||
<td>用户名称,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>password</td>
|
||||
<td>String</td>
|
||||
<td>密码,不能为空</td>
|
||||
<td>id</td>
|
||||
<td>Number</td>
|
||||
<td>接口id,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
@ -1550,14 +1946,366 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div>返回示例:</div>
|
||||
<div>示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">.</span><span class="token operator">/</span>api<span class="token operator">/</span><span class="token keyword">interface</span><span class="token operator">/</span><span class="token keyword">get</span><span class="token punctuation">.</span>json</code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-interface-list" class="page-header subject">
|
||||
/interface/list
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-interface-list">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
添加项目分组
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#100" target="_blank">./server/controllers/interface.js:100</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
<div class="docs-table">
|
||||
<table class="yo-table yo-table-border">
|
||||
<colgroup>
|
||||
<col class="c1">
|
||||
<col class="c2">
|
||||
<col class="c3">
|
||||
<col class="c4">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="active">
|
||||
<th>参数名</th>
|
||||
<th>类型</th>
|
||||
<th>描述</th>
|
||||
<th>必选</th>
|
||||
<th>支持版本</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>project_id</td>
|
||||
<td>Number</td>
|
||||
<td>项目id,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div>示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">.</span><span class="token operator">/</span>api<span class="token operator">/</span><span class="token keyword">interface</span><span class="token operator">/</span>list<span class="token punctuation">.</span>json</code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-interface-up" class="page-header subject">
|
||||
/interface/up
|
||||
|
||||
<span class="ui-badge">POST</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-interface-up">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
添加项目分组
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#124" target="_blank">./server/controllers/interface.js:124</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
<div class="docs-table">
|
||||
<table class="yo-table yo-table-border">
|
||||
<colgroup>
|
||||
<col class="c1">
|
||||
<col class="c2">
|
||||
<col class="c3">
|
||||
<col class="c4">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="active">
|
||||
<th>参数名</th>
|
||||
<th>类型</th>
|
||||
<th>描述</th>
|
||||
<th>必选</th>
|
||||
<th>支持版本</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td>Number</td>
|
||||
<td>接口id,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>path</td>
|
||||
<td>String</td>
|
||||
<td>接口请求路径</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>method</td>
|
||||
<td>String</td>
|
||||
<td>请求方式</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_headers</td>
|
||||
<td>Array</td>
|
||||
<td>请求的header信息</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_headers[].name</td>
|
||||
<td>String</td>
|
||||
<td>请求的header信息名</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_headers[].value</td>
|
||||
<td>String</td>
|
||||
<td>请求的header信息值</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_headers[].required</td>
|
||||
<td>Boolean</td>
|
||||
<td>是否是必须,默认为否</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_headers[].desc</td>
|
||||
<td>String</td>
|
||||
<td>header描述</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params_type</td>
|
||||
<td>String</td>
|
||||
<td>请求参数方式,有["form", "json", "text", "xml"]四种</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params</td>
|
||||
<td>Mixed</td>
|
||||
<td>请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].name</td>
|
||||
<td>String</td>
|
||||
<td>请求参数名</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].value</td>
|
||||
<td>String</td>
|
||||
<td>请求参数值,可填写生成规则(mock)。如@email,随机生成一条email</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>req_params[].type</td>
|
||||
<td>String</td>
|
||||
<td>请求参数类型,有["text", "file"]两种</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>res_body_type</td>
|
||||
<td>String</td>
|
||||
<td>相应信息的数据格式,有["json", "text", "xml"]三种</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>res_body</td>
|
||||
<td>String</td>
|
||||
<td>响应信息,可填写任意字符串,如果res_body_type是json,则会调用mock功能</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>desc</td>
|
||||
<td>String</td>
|
||||
<td>接口描述</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div>示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
|
||||
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"success"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"username"</span><span class="token punctuation">:</span> <span class="token string">"testuser"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"password"</span><span class="token punctuation">:</span> <span class="token string">"testpassword"</span>
|
||||
<span class="token string">"n"</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"nModified"</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"ok"</span><span class="token punctuation">:</span> <span class="token number">1</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-interface-del" class="page-header subject">
|
||||
/interface/del
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-interface-del">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
删除接口
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/interface.js.html#189" target="_blank">./server/controllers/interface.js:189</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<small class="text-muted">参数:</small>
|
||||
</p>
|
||||
<div class="docs-table">
|
||||
<table class="yo-table yo-table-border">
|
||||
<colgroup>
|
||||
<col class="c1">
|
||||
<col class="c2">
|
||||
<col class="c3">
|
||||
<col class="c4">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="active">
|
||||
<th>参数名</th>
|
||||
<th>类型</th>
|
||||
<th>描述</th>
|
||||
<th>必选</th>
|
||||
<th>支持版本</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td>Number</td>
|
||||
<td>接口id,不能为空</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div>示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
|
||||
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"success"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"n"</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"ok"</span><span class="token punctuation">:</span> <span class="token number">1</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
60
doc/build/static/server/controllers/base.js.html
vendored
60
doc/build/static/server/controllers/base.js.html
vendored
@ -27,27 +27,65 @@
|
||||
<pre class="brush: js;">
|
||||
import yapi from '../yapi.js'
|
||||
import projectModel from '../models/project.js'
|
||||
import userModel from '../models/user.js'
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
|
||||
class baseController{
|
||||
constructor(ctx){
|
||||
console.log('baseControler init...')
|
||||
|
||||
//网站上线后,role对象key是不能修改的,value可以修改
|
||||
this.roles = {
|
||||
admin: 'Admin',
|
||||
member: '网站会员'
|
||||
}
|
||||
}
|
||||
|
||||
getUid(){
|
||||
return 0
|
||||
async init(ctx){
|
||||
this.$user = null;
|
||||
if(ctx.path === '/user/login' || ctx.path === '/user/reg' || ctx.path === '/user/status' || ctx.path === '/user/logout'){
|
||||
this.$auth = true;
|
||||
}else{
|
||||
await this.checkLogin(ctx)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getLoginStatus(){
|
||||
// let token = getCookie('_yapi_token');
|
||||
// let uid = getCookie('_yapi_uid');
|
||||
// let usermodel
|
||||
getUid(ctx){
|
||||
return this.$uid;
|
||||
}
|
||||
|
||||
async checkLogin(ctx){
|
||||
let token = ctx.cookies.get('_yapi_token');
|
||||
let uid = ctx.cookies.get('_yapi_uid');
|
||||
try{
|
||||
if(!token || !uid) return false;
|
||||
let userInst = yapi.getInst(userModel); //创建user实体
|
||||
let result = await userInst.findById(uid);
|
||||
let decoded = jwt.verify(token, result.passsalt)
|
||||
if(decoded.uid == uid){
|
||||
this.$uid = uid;
|
||||
this.$auth = true;
|
||||
this.$user = result;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}catch(e){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async getLoginStatus(ctx){
|
||||
if(await this.checkLogin(ctx) === true){
|
||||
return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user,['_id','username','email', 'up_time', 'add_time']));
|
||||
}
|
||||
return ctx.body = yapi.commons.resReturn(null, 300 , 'Please login.');
|
||||
|
||||
// usermode.token === token
|
||||
// return true
|
||||
return true
|
||||
}
|
||||
|
||||
getRole(){
|
||||
return 'admin'
|
||||
return this.$user.role;
|
||||
}
|
||||
|
||||
async jungeProjectAuth(id){
|
||||
|
@ -28,6 +28,7 @@
|
||||
import groupModel from '../models/group.js'
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import projectModel from '../models/project.js'
|
||||
|
||||
//
|
||||
class groupController extends baseController{
|
||||
@ -110,7 +111,16 @@ class groupController extends baseController{
|
||||
async del(ctx){
|
||||
try{
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
let id = ctx.request.body.id;
|
||||
var projectInst = yapi.getInst(projectModel);
|
||||
let id = ctx.request.body.id;
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'id不能为空');
|
||||
}
|
||||
let count = projectInst.countByGroupId(id);
|
||||
if(count > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 403, '请先删除该分组下的项目');
|
||||
}
|
||||
|
||||
let result = await groupInst.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
|
@ -102,6 +102,16 @@ class interfaceController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/get
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/get.json
|
||||
*/
|
||||
async get(ctx){
|
||||
let params = ctx.request.query;
|
||||
if(!params.id){
|
||||
@ -115,6 +125,17 @@ class interfaceController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/list
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} project_id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/list.json
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
let project_id = ctx.request.query.project_id;
|
||||
if(!project_id){
|
||||
@ -128,6 +149,32 @@ class interfaceController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/up
|
||||
* @method POST
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @param {String} [path] 接口请求路径
|
||||
* @param {String} [method] 请求方式
|
||||
* @param {Array} [req_headers] 请求的header信息
|
||||
* @param {String} [req_headers[].name] 请求的header信息名
|
||||
* @param {String} [req_headers[].value] 请求的header信息值
|
||||
* @param {Boolean} [req_headers[].required] 是否是必须,默认为否
|
||||
* @param {String} [req_headers[].desc] header描述
|
||||
* @param {String} [req_params_type] 请求参数方式,有["form", "json", "text", "xml"]四种
|
||||
* @param {Mixed} [req_params] 请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串
|
||||
* @param {String} [req_params[].name] 请求参数名
|
||||
* @param {String} [req_params[].value] 请求参数值,可填写生成规则(mock)。如@email,随机生成一条email
|
||||
* @param {String} [req_params[].type] 请求参数类型,有["text", "file"]两种
|
||||
* @param {String} [res_body_type] 相应信息的数据格式,有["json", "text", "xml"]三种
|
||||
* @param {String} [res_body] 响应信息,可填写任意字符串,如果res_body_type是json,则会调用mock功能
|
||||
* @param {String} [desc] 接口描述
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/up.json
|
||||
*/
|
||||
|
||||
async up(ctx){
|
||||
let params = ctx.request.body;
|
||||
params.method = params.method || 'GET';
|
||||
@ -167,15 +214,34 @@ class interfaceController extends baseController{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口
|
||||
* @interface /interface/del
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/del.json
|
||||
*/
|
||||
|
||||
async del(ctx){
|
||||
try{
|
||||
let id = ctx.request.body.id;
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
if(await this.jungeMemberAuth(id) !== true){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
|
||||
let data = await this.Model.get(params.id);
|
||||
|
||||
if(data.uid != this.getUid()){
|
||||
if(await this.jungeProjectAuth(data.project_id) !== true){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let result = await this.Model.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
|
@ -28,6 +28,7 @@
|
||||
import projectModel from '../models/project.js'
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import interfaceModel from '../models/interface.js'
|
||||
|
||||
class projectController extends baseController {
|
||||
|
||||
@ -227,11 +228,17 @@ class projectController extends baseController {
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
let interfaceInst = yapi.getInst(interfaceModel);
|
||||
let count = await interfaceInst.countByProjectId(id);
|
||||
if(count > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '请先删除该项目下所有接口');
|
||||
}
|
||||
|
||||
if(await this.jungeProjectAuth(id) !== true){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
let result = await this.Model.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
}
|
||||
|
202
doc/build/static/server/controllers/user.js.html
vendored
202
doc/build/static/server/controllers/user.js.html
vendored
@ -30,101 +30,151 @@ import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
const sha1 = require('sha1');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
class userController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
console.log('constructor...')
|
||||
}
|
||||
/**
|
||||
* 添加项目分组
|
||||
* 用户登录接口
|
||||
* @interface /user/login
|
||||
* @method POST
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} username 用户名称,不能为空
|
||||
* @param {String} email email名称,不能为空
|
||||
* @param {String} password 密码,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/user/login.json
|
||||
*/
|
||||
async login(ctx){ //登录
|
||||
var userInst = yapi.getInst(userModel); //创建user实体
|
||||
let username = ctx.request.body.username;
|
||||
let userInst = yapi.getInst(userModel); //创建user实体
|
||||
let email = ctx.request.body.email;
|
||||
let password = ctx.request.body.password;
|
||||
let result = await userInst.findByName(username);
|
||||
console.log(password)
|
||||
|
||||
|
||||
|
||||
userInst.save(function(error){
|
||||
console.log(111)
|
||||
var error = userInst.validateSync();
|
||||
assert.equal(error.errors['password'].message, 'password required');
|
||||
});
|
||||
|
||||
if(!username){
|
||||
return ctx.body = yapi.commons.resReturn(null,400,'用户名不能为空');
|
||||
if(!email){
|
||||
return ctx.body = yapi.commons.resReturn(null,400,'email不能为空');
|
||||
}
|
||||
// if(!password){
|
||||
// return ctx.body = yapi.commons.resReturn(null,400,'密码不能为空');
|
||||
// }
|
||||
//输入一个不存在的用户名
|
||||
var checkRepeat = await userInst.checkRepeat(username);//然后检查是否已经存在该用户
|
||||
if(checkRepeat==0){
|
||||
return ctx.body = yapi.commons.resReturn(null,404,'该用户不存在'); //返回的错误码对吗????
|
||||
}else if(sha1(result.password)===password){ //用户名存在,判断密码是否正确,正确则可以登录
|
||||
console.log('密码一致'); //是不是还需要把用户名密码一些东西写到session
|
||||
// setCookie('token', sha1(username+password));
|
||||
// userInst.update({_id, result._id}, {token: sha1(username+password)})
|
||||
// return ctx.body = {username: ''}
|
||||
return ctx.body = yapi.commons.resReturn(null,200,'ok');
|
||||
if(!password){
|
||||
return ctx.body = yapi.commons.resReturn(null,400,'密码不能为空');
|
||||
}
|
||||
|
||||
let result = await userInst.findByEmail(email);
|
||||
|
||||
|
||||
if(!result){
|
||||
return ctx.body = yapi.commons.resReturn(null,404,'该用户不存在');
|
||||
}else if(yapi.commons.generatePassword(password, result.passsalt) === result.password){
|
||||
let token = jwt.sign({uid: result._id},result.passsalt,{expiresIn: '7 days'});
|
||||
ctx.cookies.set('_yapi_token', token, {
|
||||
expires: yapi.commons.expireDate(7),
|
||||
httpOnly: true
|
||||
})
|
||||
ctx.cookies.set('_yapi_uid', result._id, {
|
||||
expires: yapi.commons.expireDate(7),
|
||||
httpOnly: true
|
||||
})
|
||||
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
uid: result._id,
|
||||
email: result.email,
|
||||
add_time: result.add_time,
|
||||
up_time: result.up_time
|
||||
|
||||
}, 0, 'logout success...');
|
||||
}else{
|
||||
return ctx.body = yapi.commons.resReturn(null,400,'密码错误');
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '密码错误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录接口
|
||||
* @interface /user/logout
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example ./api/user/logout.json
|
||||
*/
|
||||
|
||||
async logout(ctx){
|
||||
ctx.cookies.set('_yapi_token', null);
|
||||
ctx.cookies.set('_yapi_uid', null);
|
||||
ctx.body = yapi.commons.resReturn('ok');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
* @interface /user/reg
|
||||
* @method POST
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} email email名称,不能为空
|
||||
* @param {String} password 密码,不能为空
|
||||
* @param {String} [username] 用户名
|
||||
* @returns {Object}
|
||||
* @example ./api/user/login.json
|
||||
*/
|
||||
async reg(ctx){ //注册
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
|
||||
// if(!params.username){
|
||||
// return ctx.body = yapi.commons.resReturn(null,400,'用户名不能为空');
|
||||
// }
|
||||
// if(!params.password){
|
||||
// return ctx.body = yapi.commons.resReturn(null,400,'密码不能为空');
|
||||
// }
|
||||
// if(!params.email){
|
||||
// return ctx.body = yapi.commons.resReturn(null,400,'邮箱不能为空');
|
||||
// }
|
||||
|
||||
// var checkRepeat = await userInst.checkRepeat(params.username);//然后检查是否已经存在该用户
|
||||
// if(checkRepeat>0){
|
||||
// return ctx.body = yapi.commons.resReturn(null,401,'该用户名已经注册');
|
||||
// }
|
||||
// var checkRepeat = await userInst.checkRepeat(params.email);//然后检查是否已经存在该用户
|
||||
// if(checkRepeat>0){
|
||||
// return ctx.body = yapi.commons.resReturn(null,401,'该邮箱已经注册');
|
||||
// }
|
||||
|
||||
if(!params.email){
|
||||
return ctx.body = yapi.commons.resReturn(null,400,'邮箱不能为空');
|
||||
}
|
||||
if(!params.password){
|
||||
return ctx.body = yapi.commons.resReturn(null,400,'密码不能为空');
|
||||
}
|
||||
|
||||
var checkRepeat = await userInst.checkRepeat(params.email);//然后检查是否已经存在该用户
|
||||
if(checkRepeat>0){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'该email已经注册');
|
||||
}
|
||||
|
||||
let passsalt = yapi.commons.randStr();
|
||||
let data = {
|
||||
username: params.username,
|
||||
password: sha1(params.password),//加密
|
||||
password: yapi.commons.generatePassword(params.password, passsalt),//加密
|
||||
email: params.email,
|
||||
role: params.role,
|
||||
passsalt: passsalt,
|
||||
role: 'member',
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
try{
|
||||
let user = await userInst.save(data);
|
||||
user = yapi.commons.fieldSelect(user,['id','username','password','email','role'])
|
||||
ctx.body = yapi.commons.resReturn(user);
|
||||
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
uid: user._id,
|
||||
email: user.email,
|
||||
add_time: user.add_time,
|
||||
up_time: user.up_time,
|
||||
role: 'member',
|
||||
});
|
||||
yapi.commons.sendMail({
|
||||
to: params.email,
|
||||
contents: `欢迎注册,您的账号 ${params.email} 已经注册成功`
|
||||
})
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 401, e.message);
|
||||
}
|
||||
}
|
||||
async list(ctx){ //获取用户列表并分页
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @interface /user/list
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.');
|
||||
}
|
||||
var userInst = yapi.getInst(userModel);
|
||||
try{
|
||||
let user = await userInst.list();
|
||||
@ -133,18 +183,47 @@ class userController extends baseController{
|
||||
return ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @interface /user/list
|
||||
* @method GET
|
||||
* @param id 用户uid
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async findById(ctx){ //根据id获取用户信息
|
||||
try{
|
||||
try{
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let id = ctx.request.body.id;
|
||||
if(this.getUid() != id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.');
|
||||
}
|
||||
let result = await userInst.findById(id);
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
return ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表,只有admin用户才有此权限
|
||||
* @interface /user/del
|
||||
* @method POST
|
||||
* @param id 用户uid
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
async del(ctx){ //根据id删除一个用户
|
||||
try{
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.');
|
||||
}
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let id = ctx.request.body.id;
|
||||
let result = await userInst.del(id);
|
||||
@ -153,18 +232,15 @@ class userController extends baseController{
|
||||
ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async update(ctx){ //更新用户信息
|
||||
try{
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let id = ctx.request.body.id;
|
||||
let id = this.getUid();
|
||||
let data ={};
|
||||
ctx.request.body.username && (data.username = ctx.request.body.username)
|
||||
ctx.request.body.password && (data.password = ctx.request.body.password)
|
||||
ctx.request.body.email && (data.email = ctx.request.body.email)
|
||||
ctx.request.body.role && (data.role = ctx.request.body.role)
|
||||
if (Object.keys(data).length===0){
|
||||
ctx.body = yapi.commons.resReturn(null,404,'用户名、密码、Email、role都为空');
|
||||
}
|
||||
let result = await userInst.update(id,data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
|
@ -1,9 +1,10 @@
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "success",
|
||||
"errmsg": "logout success...",
|
||||
"data": {
|
||||
"_id": 4,
|
||||
"username": "testuser",
|
||||
"password": "testpassword"
|
||||
"uid": 101,
|
||||
"email": "admin@admin.com",
|
||||
"add_time": 1499762848,
|
||||
"up_time": 1499762848
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
"description": "YAPI",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build-server": "babel server -d server_dist",
|
||||
"dev-server": "nodemon server_dist/app.js dev",
|
||||
"start": "webpack-dev-server"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -75,6 +75,16 @@ class interfaceController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/get
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/get.json
|
||||
*/
|
||||
async get(ctx){
|
||||
let params = ctx.request.query;
|
||||
if(!params.id){
|
||||
@ -88,6 +98,17 @@ class interfaceController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/list
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} project_id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/list.json
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
let project_id = ctx.request.query.project_id;
|
||||
if(!project_id){
|
||||
@ -101,6 +122,32 @@ class interfaceController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/up
|
||||
* @method POST
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @param {String} [path] 接口请求路径
|
||||
* @param {String} [method] 请求方式
|
||||
* @param {Array} [req_headers] 请求的header信息
|
||||
* @param {String} [req_headers[].name] 请求的header信息名
|
||||
* @param {String} [req_headers[].value] 请求的header信息值
|
||||
* @param {Boolean} [req_headers[].required] 是否是必须,默认为否
|
||||
* @param {String} [req_headers[].desc] header描述
|
||||
* @param {String} [req_params_type] 请求参数方式,有["form", "json", "text", "xml"]四种
|
||||
* @param {Mixed} [req_params] 请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串
|
||||
* @param {String} [req_params[].name] 请求参数名
|
||||
* @param {String} [req_params[].value] 请求参数值,可填写生成规则(mock)。如@email,随机生成一条email
|
||||
* @param {String} [req_params[].type] 请求参数类型,有["text", "file"]两种
|
||||
* @param {String} [res_body_type] 相应信息的数据格式,有["json", "text", "xml"]三种
|
||||
* @param {String} [res_body] 响应信息,可填写任意字符串,如果res_body_type是json,则会调用mock功能
|
||||
* @param {String} [desc] 接口描述
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/up.json
|
||||
*/
|
||||
|
||||
async up(ctx){
|
||||
let params = ctx.request.body;
|
||||
params.method = params.method || 'GET';
|
||||
@ -140,15 +187,34 @@ class interfaceController extends baseController{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口
|
||||
* @interface /interface/del
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/del.json
|
||||
*/
|
||||
|
||||
async del(ctx){
|
||||
try{
|
||||
let id = ctx.request.body.id;
|
||||
let id = ctx.request.body.id;
|
||||
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空');
|
||||
}
|
||||
if(await this.jungeMemberAuth(id) !== true){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
|
||||
let data = await this.Model.get(params.id);
|
||||
|
||||
if(data.uid != this.getUid()){
|
||||
if(await this.jungeProjectAuth(data.project_id) !== true){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let result = await this.Model.del(id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
|
@ -10,12 +10,12 @@ class userController extends baseController{
|
||||
super(ctx)
|
||||
}
|
||||
/**
|
||||
* 添加项目分组
|
||||
* 用户登录接口
|
||||
* @interface /user/login
|
||||
* @method POST
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} username 用户名称,不能为空
|
||||
* @param {String} email email名称,不能为空
|
||||
* @param {String} password 密码,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/user/login.json
|
||||
@ -47,12 +47,29 @@ class userController extends baseController{
|
||||
expires: yapi.commons.expireDate(7),
|
||||
httpOnly: true
|
||||
})
|
||||
return ctx.body = yapi.commons.resReturn(null, 0, 'logout success...');
|
||||
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
uid: result._id,
|
||||
email: result.email,
|
||||
add_time: result.add_time,
|
||||
up_time: result.up_time
|
||||
|
||||
}, 0, 'logout success...');
|
||||
}else{
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '密码错误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录接口
|
||||
* @interface /user/logout
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example ./api/user/logout.json
|
||||
*/
|
||||
|
||||
async logout(ctx){
|
||||
ctx.cookies.set('_yapi_token', null);
|
||||
ctx.cookies.set('_yapi_uid', null);
|
||||
@ -60,7 +77,18 @@ class userController extends baseController{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
* @interface /user/reg
|
||||
* @method POST
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} email email名称,不能为空
|
||||
* @param {String} password 密码,不能为空
|
||||
* @param {String} [username] 用户名
|
||||
* @returns {Object}
|
||||
* @example ./api/user/login.json
|
||||
*/
|
||||
async reg(ctx){ //注册
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
|
||||
@ -88,8 +116,14 @@ class userController extends baseController{
|
||||
}
|
||||
try{
|
||||
let user = await userInst.save(data);
|
||||
user = yapi.commons.fieldSelect(user,['id','username','email'])
|
||||
ctx.body = yapi.commons.resReturn(user);
|
||||
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
uid: user._id,
|
||||
email: user.email,
|
||||
add_time: user.add_time,
|
||||
up_time: user.up_time,
|
||||
role: 'member',
|
||||
});
|
||||
yapi.commons.sendMail({
|
||||
to: params.email,
|
||||
contents: `欢迎注册,您的账号 ${params.email} 已经注册成功`
|
||||
@ -98,7 +132,22 @@ class userController extends baseController{
|
||||
ctx.body = yapi.commons.resReturn(null, 401, e.message);
|
||||
}
|
||||
}
|
||||
async list(ctx){
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @interface /user/list
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.');
|
||||
}
|
||||
var userInst = yapi.getInst(userModel);
|
||||
try{
|
||||
let user = await userInst.list();
|
||||
@ -107,6 +156,18 @@ class userController extends baseController{
|
||||
return ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @interface /user/list
|
||||
* @method GET
|
||||
* @param id 用户uid
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async findById(ctx){ //根据id获取用户信息
|
||||
try{
|
||||
var userInst = yapi.getInst(userModel);
|
||||
@ -120,6 +181,17 @@ class userController extends baseController{
|
||||
return ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表,只有admin用户才有此权限
|
||||
* @interface /user/del
|
||||
* @method POST
|
||||
* @param id 用户uid
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
async del(ctx){ //根据id删除一个用户
|
||||
try{
|
||||
if(this.getRole() !== 'admin'){
|
||||
@ -133,6 +205,8 @@ class userController extends baseController{
|
||||
ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async update(ctx){ //更新用户信息
|
||||
try{
|
||||
var userInst = yapi.getInst(userModel);
|
||||
|
@ -173,6 +173,18 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
return add;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/get
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/get.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'get',
|
||||
value: function () {
|
||||
@ -223,6 +235,18 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
return get;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/list
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} project_id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/list.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
@ -273,6 +297,33 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
return list;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /interface/up
|
||||
* @method POST
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @param {String} [path] 接口请求路径
|
||||
* @param {String} [method] 请求方式
|
||||
* @param {Array} [req_headers] 请求的header信息
|
||||
* @param {String} [req_headers[].name] 请求的header信息名
|
||||
* @param {String} [req_headers[].value] 请求的header信息值
|
||||
* @param {Boolean} [req_headers[].required] 是否是必须,默认为否
|
||||
* @param {String} [req_headers[].desc] header描述
|
||||
* @param {String} [req_params_type] 请求参数方式,有["form", "json", "text", "xml"]四种
|
||||
* @param {Mixed} [req_params] 请求参数,如果请求方式是form,参数是Array数组,其他格式请求参数是字符串
|
||||
* @param {String} [req_params[].name] 请求参数名
|
||||
* @param {String} [req_params[].value] 请求参数值,可填写生成规则(mock)。如@email,随机生成一条email
|
||||
* @param {String} [req_params[].type] 请求参数类型,有["text", "file"]两种
|
||||
* @param {String} [res_body_type] 相应信息的数据格式,有["json", "text", "xml"]三种
|
||||
* @param {String} [res_body] 响应信息,可填写任意字符串,如果res_body_type是json,则会调用mock功能
|
||||
* @param {String} [desc] 接口描述
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/up.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'up',
|
||||
value: function () {
|
||||
@ -361,11 +412,23 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
return up;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 删除接口
|
||||
* @interface /interface/del
|
||||
* @method GET
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 接口id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/interface/del.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'del',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
||||
var id, result;
|
||||
var id, data, result;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
@ -382,41 +445,52 @@ var interfaceController = function (_baseController) {
|
||||
|
||||
case 4:
|
||||
_context5.next = 6;
|
||||
return this.jungeMemberAuth(id);
|
||||
return this.Model.get(params.id);
|
||||
|
||||
case 6:
|
||||
data = _context5.sent;
|
||||
|
||||
if (!(data.uid != this.getUid())) {
|
||||
_context5.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
_context5.next = 10;
|
||||
return this.jungeProjectAuth(data.project_id);
|
||||
|
||||
case 10:
|
||||
_context5.t0 = _context5.sent;
|
||||
|
||||
if (!(_context5.t0 !== true)) {
|
||||
_context5.next = 9;
|
||||
_context5.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 9:
|
||||
_context5.next = 11;
|
||||
case 13:
|
||||
_context5.next = 15;
|
||||
return this.Model.del(id);
|
||||
|
||||
case 11:
|
||||
case 15:
|
||||
result = _context5.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context5.next = 18;
|
||||
_context5.next = 22;
|
||||
break;
|
||||
|
||||
case 15:
|
||||
_context5.prev = 15;
|
||||
case 19:
|
||||
_context5.prev = 19;
|
||||
_context5.t1 = _context5['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
|
||||
case 18:
|
||||
case 22:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this, [[0, 15]]);
|
||||
}, _callee5, this, [[0, 19]]);
|
||||
}));
|
||||
|
||||
function del(_x5) {
|
||||
|
@ -56,12 +56,12 @@ var userController = function (_baseController) {
|
||||
return (0, _possibleConstructorReturn3.default)(this, (userController.__proto__ || (0, _getPrototypeOf2.default)(userController)).call(this, ctx));
|
||||
}
|
||||
/**
|
||||
* 添加项目分组
|
||||
* 用户登录接口
|
||||
* @interface /user/login
|
||||
* @method POST
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} username 用户名称,不能为空
|
||||
* @param {String} email email名称,不能为空
|
||||
* @param {String} password 密码,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/user/login.json
|
||||
@ -128,7 +128,14 @@ var userController = function (_baseController) {
|
||||
expires: _yapi2.default.commons.expireDate(7),
|
||||
httpOnly: true
|
||||
});
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 0, 'logout success...'));
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn({
|
||||
uid: result._id,
|
||||
email: result.email,
|
||||
add_time: result.add_time,
|
||||
up_time: result.up_time
|
||||
|
||||
}, 0, 'logout success...'));
|
||||
|
||||
case 21:
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '密码错误'));
|
||||
@ -147,6 +154,17 @@ var userController = function (_baseController) {
|
||||
|
||||
return login;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 退出登录接口
|
||||
* @interface /user/logout
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example ./api/user/logout.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'logout',
|
||||
value: function () {
|
||||
@ -173,6 +191,20 @@ var userController = function (_baseController) {
|
||||
|
||||
return logout;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
* @interface /user/reg
|
||||
* @method POST
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} email email名称,不能为空
|
||||
* @param {String} password 密码,不能为空
|
||||
* @param {String} [username] 用户名
|
||||
* @returns {Object}
|
||||
* @example ./api/user/login.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'reg',
|
||||
value: function () {
|
||||
@ -233,27 +265,33 @@ var userController = function (_baseController) {
|
||||
case 16:
|
||||
user = _context3.sent;
|
||||
|
||||
user = _yapi2.default.commons.fieldSelect(user, ['id', 'username', 'email']);
|
||||
ctx.body = _yapi2.default.commons.resReturn(user);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn({
|
||||
uid: user._id,
|
||||
email: user.email,
|
||||
add_time: user.add_time,
|
||||
up_time: user.up_time,
|
||||
role: 'member'
|
||||
});
|
||||
_yapi2.default.commons.sendMail({
|
||||
to: params.email,
|
||||
contents: '\u6B22\u8FCE\u6CE8\u518C\uFF0C\u60A8\u7684\u8D26\u53F7 ' + params.email + ' \u5DF2\u7ECF\u6CE8\u518C\u6210\u529F'
|
||||
});
|
||||
_context3.next = 25;
|
||||
_context3.next = 24;
|
||||
break;
|
||||
|
||||
case 22:
|
||||
_context3.prev = 22;
|
||||
case 21:
|
||||
_context3.prev = 21;
|
||||
_context3.t0 = _context3['catch'](13);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 401, _context3.t0.message);
|
||||
|
||||
case 25:
|
||||
case 24:
|
||||
case 'end':
|
||||
return _context3.stop();
|
||||
}
|
||||
}
|
||||
}, _callee3, this, [[13, 22]]);
|
||||
}, _callee3, this, [[13, 21]]);
|
||||
}));
|
||||
|
||||
function reg(_x3) {
|
||||
@ -262,6 +300,17 @@ var userController = function (_baseController) {
|
||||
|
||||
return reg;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @interface /user/list
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
@ -271,26 +320,34 @@ var userController = function (_baseController) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
case 0:
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context4.next = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, 'Without permission.'));
|
||||
|
||||
case 2:
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_context4.prev = 1;
|
||||
_context4.next = 4;
|
||||
_context4.prev = 3;
|
||||
_context4.next = 6;
|
||||
return userInst.list();
|
||||
|
||||
case 4:
|
||||
case 6:
|
||||
user = _context4.sent;
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(user));
|
||||
|
||||
case 8:
|
||||
_context4.prev = 8;
|
||||
_context4.t0 = _context4['catch'](1);
|
||||
case 10:
|
||||
_context4.prev = 10;
|
||||
_context4.t0 = _context4['catch'](3);
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message));
|
||||
|
||||
case 11:
|
||||
case 13:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[1, 8]]);
|
||||
}, _callee4, this, [[3, 10]]);
|
||||
}));
|
||||
|
||||
function list(_x4) {
|
||||
@ -299,6 +356,18 @@ var userController = function (_baseController) {
|
||||
|
||||
return list;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @interface /user/list
|
||||
* @method GET
|
||||
* @param id 用户uid
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'findById',
|
||||
value: function () {
|
||||
@ -346,6 +415,18 @@ var userController = function (_baseController) {
|
||||
|
||||
return findById;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 获取用户列表,只有admin用户才有此权限
|
||||
* @interface /user/del
|
||||
* @method POST
|
||||
* @param id 用户uid
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'del',
|
||||
value: function () {
|
||||
|
Loading…
Reference in New Issue
Block a user