Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankeegan committed Apr 8, 2018
2 parents 87c1802 + 696a34a commit bce8be9
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 31 deletions.
7 changes: 7 additions & 0 deletions Image-Board.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">

<head>
Expand Down
10 changes: 5 additions & 5 deletions routes/create/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ module.exports = {
message = req.body.message;

Ban.findOne({ ip: ip }, function(err, result) {
if(err) {
if (err) {
return next(err);
}

if(result) {
return next(new Error('Ban with this id already exists!'));
if (result) {
return next(new Error('Ban with this ip already exists!'));
}

let ban = new Ban({ ip: ip, message: message });
ban.save(function(err) {
if(err) {
if (err) {
return next(err);
}
res.json({ message: message, ip: ip});
res.json({ result: { message: message, ip: ip } });
});

});
Expand Down
22 changes: 2 additions & 20 deletions routes/create/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,11 @@ module.exports = {
return next(err);
}

res.json({
result: {
name: name,
board: board,
attachment_name: attachment.originalname,
attachment_path: target_path,
content: content,
title: title,
pinned: pinned
}
});
res.redirect('/' + board + '/thread/' + thread._id);
});
});
} else {
res.json({
result: {
name: name,
board: board,
content: content,
title: title,
pinned: pinned
}
});
res.redirect('/' + board + '/thread/' + thread._id);
}
});
});
Expand Down
17 changes: 17 additions & 0 deletions routes/read/bans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const Bans = require(_base + 'models/ban');

module.exports = {
'/read/bans': {
methods: ['get'],
fn: function(req, res, next) {

Bans.find({}, function(err, results) {
if (err) {
return next(err);
}

res.json({ result: results });
});
}
}
};
14 changes: 14 additions & 0 deletions routes/read/isAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Threads = require(_base + "models/thread");

module.exports = {
'/read/isAuth': {
methods: ['get'],
fn: function(req, res, next) {
if (req.isAuthenticated()) {
res.json({ result: true });
} else {
res.json({ result: false });
}
}
}
};
12 changes: 12 additions & 0 deletions src/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Thread from './components/Thread.vue'
import About from './components/About.vue'
import Login from './components/Login.vue'
import NewThread from './components/NewThread.vue'
import BanList from './components/BanList.vue'
import Ban from './components/Ban.vue'

Vue.use(Router);

Expand Down Expand Up @@ -41,6 +43,16 @@ export default new Router({
path: '/:board/post',
name: 'NewThread',
component: NewThread
},
{
path: '/bans',
name: 'BanList',
component: BanList
},
{
path: '/ban/:ip',
name: 'Ban',
component: Ban
}
]
})
17 changes: 16 additions & 1 deletion src/assets/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ axios.defaults.withCredentials = true;
threadsUrl: 'read/threads',
boardUrl: 'read/board',
threadUrl: 'read/thread',
repliesUrl: 'read/replies'
repliesUrl: 'read/replies',
bansUrl: 'read/bans',
isAuthUrl: 'read/isAuth',
banUrl: 'create/ban'
};
function url(api) {
return root + urls[api];
Expand Down Expand Up @@ -66,4 +69,16 @@ axios.defaults.withCredentials = true;
_api.logout = function(fn) {
post(url('logoutUrl'), {}, fn);
};

_api.bans = function (fn) {
get(url('bansUrl'), {}, fn);
};

_api.isAuth = function (fn) {
get(url('isAuthUrl'), {}, fn);
};

_api.ban = function (ip, message, fn) {
post(url('banUrl'), { ip: ip, message: message }, fn);
};
})();
49 changes: 49 additions & 0 deletions src/components/Ban.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="ban">
<tbody>
<tr data-type="IP">
<td>IP</td>
<td><input id="ip" name="ip" type="text" v-model="ip"></td>
</tr>
<tr data-type="Message">
<td>Message</td>
<td><textarea name="message" cols="48" rows="4" wrap="soft" tabindex="4" v-model="message"></textarea></td>
</tr>
</tbody>
<input type="button" v-on:click="ban" value="Ban">
<p v-text="error"></p>
</div>
</template>

<style scoped></style>

<script>
export default {
data() {
return {
ip: this.$route.params.ip,
message: '',
error: ''
}
},
methods: {
ban() {
let vm = this;
_api.ban(this.ip, this.message, function (err, res) {
if (err) {
console.log(err);
vm.error = err;
vm.error = err.message;
}
else if (res.error) {
console.log(res.error);
vm.error = res.error;
}
else if (res.result) {
vm.$router.push('/bans');
}
});
}
}
}
</script>
105 changes: 105 additions & 0 deletions src/components/BanList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<div class="banlist">
<header>
<h1 id="title">Image Board Bans</h1>
<div id="description">
The purpose of this page is to give users insight into what content is being removed, and why.
<br>
Below are the recent bans.
<br>
<br>
Don't be stupid.
</div>
</header>
<table id="ban-entries">
<thead>
<tr>
<th class="col-ip">IP</th>
<th class="col-message">Reason</th>
<th class="Time">Time</th>
</tr>
</thead>
<tbody>
<tr v-for="ban in bans">
<td>{{ ban.ip }}</td>
<td>{{ ban.message }}</td>
<td>{{ new Date(ban.time) }}</td>
</tr>
</tbody>
</table>
</div>
</template>

<style scoped>
.banlist {
font-family: 'Helvetica Neue', arial, sans-serif;
margin: 5px 0 5px 0;
padding: 0 5px;
font-size: 13px;
background: #eef2ff url(http://s.4cdn.org/image/fade-blue.png) top center repeat-x;
}
#description {
margin-top: 20px;
}
header {
text-align: center;
color: #AF0A0F;
}
#ban-entries {
table-layout: fixed;
background-color: #fff;
cursor: default;
margin: auto;
margin-top: 30px;
background-color: #eef2ff;
}
#ban-entries th {
background-color: #C0C7DE;
}
table, td, th, tr {
border-collapse: collapse;
border: 1px solid black;
text-align: center;
}
#title {
margin-top: 20px;
font-size: 28px;
font-weight: bold;
letter-spacing: -2px;
}
</style>

<script>
export default {
name: 'BanList',
data () {
return {
bans: []
}
},
created() {
let vm = this;
vm.updateBans();
},
beforeRouteUpdate (to, from, next) {
let vm = this;
vm.updateBans();
next();
},
methods: {
updateBans() {
let vm = this;
_api.bans(function (err, res) {
if (err) {
console.log(err);
vm.bans = [];
}
else if (res.result) {
vm.bans = res.result;
}
});
}
}
}
</script>
2 changes: 1 addition & 1 deletion src/components/NewThread.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</form>
</template>

<style>
<style scoped>
</style>

Expand Down
Loading

0 comments on commit bce8be9

Please sign in to comment.