-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtweets.js
More file actions
113 lines (101 loc) · 2.47 KB
/
tweets.js
File metadata and controls
113 lines (101 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function getCookie(name) {
return document.cookie.split(';').filter(function(item) {
return item.indexOf(name) !== -1;
})[0];
};
$(document).ready(function() {
var accessToken = (getCookie('token') || '').split('=')[1];
var paramArr = (window.location.search.split('?')[1] || '').split('&');
var userId = '';
paramArr.forEach(function (param) {
if (param.indexOf('userid') !== -1) {
userId = param.split('=')[1];
}
})
if (userId) {
$('.userId')
.append(userId);
}
if (accessToken) {
$.ajax({
method: 'GET',
url: 'http://127.0.0.1:5000/timeline',
headers: {
'Authorization': accessToken
}
})
.done(function(msg) {
var timeline = msg.timeline;
if (timeline) {
timeline.forEach(function (item) {
$('.timeline-container')
.append('<div class="card">' +
'<div class="card-body">' +
'<h5 class="card-title">'+item.user_id+'</h5>' +
'<p class="card-text">'+item.tweet+'</p></div>' +
'</div>')
})
}
});
} else {
alert('로그인이 필요합니다.');
window.location.href = './login.html';
return;
}
$('#tweetForm').submit(function(e) {
e.preventDefault();
// if (!myId) {
if (!accessToken) {
alert('로그인이 필요합니다.');
window.location.href = './login.html';
return;
}
var tweet = $('#tweet').val();
$.ajax({
method: 'POST',
url: 'http://localhost:5000/tweet',
headers: {
'Authorization': accessToken
},
data: JSON.stringify({
"tweet" : tweet
}),
contentType: 'application/json'
})
.done(function(msg) {
console.log(msg)
});
});
$('#follow').on('click', function () {
$.ajax({
method: 'POST',
url: 'http://localhost:5000/follow',
headers: {
'Authorization': accessToken
},
data: JSON.stringify({
"follow" : userId
}),
contentType: 'application/json'
})
.done(function(msg) {
console.log(msg)
});
});
$('#unfollow').on('click', function () {
$.ajax({
method: 'POST',
url: 'http://localhost:5000/unfollow',
headers: {
'Authorization': accessToken
},
data: JSON.stringify({
"unfollow" : userId
}),
contentType: 'application/json'
})
.done(function(msg) {
console.log(msg)
});
});
});