Skip to content

Commit

Permalink
6.5.인증구현-로그인상태 UI를 반영 2
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed Jul 29, 2018
1 parent 0b7cd60 commit 02316d8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
16 changes: 16 additions & 0 deletions lib/auth.js
@@ -0,0 +1,16 @@
module.exports = {
isOwner:function(request, response) {
if (request.session.is_logined) {
return true;
} else {
return false;
}
},
statusUI:function(request, response) {
var authStatusUI = '<a href="/auth/login">login</a>'
if (this.isOwner(request, response)) {
authStatusUI = `${request.session.nickname} | <a href="/auth/logout">logout</a>`;
}
return authStatusUI;
}
}
19 changes: 2 additions & 17 deletions routes/index.js
@@ -1,22 +1,7 @@
var express = require('express');
var router = express.Router();
var template = require('../lib/template.js');

function authIsOwner(request, response) {
if (request.session.is_logined) {
return true;
} else {
return false;
}
}

function authStatusUI(request, response){
var authStatusUI = '<a href="/auth/login">login</a>'
if(authIsOwner(request, response)){
authStatusUI = `${request.session.nickname} | <a href="/auth/logout">logout</a>`;
}
return authStatusUI;
}
var auth = require('../lib/auth');

router.get('/', function (request, response) {
var title = 'Welcome';
Expand All @@ -28,7 +13,7 @@ router.get('/', function (request, response) {
<img src="/images/hello.jpg" style="width:300px; display:block; margin-top:10px;">
`,
`<a href="/topic/create">create</a>`,
authStatusUI(request, response)
auth.statusUI(request, response)
);
response.send(html);
});
Expand Down
9 changes: 6 additions & 3 deletions routes/topic.js
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var fs = require('fs');
var sanitizeHtml = require('sanitize-html');
var template = require('../lib/template.js');
var auth = require('../lib/auth');

router.get('/create', function(request, response){
var title = 'WEB - create';
Expand All @@ -18,7 +19,7 @@ router.get('/create', function(request, response){
<input type="submit">
</p>
</form>
`, '');
`, '', auth.statusUI(request, response));
response.send(html);
});

Expand Down Expand Up @@ -49,7 +50,8 @@ router.get('/create', function(request, response){
</p>
</form>
`,
`<a href="/topic/create">create</a> <a href="/topic/update/${title}">update</a>`
`<a href="/topic/create">create</a> <a href="/topic/update/${title}">update</a>`,
auth.statusUI(request, response)
);
response.send(html);
});
Expand Down Expand Up @@ -95,7 +97,8 @@ router.get('/create', function(request, response){
<form action="/topic/delete_process" method="post">
<input type="hidden" name="id" value="${sanitizedTitle}">
<input type="submit" value="delete">
</form>`
</form>`,
auth.statusUI(request, response)
);
response.send(html);
}
Expand Down

0 comments on commit 02316d8

Please sign in to comment.