feat: merge to local

This commit is contained in:
sean 2017-07-14 19:47:38 +08:00
commit 2d3412b924
29 changed files with 748 additions and 247 deletions

View File

@ -1,6 +1,5 @@
import {
LOGIN,
REGISTER,
LOGIN_TYPE
} from '../constants/action-types.js';
import axios from 'axios';
@ -24,9 +23,18 @@ const loginActions = (data) => {
}
const regActions = (data) => {
return {
type: REGISTER,
data
console.log(data);
const param = {
email: data.email,
password: data.password,
username: data.userName
}
return () => {
axios.get('/user/login', param).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
}
}

24
client/actions/project.js Normal file
View File

@ -0,0 +1,24 @@
import {
PROJECT_ADD
} from '../constants/action-types.js';
import axios from 'axios';
const addProject = (data) => {
const { name, prd_host, basepath, desc } = data;
const param = {
name,
prd_host,
basepath,
desc
}
console.log(param);
return {
type: PROJECT_ADD,
// payload 可以返回 Promise异步请求使用 axios 即可
payload: axios.get('/project/add', param)
}
}
export default {
addProject
}

View File

@ -32,49 +32,36 @@ ToolGuest.propTypes={
class Header extends Component {
constructor(props) {
super(props);
this.state={
guestToolShow:true
}
}
handleLogin = (e) => {
e.preventDefault();
this.props.loginTypeAction("1");
this.setState({
guestToolShow:false
})
}
handleReg = (e)=>{
e.preventDefault();
this.props.loginTypeAction("2");
this.setState({
guestToolShow:false
})
}
hideGuestTool = (e)=>{
e.preventDefault();
this.setState({
guestToolShow:true
})
}
render () {
const { login, user, msg } = this.props;
return (
<acticle className="header-box">
<div className="content">
<h1>YAPI</h1>
<h1>
<Link to={`/`}>YAPI</Link>
</h1>
<ul className="nav-toolbar">
<li onClick={this.hideGuestTool}>
<li>
<Link to={`/ProjectGroups`}>分组</Link>
</li>
<li onClick={this.hideGuestTool}>
<li>
<a>我的项目</a>
</li>
<li onClick={this.hideGuestTool}>
<li>
<a>文档</a>
</li>
</ul>
<ul className="user-toolbar">
{login?<ToolUser user={user} msg={msg}/>:(this.state.guestToolShow?<ToolGuest onLogin={this.handleLogin} onReg={this.handleReg}/>:'')}
{login?<ToolUser user={user} msg={msg}/>:''}
</ul>
</div>
</acticle>

View File

@ -21,8 +21,18 @@ $color-grey-deep : #929aac;
h1 {
font-size: .25rem;
float: left;
margin: 0 .2rem;
margin: 0 .2rem 0 0;
color: $color-white;
cursor: pointer;
a{
color: $color-white;
&:hover {
color: $color-white;
}
&:focus{
text-decoration: none;
}
}
}
.nav-toolbar {

View File

@ -7,9 +7,12 @@ export const PROJECT_MEMBER_INTERFACE = 'PROJECT_MEMBER_INTERFACE'
export const FETCH_GROUP_LIST = 'FETCH_GROUP_LIST'
export const FETCH_CURR_GROUP = 'FETCH_CURR_GROUP'
// project
export const PROJECT_ADD = 'PROJECT_ADD'
// login
export const LOGIN = 'LOGIN';
export const REGISTER = 'REGISTER';
//header
export const LOGIN_TYPE = 'LOGIN_TYPE';
export const LOGIN_TYPE = 'LOGIN_TYPE';

View File

@ -1,5 +1,7 @@
import './Home.scss'
import React, { Component } from 'react'
import Login from '../Login/login-wrap'
class Home extends Component {
constructor(props) {
@ -8,9 +10,15 @@ class Home extends Component {
render () {
return (
<acticle className="home-main">
主页
</acticle>
<div className="home-main">
<div className="main-one">
<div className="home-des">
<p className="title">YAPI</p>
<div className="detail">一个高效易用功能强大的api管理系统</div>
</div>
<Login/>
</div>
</div>
)
}
}

View File

@ -1,42 +1,27 @@
@import '../../styles/common.scss';
/* .home-main.css */
// .home-main {
// display: -webkit-box;
// -webkit-box-orient: vertical;
// height: 100%;
// }
.home-main {
display: -webkit-box;
max-width: 11rem;
margin: 0 auto;
-webkit-box-orient: vertical;
.main-one{
height:calc(100% - .64rem);
padding: .5rem 0;
.home-des{
padding: .3rem 0;
.title{
font-size: .6rem;
}
.detail{
font-size: .23rem;
}
}
.login-form{
// /* .home-box.css */
// .home-box {
// font-size: 0.14rem;
// display: -webkit-box;
// -webkit-box-align: center;
// -webkit-box-pack: center;
// -webkit-box-flex: 1;
}
}
// .content {
// max-width: 5rem;
// min-width: 3rem;
// zoom: 1;
// overflow: hidden;
// margin: -70px 0 0 0;
// }
}
// h3 {
// font-size: 0.2rem;
// }
// a {
// font-size: 0.14rem;
// }
// .ant-input-affix-wrapper {
// margin: 0 0 20px 0;
// height: 35px;
// }
// .login {
// float: right;
// }
// }

View File

@ -1,4 +1,4 @@
import './Login.scss'
import './login.scss'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'

View File

@ -3,5 +3,4 @@
/* .login-main.css */
.login-form {
width: 4rem;
margin: 1rem auto;
}

View File

@ -18,7 +18,10 @@ const FormItem = Form.Item;
class Reg extends Component {
constructor(props) {
super(props)
super(props);
this.state = {
confirmDirty: false
}
}
static propTypes = {
@ -29,17 +32,41 @@ class Reg extends Component {
handleSubmit = (e) => {
e.preventDefault();
const form = this.props.form;
form.validateFields((err, values) => {
form.validateFieldsAndScroll((err, values) => {
if (!err) {
this.props.regActions(values);
}
});
}
handleConfirmBlur = (e) => {
const value = e.target.value;
this.setState({ confirmDirty: this.state.confirmDirty || !!value });
}
checkPassword = (rule, value, callback) => {
const form = this.props.form;
if (value && value !== form.getFieldValue('password')) {
callback('Two passwords that you enter is inconsistent!');
} else {
callback();
}
}
checkConfirm = (rule, value, callback) => {
const form = this.props.form;
if (value && this.state.confirmDirty) {
form.validateFields(['confirm'], { force: true });
}
callback();
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit}>
{/* 用户名 */}
<FormItem>
{getFieldDecorator('userName', {
rules: [{ required: true, message: '请输入用户名!' }]
@ -47,6 +74,8 @@ class Reg extends Component {
<Input prefix={<Icon type="user" style={{ fontSize: 13 }} />} placeholder="Username" />
)}
</FormItem>
{/* Emaiil */}
<FormItem>
{getFieldDecorator('email', {
rules: [{ required: true, message: '请输入email!' }]
@ -54,13 +83,36 @@ class Reg extends Component {
<Input prefix={<Icon type="user" style={{ fontSize: 13 }} />} placeholder="Email" />
)}
</FormItem>
{/* 密码 */}
<FormItem>
{getFieldDecorator('password', {
rules: [{ required: true, message: '请输入密码!' }]
rules: [{
required: true,
message: '请输入密码!'
}, {
validator: this.checkConfirm
}]
})(
<Input prefix={<Icon type="lock" style={{ fontSize: 13 }} />} type="password" placeholder="Password" />
)}
</FormItem>
{/* 密码二次确认 */}
<FormItem>
{getFieldDecorator('confirm', {
rules: [{
required: true,
message: '请再次输入密码密码!'
}, {
validator: this.checkPassword
}]
})(
<Input prefix={<Icon type="lock" style={{ fontSize: 13 }} />} type="password" placeholder="Confirm Password" />
)}
</FormItem>
{/* 注册按钮 */}
<FormItem>
<Button type="primary" htmlType="submit" className="login-form-button">注册</Button>
</FormItem>

View File

@ -1,7 +1,10 @@
import React, { Component } from 'react'
// import PropTypes from 'prop-types'
// import { connect } from 'react-redux'
import { Table } from 'antd'
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Table, Button, Modal, Form, Input, Icon, Tooltip } from 'antd';
import { addProject } from '../../../actions/project';
const { TextArea } = Input;
const FormItem = Form.Item;
const columns = [{
title: 'Name',
@ -35,12 +38,147 @@ const data = [{
age: 32
}];
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 6 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 14 }
}
};
@connect(
state => {
return {
loginData: state.login
}
},
{
addProject
}
)
export default class GroupList extends Component {
class ProjectList extends Component {
constructor(props) {
super(props);
this.state = {
visible: false
}
}
static propTypes = {
form: PropTypes.object,
addProject: PropTypes.func
}
addProject = () => {
this.setState({
visible: true
});
}
handleOk = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
this.setState({
visible: false
});
this.props.addProject(values);
}
});
}
handleCancel = () => {
this.props.form.resetFields();
this.setState({
visible: false
});
}
handleSubmit = (e) => {
console.log(e);
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Table columns={columns} dataSource={data} />
<div>
<Modal
title="创建项目"
visible={this.state.visible}
onOk={this.handleOk}
onCancel={this.handleCancel}
>
<Form onSubmit={this.handleSubmit}>
<FormItem
{...formItemLayout}
label="项目名称"
>
{getFieldDecorator('name', {
rules: [{
required: true, message: '请输入项目名称!'
}]
})(
<Input />
)}
</FormItem>
<FormItem
{...formItemLayout}
label={(
<span>
线上域名&nbsp;
<Tooltip title="将根据配置的线上域名访问mock数据">
<Icon type="question-circle-o" />
</Tooltip>
</span>
)}
>
{getFieldDecorator('prd_host', {
rules: [{
required: true, message: '请输入项目线上域名!'
}]
})(
<Input />
)}
</FormItem>
<FormItem
{...formItemLayout}
label="URL"
>
{getFieldDecorator('basepath', {
rules: [{
required: true, message: '请输入项目基本路径!'
}]
})(
<Input />
)}
</FormItem>
<FormItem
{...formItemLayout}
label="描述"
>
{getFieldDecorator('desc', {
rules: [{
required: true, message: '请输入描述!'
}]
})(
<TextArea rows={4} />
)}
</FormItem>
</Form>
</Modal>
<Table
columns={columns}
dataSource={data}
title={() => <Button type="primary" onClick={this.addProject}>创建项目</Button>}
/>
</div>
);
}
}
export default Form.create()(ProjectList);

View File

@ -1,5 +1,5 @@
import Home from './Home/Home.js'
import Login from './Login/loginWrap.js'
import Login from './Login/login-wrap.js'
import ProjectGroups from './ProjectGroups/ProjectGroups.js'
import Interface from './Interface/Interface.js'

View File

@ -1,13 +1,14 @@
import React from 'react'
import { Route, HashRouter } from 'react-router-dom'
import { Home, Login, ProjectGroups, Interface } from './containers/index'
import { Home, ProjectGroups, Interface } from './containers/index'
import Header from './components/Header/Header'
export default () => {
return (
<HashRouter>
<div className="router-main">
<Header/>
<Route path="/" component={ Home } exact />
<Route path="/Login" component={ Login } />
<Route path="/ProjectGroups" component={ ProjectGroups } />
<Route path="/Interface" component={ Interface } />
</div>

View File

@ -0,0 +1,16 @@
{
"errcode": 0,
"errmsg": "success",
"data": [
{
"_id": 101,
"email": "admin@admin.com",
"password": "e00084747ecba89837affe8a048e83c751e44209",
"passsalt": "fmf3kytyysc4swwuqc15rk9",
"role": "admin",
"add_time": 1499932673,
"up_time": 1499932673,
"__v": 0
}
]
}

View File

@ -0,0 +1,34 @@
{
"errcode": 200,
"errmsg": "ok",
"data": {
"project": [
{
"_id": 101,
"name": "project yapi",
"prd_host": "yapi.qunar.com",
"basepath": "/yapi/",
"uid": 101,
"group_id": 193,
"add_time": 1500013365,
"up_time": 1500013365,
"__v": 0,
"env": [],
"members": [
"101"
]
}
],
"group": [
{
"_id": 193,
"group_name": "yapi",
"group_desc": "group yapi",
"uid": 0,
"add_time": 1500013066,
"up_time": 1500013066,
"__v": 0
}
]
}
}

View File

@ -0,0 +1,9 @@
{
"errcode": 0,
"errmsg": "success",
"data": {
"n": 1,
"nModified": 1,
"ok": 1
}
}

View File

@ -0,0 +1,16 @@
{
"errcode": 200,
"errmsg": "ok",
"data": [
{
"_id": 101,
"email": "admin@admin.com",
"password": "3d078af947521bb4a99c93f5e089fc2ac601fa09",
"passsalt": "qc8lnjpnbs9z1vodz4ynfjemi",
"role": "admin",
"add_time": 1499936103,
"up_time": 1499936103,
"__v": 0
}
]
}

View File

@ -7,7 +7,6 @@ import projectModel from '../models/project.js'
class groupController extends baseController{
constructor(ctx){
super(ctx)
console.log('constructor....')
}

View File

@ -1,7 +1,8 @@
import projectModel from '../models/project.js'
import projectModel from '../models/project.js'
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 {
@ -75,7 +76,7 @@ class projectController extends baseController {
}
/**
* 添加项目
* 添加项目成员
* @interface /project/add_member
* @method POST
* @category project
@ -107,7 +108,7 @@ class projectController extends baseController {
}
/**
* 添加项目
* 删除项目成员
* @interface /project/del_member
* @method POST
* @category project
@ -138,6 +139,41 @@ class projectController extends baseController {
ctx.body = yapi.commons.resReturn(null, 402, e.message)
}
}
/**
* 获取项目成员列表
* @interface /project/get_member_list.json
* @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(user);
}
ctx.body = yapi.commons.resReturn(result);
} catch(e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
}
/**
* 添加项目
* @interface /project/get
@ -288,7 +324,7 @@ class projectController extends baseController {
* @foldnumber 10
* @param {String} q
* @return {Object}
* @example
* @example ./api/project/search.json
*/
async search(ctx) {
const { q } = ctx.request.query;

View File

@ -150,22 +150,41 @@ class userController extends baseController{
/**
* 修改用户密码
* @param {*} ctx
* @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;
var userInst = yapi.getInst(userModel);
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(passsalt, passsalt),
password: yapi.commons.generatePassword(params.password, passsalt),
passsalt: passsalt
}
};
try{
let result = await userInst.update(id, data);
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);
@ -368,7 +387,7 @@ class userController extends baseController{
* @foldnumber 10
* @param {String} q
* @return {Object}
* @example
* @example ./api/user/search.json
*/
async search(ctx) {
const { q } = ctx.request.query;

View File

@ -46,7 +46,7 @@ class groupModel extends baseModel{
search(keyword) {
return this.model.find({
name: new RegExp(keyword, 'ig')
group_name: new RegExp(keyword, 'i')
})
.limit(10)
}

View File

@ -52,12 +52,7 @@ class userModel extends baseModel{
update(id,data){
return this.model.update({
_id: id
},{
username: data.username,
email: data.email,
role: data.role,
up_time: yapi.commons.time()
})
}, data)
}
search(keyword) {
return this.model.find({

View File

@ -44,6 +44,7 @@ createAction('user', 'del', 'post', 'del')
createAction('user', 'status', 'get', 'getLoginStatus')
createAction('user', 'logout', 'get', 'logout')
createAction('user', 'login_by_token', 'post', 'loginByToken')
createAction('user', 'change_password', 'post', 'changePassword')
createAction('user', 'search', 'get', 'search')
@ -55,6 +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', 'search', 'get', 'search')
//interface

View File

@ -56,11 +56,7 @@ var groupController = function (_baseController) {
function groupController(ctx) {
(0, _classCallCheck3.default)(this, groupController);
var _this = (0, _possibleConstructorReturn3.default)(this, (groupController.__proto__ || (0, _getPrototypeOf2.default)(groupController)).call(this, ctx));
console.log('constructor....');
return _this;
return (0, _possibleConstructorReturn3.default)(this, (groupController.__proto__ || (0, _getPrototypeOf2.default)(groupController)).call(this, ctx));
}
/**

View File

@ -1,5 +1,9 @@
'use strict';
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
@ -44,6 +48,10 @@ var _interface = require('../models/interface.js');
var _interface2 = _interopRequireDefault(_interface);
var _user = require('../models/user.js');
var _user2 = _interopRequireDefault(_user);
var _group = require('../models/group');
var _group2 = _interopRequireDefault(_group);
@ -193,7 +201,7 @@ var projectController = function (_baseController) {
return add;
}()
/**
* 添加项目
* 添加项目成员
* @interface /project/add_member
* @method POST
* @category project
@ -277,7 +285,7 @@ var projectController = function (_baseController) {
return addMember;
}()
/**
* 添加项目
* 删除项目成员
* @interface /project/del_member
* @method POST
* @category project
@ -360,22 +368,24 @@ var projectController = function (_baseController) {
return delMember;
}()
/**
* 添加项目
* @interface /project/get
* @method GET
* @category project
* @foldnumber 10
* @param {Number} id 项目id不能为空
* @returns {Object}
* @example ./api/project/get.json
*/
* 获取项目成员列表
* @interface /project/get_member_list.json
* @method GET
* @category project
* @foldnumber 10
* @param {Number} id 项目id不能为空
* @return {Object}
* @example ./api/project/get_member_list.json
*/
}, {
key: 'get',
key: 'getMemberList',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
var params, result;
var params, project, userInst, result, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, i, user;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
@ -395,30 +405,155 @@ var projectController = function (_baseController) {
return this.Model.get(params.id);
case 6:
result = _context4.sent;
project = _context4.sent;
userInst = _yapi2.default.getInst(_user2.default);
result = [];
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context4.prev = 12;
_iterator = (0, _getIterator3.default)(project.members);
ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 13;
case 14:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context4.next = 23;
break;
}
i = _step.value;
_context4.next = 18;
return userInst.findById(i);
case 18:
user = _context4.sent;
result.push(user);
case 20:
_iteratorNormalCompletion = true;
_context4.next = 14;
break;
case 10:
_context4.prev = 10;
_context4.t0 = _context4['catch'](3);
case 23:
_context4.next = 29;
break;
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
case 25:
_context4.prev = 25;
_context4.t0 = _context4['catch'](12);
_didIteratorError = true;
_iteratorError = _context4.t0;
case 13:
case 29:
_context4.prev = 29;
_context4.prev = 30;
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 32:
_context4.prev = 32;
if (!_didIteratorError) {
_context4.next = 35;
break;
}
throw _iteratorError;
case 35:
return _context4.finish(32);
case 36:
return _context4.finish(29);
case 37:
ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 43;
break;
case 40:
_context4.prev = 40;
_context4.t1 = _context4['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t1.message);
case 43:
case 'end':
return _context4.stop();
}
}
}, _callee4, this, [[3, 10]]);
}, _callee4, this, [[3, 40], [12, 25, 29, 37], [30,, 32, 36]]);
}));
function get(_x4) {
function getMemberList(_x4) {
return _ref4.apply(this, arguments);
}
return getMemberList;
}()
/**
* 添加项目
* @interface /project/get
* @method GET
* @category project
* @foldnumber 10
* @param {Number} id 项目id不能为空
* @returns {Object}
* @example ./api/project/get.json
*/
}, {
key: 'get',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
params = ctx.request.query;
if (params.id) {
_context5.next = 3;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 3:
_context5.prev = 3;
_context5.next = 6;
return this.Model.get(params.id);
case 6:
result = _context5.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context5.next = 13;
break;
case 10:
_context5.prev = 10;
_context5.t0 = _context5['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message);
case 13:
case 'end':
return _context5.stop();
}
}
}, _callee5, this, [[3, 10]]);
}));
function get(_x5) {
return _ref5.apply(this, arguments);
}
return get;
}()
@ -436,49 +571,49 @@ var projectController = function (_baseController) {
}, {
key: 'list',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var group_id, result;
return _regenerator2.default.wrap(function _callee5$(_context5) {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
group_id = ctx.request.query.group_id;
if (group_id) {
_context5.next = 3;
_context6.next = 3;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
case 3:
_context5.prev = 3;
_context5.next = 6;
_context6.prev = 3;
_context6.next = 6;
return this.Model.list(group_id);
case 6:
result = _context5.sent;
result = _context6.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context5.next = 13;
_context6.next = 13;
break;
case 10:
_context5.prev = 10;
_context5.t0 = _context5['catch'](3);
_context6.prev = 10;
_context6.t0 = _context6['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
case 13:
case 'end':
return _context5.stop();
return _context6.stop();
}
}
}, _callee5, this, [[3, 10]]);
}, _callee6, this, [[3, 10]]);
}));
function list(_x5) {
return _ref5.apply(this, arguments);
function list(_x6) {
return _ref6.apply(this, arguments);
}
return list;
@ -498,78 +633,78 @@ var projectController = function (_baseController) {
}, {
key: 'del',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var id, interfaceInst, count, result;
return _regenerator2.default.wrap(function _callee6$(_context6) {
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context7.prev = _context7.next) {
case 0:
_context6.prev = 0;
_context7.prev = 0;
id = ctx.request.body.id;
if (id) {
_context6.next = 4;
_context7.next = 4;
break;
}
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 4:
interfaceInst = _yapi2.default.getInst(_interface2.default);
_context6.next = 7;
_context7.next = 7;
return interfaceInst.countByProjectId(id);
case 7:
count = _context6.sent;
count = _context7.sent;
if (!(count > 0)) {
_context6.next = 10;
_context7.next = 10;
break;
}
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
case 10:
_context6.next = 12;
_context7.next = 12;
return this.jungeProjectAuth(id);
case 12:
_context6.t0 = _context6.sent;
_context7.t0 = _context7.sent;
if (!(_context6.t0 !== true)) {
_context6.next = 15;
if (!(_context7.t0 !== true)) {
_context7.next = 15;
break;
}
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 15:
_context6.next = 17;
_context7.next = 17;
return this.Model.del(id);
case 17:
result = _context6.sent;
result = _context7.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context6.next = 24;
_context7.next = 24;
break;
case 21:
_context6.prev = 21;
_context6.t1 = _context6['catch'](0);
_context7.prev = 21;
_context7.t1 = _context7['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
case 24:
case 'end':
return _context6.stop();
return _context7.stop();
}
}
}, _callee6, this, [[0, 21]]);
}, _callee7, this, [[0, 21]]);
}));
function del(_x6) {
return _ref6.apply(this, arguments);
function del(_x7) {
return _ref7.apply(this, arguments);
}
return del;
@ -596,65 +731,65 @@ var projectController = function (_baseController) {
}, {
key: 'up',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var id, params, checkRepeat, checkRepeatDomain, data, result;
return _regenerator2.default.wrap(function _callee7$(_context7) {
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context8.prev = _context8.next) {
case 0:
_context7.prev = 0;
_context8.prev = 0;
id = ctx.request.body.id;
params = ctx.request.body;
_context7.next = 5;
_context8.next = 5;
return this.jungeMemberAuth(id, this.getUid());
case 5:
_context7.t0 = _context7.sent;
_context8.t0 = _context8.sent;
if (!(_context7.t0 !== true)) {
_context7.next = 8;
if (!(_context8.t0 !== true)) {
_context8.next = 8;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 8:
if (!params.name) {
_context7.next = 14;
_context8.next = 14;
break;
}
_context7.next = 11;
_context8.next = 11;
return this.Model.checkNameRepeat(params.name);
case 11:
checkRepeat = _context7.sent;
checkRepeat = _context8.sent;
if (!(checkRepeat > 0)) {
_context7.next = 14;
_context8.next = 14;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
case 14:
if (!(params.basepath && params.prd_host)) {
_context7.next = 20;
_context8.next = 20;
break;
}
_context7.next = 17;
_context8.next = 17;
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
case 17:
checkRepeatDomain = _context7.sent;
checkRepeatDomain = _context8.sent;
if (!(checkRepeatDomain > 0)) {
_context7.next = 20;
_context8.next = 20;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
case 20:
data = {
@ -671,32 +806,32 @@ var projectController = function (_baseController) {
}
if (params.env) data.env = params.env;
_context7.next = 27;
_context8.next = 27;
return this.Model.up(id, data);
case 27:
result = _context7.sent;
result = _context8.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context7.next = 34;
_context8.next = 34;
break;
case 31:
_context7.prev = 31;
_context7.t1 = _context7['catch'](0);
_context8.prev = 31;
_context8.t1 = _context8['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t1.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
case 34:
case 'end':
return _context7.stop();
return _context8.stop();
}
}
}, _callee7, this, [[0, 31]]);
}, _callee8, this, [[0, 31]]);
}));
function up(_x7) {
return _ref7.apply(this, arguments);
function up(_x8) {
return _ref8.apply(this, arguments);
}
return up;
@ -710,62 +845,62 @@ var projectController = function (_baseController) {
* @foldnumber 10
* @param {String} q
* @return {Object}
* @example
* @example ./api/project/search.json
*/
}, {
key: 'search',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var q, queryList;
return _regenerator2.default.wrap(function _callee8$(_context8) {
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context9.prev = _context9.next) {
case 0:
q = ctx.request.query.q;
if (q) {
_context8.next = 3;
_context9.next = 3;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
case 3:
if (_yapi2.default.commons.validateSearchKeyword(q)) {
_context8.next = 5;
_context9.next = 5;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
case 5:
_context8.next = 7;
_context9.next = 7;
return this.Model.search(q);
case 7:
_context8.t0 = _context8.sent;
_context8.next = 10;
_context9.t0 = _context9.sent;
_context9.next = 10;
return this.groupModel.search(q);
case 10:
_context8.t1 = _context8.sent;
_context9.t1 = _context9.sent;
queryList = {
project: _context8.t0,
group: _context8.t1
project: _context9.t0,
group: _context9.t1
};
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 200, 'ok'));
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 200, 'ok'));
case 13:
case 'end':
return _context8.stop();
return _context9.stop();
}
}
}, _callee8, this);
}, _callee9, this);
}));
function search(_x8) {
return _ref8.apply(this, arguments);
function search(_x9) {
return _ref9.apply(this, arguments);
}
return search;

View File

@ -346,14 +346,21 @@ var userController = function (_baseController) {
/**
* 修改用户密码
* @param {*} ctx
* @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
*/
}, {
key: 'changePassword',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var params, userInst, passsalt, data, result;
var params, userInst, user, passsalt, data, result;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
@ -362,42 +369,70 @@ var userController = function (_baseController) {
userInst = _yapi2.default.getInst(_user2.default);
if (!(this.getRole() !== 'admin' && params.uid != this.getUid())) {
_context5.next = 4;
_context5.next = 5;
break;
}
console.log(this.getRole(), this.getUid());
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, '没有权限'));
case 4:
case 5:
if (!(this.getRole() !== 'admin')) {
_context5.next = 13;
break;
}
if (params.old_password) {
_context5.next = 8;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '旧密码不能为空'));
case 8:
_context5.next = 10;
return userInst.findById(params.uid);
case 10:
user = _context5.sent;
if (!(_yapi2.default.commons.generatePassword(params.old_password, user.passsalt) !== user.password)) {
_context5.next = 13;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, '旧密码错误'));
case 13:
passsalt = _yapi2.default.commons.randStr();
data = {
up_time: _yapi2.default.commons.time(),
password: _yapi2.default.commons.generatePassword(passsalt, passsalt),
password: _yapi2.default.commons.generatePassword(params.password, passsalt),
passsalt: passsalt
};
_context5.prev = 6;
_context5.next = 9;
return userInst.update(id, data);
_context5.prev = 15;
_context5.next = 18;
return userInst.update(params.uid, data);
case 9:
case 18:
result = _context5.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context5.next = 16;
_context5.next = 25;
break;
case 13:
_context5.prev = 13;
_context5.t0 = _context5['catch'](6);
case 22:
_context5.prev = 22;
_context5.t0 = _context5['catch'](15);
ctx.body = _yapi2.default.commons.resReturn(null, 401, _context5.t0.message);
case 16:
case 25:
case 'end':
return _context5.stop();
}
}
}, _callee5, this, [[6, 13]]);
}, _callee5, this, [[15, 22]]);
}));
function changePassword(_x6) {
@ -648,17 +683,16 @@ var userController = function (_baseController) {
key: 'findById',
value: function () {
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
var userInst, _id, result;
var userInst, id, result;
return _regenerator2.default.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.prev = 0;
userInst = _yapi2.default.getInst(_user2.default);
_id = ctx.request.body.id;
id = ctx.request.body.id;
_context10.next = 5;
return userInst.findById(_id);
return userInst.findById(id);
case 5:
result = _context10.sent;
@ -699,8 +733,7 @@ var userController = function (_baseController) {
key: 'del',
value: function () {
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
var userInst, _id2, result;
var userInst, id, result;
return _regenerator2.default.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
@ -716,9 +749,9 @@ var userController = function (_baseController) {
case 3:
userInst = _yapi2.default.getInst(_user2.default);
_id2 = ctx.request.body.id;
id = ctx.request.body.id;
_context11.next = 7;
return userInst.del(_id2);
return userInst.del(id);
case 7:
result = _context11.sent;
@ -764,15 +797,14 @@ var userController = function (_baseController) {
key: 'update',
value: function () {
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(ctx) {
var userInst, _id3, data, checkRepeat, result;
var userInst, id, data, checkRepeat, result;
return _regenerator2.default.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.prev = 0;
userInst = _yapi2.default.getInst(_user2.default);
_id3 = this.getUid();
id = this.getUid();
data = {
up_time: _yapi2.default.commons.time()
};
@ -800,7 +832,7 @@ var userController = function (_baseController) {
case 12:
_context12.next = 14;
return userInst.update(_id3, data);
return userInst.update(id, data);
case 14:
result = _context12.sent;
@ -838,7 +870,7 @@ var userController = function (_baseController) {
* @foldnumber 10
* @param {String} q
* @return {Object}
* @example
* @example ./api/user/search.json
*/
}, {

View File

@ -98,7 +98,7 @@ var groupModel = function (_baseModel) {
key: 'search',
value: function search(keyword) {
return this.model.find({
name: new RegExp(keyword, 'ig')
group_name: new RegExp(keyword, 'i')
}).limit(10);
}
}]);

View File

@ -108,12 +108,7 @@ var userModel = function (_baseModel) {
value: function update(id, data) {
return this.model.update({
_id: id
}, {
username: data.username,
email: data.email,
role: data.role,
up_time: _yapi2.default.commons.time()
});
}, data);
}
}, {
key: 'search',

View File

@ -71,6 +71,7 @@ createAction('user', 'del', 'post', 'del');
createAction('user', 'status', 'get', 'getLoginStatus');
createAction('user', 'logout', 'get', 'logout');
createAction('user', 'login_by_token', 'post', 'loginByToken');
createAction('user', 'change_password', 'post', 'changePassword');
createAction('user', 'search', 'get', 'search');
//project
@ -81,6 +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', 'search', 'get', 'search');
//interface