mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
feat: 给list接口添加分页功能
This commit is contained in:
parent
54e84763a5
commit
2ce79aeada
555
doc/build/api.html
vendored
555
doc/build/api.html
vendored
@ -104,6 +104,10 @@
|
||||
<a href="#-user-logout">/user/logout</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-change_password">/user/change_password</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-reg">/user/reg</a>
|
||||
</li>
|
||||
@ -113,13 +117,21 @@
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-list">/user/list</a>
|
||||
<a href="#-user-find">/user/find</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-del">/user/del</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-update">/user/update</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-user-search">/user/search</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- <li > -->
|
||||
@ -142,6 +154,10 @@
|
||||
<a href="#-project-del_member">/project/del_member</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-project-get_member_list">/project/get_member_list</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-project-get">/project/get</a>
|
||||
</li>
|
||||
@ -158,6 +174,10 @@
|
||||
<a href="#-project-up">/project/up</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-project-search">/project/search</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- <li > -->
|
||||
@ -218,7 +238,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#13" target="_blank">./server/controllers/group.js:13</a>
|
||||
<a href="./static/server/controllers/group.js.html#12" target="_blank">./server/controllers/group.js:12</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -301,7 +321,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#52" target="_blank">./server/controllers/group.js:52</a>
|
||||
<a href="./static/server/controllers/group.js.html#51" target="_blank">./server/controllers/group.js:51</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -363,7 +383,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#72" target="_blank">./server/controllers/group.js:72</a>
|
||||
<a href="./static/server/controllers/group.js.html#71" target="_blank">./server/controllers/group.js:71</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -435,7 +455,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/group.js.html#103" target="_blank">./server/controllers/group.js:103</a>
|
||||
<a href="./static/server/controllers/group.js.html#102" target="_blank">./server/controllers/group.js:102</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -535,7 +555,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#11" target="_blank">./server/controllers/user.js:11</a>
|
||||
<a href="./static/server/controllers/user.js.html#13" target="_blank">./server/controllers/user.js:13</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -595,6 +615,7 @@
|
||||
<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">"username"</span><span class="token punctuation">:</span> <span class="token string">"admin"</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>
|
||||
@ -621,7 +642,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#62" target="_blank">./server/controllers/user.js:62</a>
|
||||
<a href="./static/server/controllers/user.js.html#57" target="_blank">./server/controllers/user.js:57</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -634,6 +655,93 @@
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-change_password" class="page-header subject">
|
||||
/user/change_password
|
||||
|
||||
<span class="ui-badge">POST</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-change_password">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
修改用户密码
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#150" target="_blank">./server/controllers/user.js:150</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>uid</td>
|
||||
<td>Number</td>
|
||||
<td>用户ID</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>old_password</td>
|
||||
<td>Number</td>
|
||||
<td>旧密码, 非admin用户必须传</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>password</td>
|
||||
<td>Number</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" ><code><span class="token punctuation">.</span><span class="token operator">/</span>api<span class="token operator">/</span>user<span class="token operator">/</span>change_password</code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
@ -654,7 +762,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#79" target="_blank">./server/controllers/user.js:79</a>
|
||||
<a href="./static/server/controllers/user.js.html#214" target="_blank">./server/controllers/user.js:214</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -724,6 +832,7 @@
|
||||
<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">"username"</span><span class="token punctuation">:</span> <span class="token string">"admin"</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>
|
||||
@ -750,33 +859,77 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#136" target="_blank">./server/controllers/user.js:136</a>
|
||||
<a href="./static/server/controllers/user.js.html#276" target="_blank">./server/controllers/user.js:276</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>pageNo</td>
|
||||
<td>Number</td>
|
||||
<td>分页页码</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>pageSize</td>
|
||||
<td>Number</td>
|
||||
<td>分页大小</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-list" class="page-header subject">
|
||||
/user/list
|
||||
<h3 id="-user-find" class="page-header subject">
|
||||
/user/find
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-list">#</a>
|
||||
<a class="hashlink" href="#-user-find">#</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>
|
||||
<a href="./static/server/controllers/user.js.html#314" target="_blank">./server/controllers/user.js:314</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -833,12 +986,12 @@
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
获取用户列表,只有admin用户才有此权限
|
||||
删除用户,只有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>
|
||||
<a href="./static/server/controllers/user.js.html#336" target="_blank">./server/controllers/user.js:336</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -880,6 +1033,160 @@
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-user-update" class="page-header subject">
|
||||
/user/update
|
||||
|
||||
<span class="ui-badge">POST</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-update">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
更新用户个人信息
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#360" target="_blank">./server/controllers/user.js:360</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>username</td>
|
||||
<td></td>
|
||||
<td>String</td>
|
||||
<td>
|
||||
|
||||
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>email</td>
|
||||
<td></td>
|
||||
<td>String</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-search" class="page-header subject">
|
||||
/user/search
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-user-search">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
模糊搜索用户名或者email
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#396" target="_blank">./server/controllers/user.js:396</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>q</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">200</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"ok"</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 punctuation">{</span>
|
||||
<span class="token string">"_id"</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">"password"</span><span class="token punctuation">:</span> <span class="token string">"3d078af947521bb4a99c93f5e089fc2ac601fa09"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"passsalt"</span><span class="token punctuation">:</span> <span class="token string">"qc8lnjpnbs9z1vodz4ynfjemi"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"role"</span><span class="token punctuation">:</span> <span class="token string">"admin"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1499936103</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1499936103</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@ -903,7 +1210,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#12" target="_blank">./server/controllers/project.js:12</a>
|
||||
<a href="./static/server/controllers/project.js.html#15" target="_blank">./server/controllers/project.js:15</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1027,12 +1334,12 @@
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
添加项目
|
||||
添加项目成员
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#74" target="_blank">./server/controllers/project.js:74</a>
|
||||
<a href="./static/server/controllers/project.js.html#77" target="_blank">./server/controllers/project.js:77</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1070,8 +1377,8 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>uid</td>
|
||||
<td>member_uid</td>
|
||||
<td>String</td>
|
||||
<td>项目成员uid,不能为空</td>
|
||||
<td>
|
||||
|
||||
@ -1111,12 +1418,12 @@
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
添加项目
|
||||
删除项目成员
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#106" target="_blank">./server/controllers/project.js:106</a>
|
||||
<a href="./static/server/controllers/project.js.html#109" target="_blank">./server/controllers/project.js:109</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1180,6 +1487,84 @@
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-project-get_member_list" class="page-header subject">
|
||||
/project/get_member_list
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-project-get_member_list">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
获取项目成员列表
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#142" target="_blank">./server/controllers/project.js:142</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 punctuation">{</span>
|
||||
<span class="token string">"_id"</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">"role"</span><span class="token punctuation">:</span> <span class="token string">"admin"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1499932673</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1499932673</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
@ -1200,7 +1585,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#138" target="_blank">./server/controllers/project.js:138</a>
|
||||
<a href="./static/server/controllers/project.js.html#182" target="_blank">./server/controllers/project.js:182</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1283,7 +1668,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#162" target="_blank">./server/controllers/project.js:162</a>
|
||||
<a href="./static/server/controllers/project.js.html#206" target="_blank">./server/controllers/project.js:206</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1320,6 +1705,26 @@
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>pageNo</td>
|
||||
<td>Number</td>
|
||||
<td>分页页码</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>pageSize</td>
|
||||
<td>Number</td>
|
||||
<td>分页大小</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@ -1383,7 +1788,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#186" target="_blank">./server/controllers/project.js:186</a>
|
||||
<a href="./static/server/controllers/project.js.html#244" target="_blank">./server/controllers/project.js:244</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1455,7 +1860,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#219" target="_blank">./server/controllers/project.js:219</a>
|
||||
<a href="./static/server/controllers/project.js.html#277" target="_blank">./server/controllers/project.js:277</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1595,6 +2000,104 @@
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-project-search" class="page-header subject">
|
||||
/project/search
|
||||
|
||||
<span class="ui-badge">GET</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-project-search">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
模糊搜索项目名称或者组名称
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#338" target="_blank">./server/controllers/project.js:338</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>q</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">200</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"ok"</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">"project"</span><span class="token punctuation">:</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">101</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"project yapi"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"yapi.qunar.com"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"/yapi/"</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">"group_id"</span><span class="token punctuation">:</span> <span class="token number">193</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500013365</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500013365</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
|
||||
<span class="token string">"101"</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group"</span><span class="token punctuation">:</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">193</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_name"</span><span class="token punctuation">:</span> <span class="token string">"yapi"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_desc"</span><span class="token punctuation">:</span> <span class="token string">"group yapi"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500013066</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500013066</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">]</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
11
doc/build/static/server/controllers/base.js.html
vendored
11
doc/build/static/server/controllers/base.js.html
vendored
@ -33,7 +33,7 @@ const jwt = require('jsonwebtoken');
|
||||
|
||||
class baseController{
|
||||
constructor(ctx){
|
||||
|
||||
this.ctx = ctx;
|
||||
//网站上线后,role对象key是不能修改的,value可以修改
|
||||
this.roles = {
|
||||
admin: 'Admin',
|
||||
@ -43,7 +43,14 @@ class baseController{
|
||||
|
||||
async init(ctx){
|
||||
this.$user = null;
|
||||
if(ctx.path === '/user/login' || ctx.path === '/user/reg' || ctx.path === '/user/status' || ctx.path === '/user/logout'){
|
||||
let ignoreRouter = [
|
||||
'/user/login_by_token',
|
||||
'/user/login',
|
||||
'/user/reg',
|
||||
'/user/status',
|
||||
'/user/logout'
|
||||
]
|
||||
if(ignoreRouter.indexOf(ctx.path) > -1){
|
||||
this.$auth = true;
|
||||
}else{
|
||||
await this.checkLogin(ctx)
|
||||
|
@ -34,7 +34,6 @@ import projectModel from '../models/project.js'
|
||||
class groupController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
console.log('constructor....')
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,12 +29,15 @@
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import interfaceModel from '../models/interface.js'
|
||||
import userModel from '../models/user.js'
|
||||
import groupModel from '../models/group'
|
||||
|
||||
class projectController extends baseController {
|
||||
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
this.Model = yapi.getInst(projectModel);
|
||||
this.groupModel = yapi.getInst(groupModel);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,13 +103,13 @@ class projectController extends baseController {
|
||||
|
||||
}
|
||||
/**
|
||||
* 添加项目
|
||||
* 添加项目成员
|
||||
* @interface /project/add_member
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @param {member_uid} uid 项目成员uid,不能为空
|
||||
* @param {String} member_uid 项目成员uid,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/add_member.json
|
||||
*/
|
||||
@ -132,7 +135,7 @@ class projectController extends baseController {
|
||||
|
||||
}
|
||||
/**
|
||||
* 添加项目
|
||||
* 删除项目成员
|
||||
* @interface /project/del_member
|
||||
* @method POST
|
||||
* @category project
|
||||
@ -163,6 +166,47 @@ class projectController extends baseController {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目成员列表
|
||||
* @interface /project/get_member_list
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @return {Object}
|
||||
* @example ./api/project/get_member_list.json
|
||||
*/
|
||||
|
||||
async getMemberList(ctx) {
|
||||
let params = ctx.request.query;
|
||||
if(!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
let project = await this.Model.get(params.id);
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let result = [];
|
||||
|
||||
for(let i of project.members) {
|
||||
let user = await userInst.findById(i);
|
||||
result.push({
|
||||
_id: user._id,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
add_time: user.add_time,
|
||||
up_time: user.up_time
|
||||
});
|
||||
}
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch(e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/get
|
||||
@ -194,18 +238,32 @@ class projectController extends baseController {
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} group_id 项目group_id,不能为空
|
||||
* @param {Number} [pageNo] 分页页码
|
||||
* @param {Number} [pageSize] 分页大小
|
||||
* @returns {Object}
|
||||
* @example ./api/project/list.json
|
||||
*/
|
||||
|
||||
async list(ctx) {
|
||||
let group_id = ctx.request.query.group_id;
|
||||
let group_id = ctx.request.query.group_id,
|
||||
pageNo = ctx.request.query.pageNo || 1,
|
||||
pageSize = ctx.request.query.pageSize || 10;
|
||||
|
||||
if(!group_id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
|
||||
try{
|
||||
let result = await this.Model.list(group_id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
let resResult = [];
|
||||
for(let i = (pageNo - 1) * pageSize; i < pageNo * pageSize; i++) {
|
||||
if(!result[i]) break;
|
||||
resResult.push(result[i]);
|
||||
}
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
total: result.length,
|
||||
list: resResult
|
||||
})
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
}
|
||||
@ -304,6 +362,35 @@ class projectController extends baseController {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊搜索项目名称或者组名称
|
||||
* @interface /project/search
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {String} q
|
||||
* @return {Object}
|
||||
* @example ./api/project/search.json
|
||||
*/
|
||||
async search(ctx) {
|
||||
const { q } = ctx.request.query;
|
||||
|
||||
if (!q) {
|
||||
return ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.')
|
||||
}
|
||||
|
||||
if (!yapi.commons.validateSearchKeyword(q)) {
|
||||
return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.')
|
||||
}
|
||||
|
||||
let queryList = {
|
||||
project: await this.Model.search(q),
|
||||
group: await this.groupModel.search(q)
|
||||
}
|
||||
|
||||
return ctx.body = yapi.commons.resReturn(queryList, 200, 'ok')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = projectController;
|
||||
|
240
doc/build/static/server/controllers/user.js.html
vendored
240
doc/build/static/server/controllers/user.js.html
vendored
@ -29,12 +29,14 @@
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import mongoose from 'mongoose'
|
||||
import request from 'request'
|
||||
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
class userController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
this.Model = yapi.getInst(userModel);
|
||||
}
|
||||
/**
|
||||
* 用户登录接口
|
||||
@ -65,17 +67,10 @@ class userController extends baseController{
|
||||
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
|
||||
})
|
||||
this.setLoginCookie(result._id, result.passsalt)
|
||||
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
username: result.username,
|
||||
uid: result._id,
|
||||
email: result.email,
|
||||
add_time: result.add_time,
|
||||
@ -104,6 +99,146 @@ class userController extends baseController{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 第三方登录需要提供一个request方法和 token字段,暂时只支持qunar第三方
|
||||
* @return {email: String, username: String}
|
||||
*/
|
||||
thirdQunarLogin(){
|
||||
return {
|
||||
request: (token) => {
|
||||
return new Promise((resolve, reject) =>{
|
||||
request('http://qsso.corp.qunar.com/api/verifytoken.php?token=' + token ,function (error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
let result = JSON.parse(body);
|
||||
if(result && result.ret === true){
|
||||
let ret = {
|
||||
email: result.userId + '@qunar.com',
|
||||
username: result.data.userInfo.name
|
||||
}
|
||||
resolve(ret)
|
||||
}else{
|
||||
reject(result)
|
||||
}
|
||||
}
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
tokenField: 'token',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async loginByToken(ctx){
|
||||
let config = this.thirdQunarLogin();
|
||||
|
||||
let token = ctx.request.body[config.tokenField] || ctx.request.query[config.tokenField];
|
||||
|
||||
try{
|
||||
let ret = await config.request(token);
|
||||
let login = await this.handleThirdLogin(ret.email, ret.username);
|
||||
if(login === true){
|
||||
yapi.commons.log('login success');
|
||||
ctx.redirect('/')
|
||||
}
|
||||
}catch(e){
|
||||
yapi.commons.log(e.message, 'error')
|
||||
ctx.redirect('/')
|
||||
}
|
||||
}
|
||||
|
||||
async handleThirdLogin(email, username){
|
||||
let user, data, passsalt;
|
||||
var userInst = yapi.getInst(userModel);
|
||||
try{
|
||||
user = await userInst.findByEmail(email);
|
||||
if(!user || !user._id){
|
||||
passsalt = yapi.commons.randStr();
|
||||
data = {
|
||||
username: username,
|
||||
password: yapi.commons.generatePassword(passsalt, passsalt),
|
||||
email: email,
|
||||
passsalt: passsalt,
|
||||
role: 'member',
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
user = await userInst.save(data);
|
||||
}
|
||||
|
||||
this.setLoginCookie(user._id, user.passsalt)
|
||||
return true;
|
||||
}catch(e){
|
||||
console.error(e.message)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
* @interface /user/change_password
|
||||
* @method POST
|
||||
* @category user
|
||||
* @param {Number} uid 用户ID
|
||||
* @param {Number} [old_password] 旧密码, 非admin用户必须传
|
||||
* @param {Number} password 新密码
|
||||
* @return {Object}
|
||||
* @example ./api/user/change_password
|
||||
*/
|
||||
async changePassword(ctx){
|
||||
let params = ctx.request.body;
|
||||
let userInst = yapi.getInst(userModel);
|
||||
if(this.getRole() !== 'admin' && params.uid != this.getUid()){
|
||||
console.log(this.getRole(), this.getUid());
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, '没有权限');
|
||||
}
|
||||
if(this.getRole() !== 'admin') {
|
||||
if(!params.old_password) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '旧密码不能为空');
|
||||
}
|
||||
|
||||
let user = await userInst.findById(params.uid);
|
||||
if(yapi.commons.generatePassword(params.old_password, user.passsalt) !== user.password) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, '旧密码错误');
|
||||
}
|
||||
}
|
||||
|
||||
let passsalt = yapi.commons.randStr();
|
||||
let data = {
|
||||
up_time: yapi.commons.time(),
|
||||
password: yapi.commons.generatePassword(params.password, passsalt),
|
||||
passsalt: passsalt
|
||||
};
|
||||
try{
|
||||
let result = await userInst.update(params.uid, data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 401, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async forgetPassword(ctx){
|
||||
|
||||
}
|
||||
|
||||
async resetPassword(ctx){
|
||||
|
||||
}
|
||||
|
||||
setLoginCookie(uid, passsalt){
|
||||
let token = jwt.sign({uid: uid},passsalt,{expiresIn: '7 days'});
|
||||
this.ctx.cookies.set('_yapi_token', token, {
|
||||
expires: yapi.commons.expireDate(7),
|
||||
httpOnly: true
|
||||
})
|
||||
this.ctx.cookies.set('_yapi_uid', uid, {
|
||||
expires: yapi.commons.expireDate(7),
|
||||
httpOnly: true
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
* @interface /user/reg
|
||||
@ -141,15 +276,20 @@ class userController extends baseController{
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
if(!data.username){
|
||||
data.username = data.email.substr(0, data.email.indexOf('@'));
|
||||
}
|
||||
try{
|
||||
let user = await userInst.save(data);
|
||||
this.setLoginCookie(user._id, user.passsalt)
|
||||
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
uid: user._id,
|
||||
email: user.email,
|
||||
username: user.username,
|
||||
add_time: user.add_time,
|
||||
up_time: user.up_time,
|
||||
role: 'member',
|
||||
role: 'member'
|
||||
});
|
||||
yapi.commons.sendMail({
|
||||
to: params.email,
|
||||
@ -167,26 +307,41 @@ class userController extends baseController{
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {Number} [pageNo] 分页页码
|
||||
* @param {Number} [pageSize] 分页大小
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
let pageNo = ctx.request.query.pageNo || 1,
|
||||
pageSize = ctx.request.query.pageSize || 10;
|
||||
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.');
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, '没有权限');
|
||||
}
|
||||
var userInst = yapi.getInst(userModel);
|
||||
try{
|
||||
let user = await userInst.list();
|
||||
return ctx.body = yapi.commons.resReturn(user);
|
||||
let result = [];
|
||||
|
||||
for(let i = (pageNo - 1) * pageSize; i < pageNo * pageSize; i++) {
|
||||
if(!user[i]) break;
|
||||
result.push(user[i]);
|
||||
}
|
||||
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
total: user.length,
|
||||
list: result
|
||||
});
|
||||
}catch(e){
|
||||
return ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @interface /user/list
|
||||
* 获取用户个人信息
|
||||
* @interface /user/find
|
||||
* @method GET
|
||||
* @param id 用户uid
|
||||
* @category user
|
||||
@ -199,9 +354,6 @@ class userController extends baseController{
|
||||
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){
|
||||
@ -210,7 +362,7 @@ class userController extends baseController{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表,只有admin用户才有此权限
|
||||
* 删除用户,只有admin用户才有此权限
|
||||
* @interface /user/del
|
||||
* @method POST
|
||||
* @param id 用户uid
|
||||
@ -233,20 +385,66 @@ class userController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新用户个人信息
|
||||
* @interface /user/update
|
||||
* @method POST
|
||||
* @param username String
|
||||
* @param email String
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
async update(ctx){ //更新用户信息
|
||||
try{
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let id = this.getUid();
|
||||
let data ={};
|
||||
let data ={
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
ctx.request.body.username && (data.username = ctx.request.body.username)
|
||||
ctx.request.body.email && (data.email = ctx.request.body.email)
|
||||
let result = await userInst.update(id,data);
|
||||
|
||||
if(data.email){
|
||||
var checkRepeat = await userInst.checkRepeat(data.email);//然后检查是否已经存在该用户
|
||||
if(checkRepeat>0){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'该email已经注册');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let result = await userInst.update(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊搜索用户名或者email
|
||||
* @interface /user/search
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {String} q
|
||||
* @return {Object}
|
||||
* @example ./api/user/search.json
|
||||
*/
|
||||
async search(ctx) {
|
||||
const { q } = ctx.request.query;
|
||||
|
||||
if (!q) {
|
||||
return ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.')
|
||||
}
|
||||
|
||||
if (!yapi.commons.validateSearchKeyword(q)) {
|
||||
return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.')
|
||||
}
|
||||
|
||||
let queryList = await this.Model.search(q);
|
||||
return ctx.body = yapi.commons.resReturn(queryList, 200, 'ok')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = userController
|
||||
|
@ -5,12 +5,9 @@
|
||||
{
|
||||
"_id": 101,
|
||||
"email": "admin@admin.com",
|
||||
"password": "e00084747ecba89837affe8a048e83c751e44209",
|
||||
"passsalt": "fmf3kytyysc4swwuqc15rk9",
|
||||
"role": "admin",
|
||||
"add_time": 1499932673,
|
||||
"up_time": 1499932673,
|
||||
"__v": 0
|
||||
"up_time": 1499932673
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class projectController extends baseController {
|
||||
|
||||
/**
|
||||
* 获取项目成员列表
|
||||
* @interface /project/get_member_list.json
|
||||
* @interface /project/get_member_list
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
@ -164,7 +164,13 @@ class projectController extends baseController {
|
||||
|
||||
for(let i of project.members) {
|
||||
let user = await userInst.findById(i);
|
||||
result.push(user);
|
||||
result.push({
|
||||
_id: user._id,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
add_time: user.add_time,
|
||||
up_time: user.up_time
|
||||
});
|
||||
}
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
@ -205,18 +211,32 @@ class projectController extends baseController {
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} group_id 项目group_id,不能为空
|
||||
* @param {Number} [pageNo] 分页页码
|
||||
* @param {Number} [pageSize] 分页大小
|
||||
* @returns {Object}
|
||||
* @example ./api/project/list.json
|
||||
*/
|
||||
|
||||
async list(ctx) {
|
||||
let group_id = ctx.request.query.group_id;
|
||||
let group_id = ctx.request.query.group_id,
|
||||
pageNo = ctx.request.query.pageNo || 1,
|
||||
pageSize = ctx.request.query.pageSize || 10;
|
||||
|
||||
if(!group_id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
|
||||
try{
|
||||
let result = await this.Model.list(group_id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
let resResult = [];
|
||||
for(let i = (pageNo - 1) * pageSize; i < pageNo * pageSize; i++) {
|
||||
if(!result[i]) break;
|
||||
resResult.push(result[i]);
|
||||
}
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
total: result.length,
|
||||
list: resResult
|
||||
})
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
}
|
||||
|
@ -280,18 +280,33 @@ class userController extends baseController{
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {Number} [pageNo] 分页页码
|
||||
* @param {Number} [pageSize] 分页大小
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async list(ctx){
|
||||
let pageNo = ctx.request.query.pageNo || 1,
|
||||
pageSize = ctx.request.query.pageSize || 10;
|
||||
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, '没有权限');
|
||||
}
|
||||
var userInst = yapi.getInst(userModel);
|
||||
try{
|
||||
let user = await userInst.list();
|
||||
return ctx.body = yapi.commons.resReturn(user);
|
||||
let result = [];
|
||||
|
||||
for(let i = (pageNo - 1) * pageSize; i < pageNo * pageSize; i++) {
|
||||
if(!user[i]) break;
|
||||
result.push(user[i]);
|
||||
}
|
||||
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
total: user.length,
|
||||
list: result
|
||||
});
|
||||
}catch(e){
|
||||
return ctx.body = yapi.commons.resReturn(null,402,e.message);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ createAction('project', 'up', 'post', 'up')
|
||||
createAction('project', 'del', 'post', 'del')
|
||||
createAction('project', 'add_member', 'post', 'addMember')
|
||||
createAction('project', 'del_member', 'post', 'delMember')
|
||||
createAction('project', 'get_member_list.json', 'get', 'getMemberList')
|
||||
createAction('project', 'get_member_list', 'get', 'getMemberList')
|
||||
createAction('project', 'search', 'get', 'search')
|
||||
|
||||
//interface
|
||||
|
@ -371,7 +371,7 @@ var projectController = function (_baseController) {
|
||||
|
||||
/**
|
||||
* 获取项目成员列表
|
||||
* @interface /project/get_member_list.json
|
||||
* @interface /project/get_member_list
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
@ -427,7 +427,13 @@ var projectController = function (_baseController) {
|
||||
case 18:
|
||||
user = _context4.sent;
|
||||
|
||||
result.push(user);
|
||||
result.push({
|
||||
_id: user._id,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
add_time: user.add_time,
|
||||
up_time: user.up_time
|
||||
});
|
||||
|
||||
case 20:
|
||||
_iteratorNormalCompletion = true;
|
||||
@ -564,6 +570,8 @@ var projectController = function (_baseController) {
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} group_id 项目group_id,不能为空
|
||||
* @param {Number} [pageNo] 分页页码
|
||||
* @param {Number} [pageSize] 分页大小
|
||||
* @returns {Object}
|
||||
* @example ./api/project/list.json
|
||||
*/
|
||||
@ -572,12 +580,12 @@ var projectController = function (_baseController) {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
||||
var group_id, result;
|
||||
var group_id, pageNo, pageSize, result, resResult, i;
|
||||
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
||||
while (1) {
|
||||
switch (_context6.prev = _context6.next) {
|
||||
case 0:
|
||||
group_id = ctx.request.query.group_id;
|
||||
group_id = ctx.request.query.group_id, pageNo = ctx.request.query.pageNo || 1, pageSize = ctx.request.query.pageSize || 10;
|
||||
|
||||
if (group_id) {
|
||||
_context6.next = 3;
|
||||
@ -593,23 +601,50 @@ var projectController = function (_baseController) {
|
||||
|
||||
case 6:
|
||||
result = _context6.sent;
|
||||
resResult = [];
|
||||
i = (pageNo - 1) * pageSize;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context6.next = 13;
|
||||
case 9:
|
||||
if (!(i < pageNo * pageSize)) {
|
||||
_context6.next = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result[i]) {
|
||||
_context6.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context6.abrupt('break', 16);
|
||||
|
||||
case 12:
|
||||
resResult.push(result[i]);
|
||||
|
||||
case 13:
|
||||
i++;
|
||||
_context6.next = 9;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
_context6.prev = 10;
|
||||
case 16:
|
||||
ctx.body = _yapi2.default.commons.resReturn({
|
||||
total: result.length,
|
||||
list: resResult
|
||||
});
|
||||
_context6.next = 22;
|
||||
break;
|
||||
|
||||
case 19:
|
||||
_context6.prev = 19;
|
||||
_context6.t0 = _context6['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
|
||||
case 13:
|
||||
case 22:
|
||||
case 'end':
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee6, this, [[3, 10]]);
|
||||
}, _callee6, this, [[3, 19]]);
|
||||
}));
|
||||
|
||||
function list(_x6) {
|
||||
|
@ -618,6 +618,8 @@ var userController = function (_baseController) {
|
||||
* @method GET
|
||||
* @category user
|
||||
* @foldnumber 10
|
||||
* @param {Number} [pageNo] 分页页码
|
||||
* @param {Number} [pageSize] 分页大小
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
@ -626,39 +628,69 @@ var userController = function (_baseController) {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var userInst, user;
|
||||
var pageNo, pageSize, userInst, user, result, i;
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
case 0:
|
||||
pageNo = ctx.request.query.pageNo || 1, pageSize = ctx.request.query.pageSize || 10;
|
||||
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context9.next = 2;
|
||||
_context9.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, '没有权限'));
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_context9.prev = 3;
|
||||
_context9.next = 6;
|
||||
_context9.prev = 4;
|
||||
_context9.next = 7;
|
||||
return userInst.list();
|
||||
|
||||
case 6:
|
||||
case 7:
|
||||
user = _context9.sent;
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(user));
|
||||
result = [];
|
||||
i = (pageNo - 1) * pageSize;
|
||||
|
||||
case 10:
|
||||
_context9.prev = 10;
|
||||
_context9.t0 = _context9['catch'](3);
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t0.message));
|
||||
if (!(i < pageNo * pageSize)) {
|
||||
_context9.next = 17;
|
||||
break;
|
||||
}
|
||||
|
||||
if (user[i]) {
|
||||
_context9.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('break', 17);
|
||||
|
||||
case 13:
|
||||
result.push(user[i]);
|
||||
|
||||
case 14:
|
||||
i++;
|
||||
_context9.next = 10;
|
||||
break;
|
||||
|
||||
case 17:
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn({
|
||||
total: user.length,
|
||||
list: result
|
||||
}));
|
||||
|
||||
case 20:
|
||||
_context9.prev = 20;
|
||||
_context9.t0 = _context9['catch'](4);
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t0.message));
|
||||
|
||||
case 23:
|
||||
case 'end':
|
||||
return _context9.stop();
|
||||
}
|
||||
}
|
||||
}, _callee9, this, [[3, 10]]);
|
||||
}, _callee9, this, [[4, 20]]);
|
||||
}));
|
||||
|
||||
function list(_x10) {
|
||||
|
@ -82,7 +82,7 @@ createAction('project', 'up', 'post', 'up');
|
||||
createAction('project', 'del', 'post', 'del');
|
||||
createAction('project', 'add_member', 'post', 'addMember');
|
||||
createAction('project', 'del_member', 'post', 'delMember');
|
||||
createAction('project', 'get_member_list.json', 'get', 'getMemberList');
|
||||
createAction('project', 'get_member_list', 'get', 'getMemberList');
|
||||
createAction('project', 'search', 'get', 'search');
|
||||
|
||||
//interface
|
||||
|
Loading…
Reference in New Issue
Block a user