Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pec9399 authored Jun 5, 2018
2 parents 1f58b58 + 9c7730a commit 33b3d46
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 33 deletions.
2 changes: 1 addition & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ app.use('/*', function (req, res, next) {
})
*/

// 라우팅
// 라우팅
app.use('/rest/', index);
app.use('/rest/admin', admin);
app.use('/rest/user', user);
Expand Down
3 changes: 2 additions & 1 deletion server/models/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module.exports = (sequelize, DataTypes) => {
const todo = sequelize.define('todo', {
tdid: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
allowNull: false,
comment: '아이디'
},
component: {
Expand Down
33 changes: 33 additions & 0 deletions server/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,37 @@ router.put('/users', wrap(async (req, res) => {
res.status(500).send('error');
}));

// 선택한 수행원의 정보 전체 및 소속 프로젝트 이름과 pid 리스트
router.get('/user/:uid', wrap(async (req, res) => {
if (req.session.user.auth === 1) {
const user = await models.user.findOne({
where: { uid: req.params.uid },
attributes: ['uid', 'name', 'auth', 'email', 'ph']
});
const project = await models.assign_r.findAll({
where: { uid: req.params.uid },
attributes: ['pid'],
include: [{ model: models.project, attributes: ['name'] }]
});
if (user && project) {
res.send({ user, project });
}
} else {
res.status(500).send('error');
}
}));

// 선택한 유저 삭제
router.delete('/user/:uid', wrap(async (req, res) => {
console.log('delete');
const destroy = await models.user.destroy({
where: { uid: req.params.uid }
});
if (destroy) {
res.send({
result: true
});
}
}));

module.exports = router;
49 changes: 19 additions & 30 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,21 @@ router.get('/', (req, res) => {

// login
router.post('/login', wrap(async (req, res) => {
try {
const user = await models.user.findOne({
where: {
uid: req.body.uid,
pw: req.body.pw
}
});
if (user !== null) {
req.session.user = user.dataValues; // 세션 생성
req.session.user.time = new Date();
req.session.user.ip = req.connection.remoteAddress;
delete req.session.user.pw;
req.session.user.result = true; // 로그인 성공 시 true
res.send(req.session.user);
} else {
res.send({ result: false });
const user = await models.user.findOne({
where: {
uid: req.body.uid,
pw: req.body.pw
}
} catch (e) {
res.send({
result: false
});
});
if (user !== null) {
req.session.user = user.dataValues; // 세션 생성
req.session.user.time = new Date();
req.session.user.ip = req.connection.remoteAddress;
delete req.session.user.pw;
req.session.user.result = true; // 로그인 성공 시 true
res.send(req.session.user);
} else {
res.status(500).send('error');
}
}));

Expand All @@ -54,18 +48,13 @@ router.get('/logout', wrap(async (req, res) => {
}
}));


// load session
router.get('/session', wrap(async (req, res) => {
try {
const session = await req.session.user;
if (session) {
res.send(session);
}
} catch (e) {
res.send({
result: false
});
const session = await req.session.user;
if (session) {
res.send(session);
} else {
res.status(500).send('error');
}
}));

Expand Down
40 changes: 40 additions & 0 deletions server/routes/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,46 @@ router.put('/:uid/:pid/:tdid', wrap(async (req, res) => {
}
}));

// todo 제거(PM과 ADMIN만 가능)
router.delete('/:pid/:tdid', wrap(async (req, res) => {
if (req.session.user.auth === 1) {
const destroy = await models.todo.destroy({
where: { tdid: req.params.tdid }
});
if (destroy) {
res.send({
result: true
});
}
} else if (req.session.user.auth === 2) {
const todo = await models.todo.findOne({
where: {
tdid: req.params.tdid
},
include: ['project']
});
if (todo.project.uid === req.session.user.uid) {
const destroy = await models.todo.destroy({
where: { tdid: req.params.tdid }
});
if (destroy) {
res.send({
result: true
});
}
} else {
res.send({
result: false
});
}
} else {
res.send({
result: false
});
}
}));


// Todo 상세 정보 불러옴(get방식으로)
router.get('/:uid/:pid/:tdid', wrap(async (req, res) => {
const list = await models.list.findAll({
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/login.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 백엔드에 인증 시도
$http.post('/rest/login', {
uid: vm.uid,
pw: SHA256(vm.pw)
pw: vm.pw
}).then((result) => {
if (result.data.result) {
$window.location.assign('/main');
Expand Down

0 comments on commit 33b3d46

Please sign in to comment.