Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
a72c4a07
Commit
a72c4a07
authored
Jun 08, 2020
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add courseBack
parent
fcbb2da5
Pipeline
#24661
passed with stage
in 4 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
256 additions
and
42 deletions
+256
-42
back.js
app/controller/course/back.js
+32
-0
backAuth.js
app/middleware/backAuth.js
+23
-0
xmlparse.js
app/middleware/xmlparse.js
+0
-11
courseBackMenu.js
app/model/class/courseBackMenu.js
+43
-0
courseBackUser.js
app/model/class/courseBackUser.js
+43
-0
courseBackUserToMenu.js
app/model/class/courseBackUserToMenu.js
+41
-0
course.js
app/router/course.js
+4
-31
back.js
app/service/course/back.js
+70
-0
No files found.
app/controller/course/back.js
0 → 100644
View file @
a72c4a07
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
class
BackController
extends
Controller
{
// 登录
async
login
()
{
const
{
ctx
,
service
}
=
this
;
const
params
=
ctx
.
request
.
body
;
if
(
ctx
.
isEmpty
(
params
)
||
ctx
.
isEmpty
(
params
.
account
))
{
ctx
.
failed
(
'account is empty'
);
}
if
(
ctx
.
isEmpty
(
params
)
||
ctx
.
isEmpty
(
params
.
password
))
{
ctx
.
failed
(
'password is empty'
);
}
const
ret
=
await
service
.
course
.
back
.
login
(
params
);
ctx
.
success
(
ret
);
}
// 获取菜单
async
getMenuList
()
{
const
{
ctx
,
service
}
=
this
;
const
ret
=
await
service
.
course
.
back
.
getMenuList
();
ctx
.
success
(
ret
);
}
}
module
.
exports
=
BackController
;
app/middleware/backAuth.js
0 → 100644
View file @
a72c4a07
'use strict'
;
module
.
exports
=
()
=>
{
return
async
function
(
ctx
,
next
)
{
const
bearerToken
=
ctx
.
request
.
header
.
authorization
;
ctx
.
logger
.
info
(
'course_headers: '
+
JSON
.
stringify
(
ctx
.
request
.
header
));
if
(
!
bearerToken
)
{
ctx
.
throw
(
401
,
'error auth'
);
}
const
token
=
bearerToken
.
replace
(
'Bearer '
,
''
);
const
decode_res
=
await
ctx
.
service
.
jwt
.
decode_token
(
token
);
ctx
.
logger
.
info
(
'course_back_decode_res: '
+
JSON
.
stringify
(
decode_res
));
if
(
ctx
.
isEmpty
(
decode_res
))
{
ctx
.
throw
(
401
,
'jwt校验失败'
);
}
const
token_black
=
await
ctx
.
app
.
memcache
.
get
(
'course_back_auth_token_'
+
decode_res
.
data
.
user_uuid
);
if
(
token_black
!==
token
)
{
ctx
.
throw
(
401
,
'token不一致'
);
}
ctx
.
setUserUuid
(
decode_res
.
data
.
user_uuid
);
await
next
();
};
};
app/middleware/xmlparse.js
deleted
100644 → 0
View file @
fcbb2da5
'use strict'
;
module
.
exports
=
()
=>
{
return
async
function
(
ctx
,
next
)
{
const
bodyParser
=
require
(
'body-parser'
);
ctx
.
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
,
}));
await
next
();
};
};
app/model/class/courseBackMenu.js
0 → 100644
View file @
a72c4a07
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
}
=
app
.
Sequelize
;
const
CourseBackMenu
=
app
.
classModel
.
define
(
'course_back_menu'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
title
:
STRING
,
path
:
STRING
,
icon
:
STRING
,
parent_id
:
INTEGER
,
is_deleted
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_back_menu'
,
});
return
CourseBackMenu
;
};
app/model/class/courseBackUser.js
0 → 100644
View file @
a72c4a07
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
}
=
app
.
Sequelize
;
const
CourseBackUser
=
app
.
classModel
.
define
(
'course_back_user'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
account
:
STRING
,
password
:
STRING
,
institution_id
:
INTEGER
,
is_admin
:
INTEGER
,
is_deleted
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_back_user'
,
});
return
CourseBackUser
;
};
app/model/class/courseBackUserToMenu.js
0 → 100644
View file @
a72c4a07
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
}
=
app
.
Sequelize
;
const
CourseBackUserToMenu
=
app
.
classModel
.
define
(
'course_back_user_to_menu'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
user_uuid
:
INTEGER
,
menu_id
:
INTEGER
,
is_deleted
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_back_user_to_menu'
,
});
return
CourseBackUserToMenu
;
};
app/router/course.js
View file @
a72c4a07
'use strict'
;
module
.
exports
=
app
=>
{
// const router = app.router.namespace(app.config.projectRootPath + '/course');
// const loginAuth = app.middleware.loginAuth({ type: 'new' });// 登录中间件
// const miniAuth = app.middleware.miniAuth();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件
// router.get('third', '/options', 'course.option.getOptions');// 筛选项
// router.post('third', '/address', miniAuth, 'course.location.getAddress');// 根据经纬度或ip获取地理位置信息
// router.post('third', '/institutions', miniAuth, 'course.institution.institutionList');// 机构列表
// router.get('third', '/institutions', miniAuth, 'course.institution.institutionList');// 机构列表
// router.get('third', '/institution/:institution_id/:area_id', miniAuth, 'course.institution.institutionInfo');// 机构详情
// router.post('third', '/classes', miniAuth, 'course.institution.classList');// 课程列表
// router.get('third', '/classes', miniAuth, 'course.institution.classList');// 课程列表
// router.get('third', '/class/:class_id', miniAuth, 'course.institution.classInfo');// 课程详情
// router.post('third', '/teachers', miniAuth, 'course.institution.teacherList');// 老师列表
// router.get('third', '/teachers', miniAuth, 'course.institution.teacherList');// 老师详情
// router.get('third', '/teacher/:teacher_id', miniAuth, 'course.institution.teacherInfo');// 老师详情
// router.post('third', '/user/auth', 'course.user.auth');// 微信授权登录
// router.post('third', '/user/register_user', miniAuth, 'course.user.registerUserInfo');// 授权后注册用户
// router.get('third', '/user/baby', miniAuth, 'course.user.getBabyInfo');// 获取baby信息
// router.post('third', '/user/baby', miniAuth, 'course.user.saveBabyInfo');// 保存baby信息
// router.delete('third', '/user/baby', miniAuth, 'course.user.delBabyInfo');// 删除baby信息
// router.get('third', '/user/collection/institution', miniAuth, 'course.user.getCollectInstitutions');// 收藏的机构列表
// router.post('third', '/user/collection/institution', miniAuth, 'course.user.collectInstitution');// 收藏机构
// router.delete('third', '/user/collection/institution', miniAuth, 'course.user.delCollectInstitution');// 取消收藏机构
// router.get('third', '/wechat/callbackAction', 'course.wechat.check');
// router.post('third', '/wechat/callbackAction', 'course.wechat.callbackAction');
// router.post('third', '/wechat/test', 'course.wechat.test');
const
router
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
+
'/course/back'
);
const
auth
=
app
.
middleware
.
backAuth
();
router
.
post
(
'third'
,
'/login'
,
'course.back.login'
);
router
.
get
(
'third'
,
'/menu'
,
auth
,
'course.back.getMenuList'
);
};
app/service/course/back.js
0 → 100644
View file @
a72c4a07
'use strict'
;
const
Service
=
require
(
'egg'
).
Service
;
const
R
=
require
(
'ramda'
);
const
_
=
require
(
'lodash'
);
class
BackService
extends
Service
{
// 登录
async
login
(
input
)
{
const
{
ctx
}
=
this
;
const
{
account
,
password
}
=
input
;
const
userInfo
=
await
ctx
.
classModel
.
CourseBackUser
.
findOne
({
where
:
{
account
,
is_deleted
:
0
}
});
if
(
ctx
.
isEmpty
(
userInfo
))
{
ctx
.
failed
(
'用户不存在'
);
}
console
.
log
(
ctx
.
helper
.
md5
(
password
+
'course'
));
if
(
userInfo
.
password
!==
ctx
.
helper
.
md5
(
password
+
'course'
))
{
ctx
.
failed
(
'密码错误'
);
}
const
authToken
=
await
this
.
service
.
jwt
.
apply
({
user_uuid
:
userInfo
.
id
});
await
this
.
app
.
memcache
.
set
(
'course_back_auth_token_'
+
userInfo
.
id
,
authToken
,
3600
);
return
{
auth_token
:
authToken
};
}
// 获取菜单
async
getMenuList
()
{
const
{
ctx
}
=
this
;
const
userUuid
=
ctx
.
userUuid
;
const
userInfo
=
await
ctx
.
classModel
.
CourseBackUser
.
findOne
({
where
:
{
id
:
userUuid
,
is_deleted
:
0
}
});
if
(
ctx
.
isEmpty
(
userInfo
))
{
ctx
.
failed
(
'无效用户'
);
}
let
menuList
=
[];
if
(
userInfo
.
is_admin
>
0
)
{
menuList
=
await
ctx
.
classModel
.
CourseBackMenu
.
findAll
({
where
:
{
is_deleted
:
0
},
attributes
:
[
'id'
,
'title'
,
'path'
,
'icon'
,
'parent_id'
],
raw
:
true
});
}
else
{
const
userToMenuList
=
await
ctx
.
classModel
.
CourseBackUserToMenu
.
findAll
({
where
:
{
user_uuid
:
userUuid
,
is_deleted
:
0
}
});
menuList
=
await
ctx
.
classModel
.
CourseBackMenu
.
findAll
({
where
:
{
id
:
{
$in
:
R
.
pluck
(
'menu_id'
,
userToMenuList
)
},
is_deleted
:
0
},
attributes
:
[
'id'
,
'title'
,
'path'
,
'icon'
,
'parent_id'
],
raw
:
true
});
}
for
(
const
i
in
menuList
)
{
menuList
[
i
].
subs
=
[];
}
const
menu
=
_
.
groupBy
(
menuList
,
'id'
);
for
(
const
v
of
menuList
)
{
if
(
v
.
parent_id
>
0
&&
!
ctx
.
isEmpty
(
menu
[
v
.
parent_id
]))
{
menu
[
v
.
parent_id
][
0
].
subs
.
push
(
v
);
}
}
const
results
=
[];
for
(
const
i
in
menu
)
{
if
(
menu
[
i
][
0
].
parent_id
===
0
)
{
results
.
push
(
menu
[
i
][
0
]);
}
}
return
{
list
:
results
};
}
}
module
.
exports
=
BackService
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment