More updates
This commit is contained in:
parent
18c7c25eed
commit
cc025b2393
14 changed files with 140 additions and 17 deletions
|
@ -18,7 +18,7 @@ export function restrict(level = orgAccess.Normal) {
|
||||||
return ctx.throw(403, 'Authentication token was not found (did you forget to login?)')
|
return ctx.throw(403, 'Authentication token was not found (did you forget to login?)')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.state.user || !ctx.state.user.id || !ctx.state.user.level) {
|
if (!ctx.state.user || !ctx.state.user.email || !ctx.state.user.level) {
|
||||||
return ctx.throw(403, 'You must be authenticated to access this resource')
|
return ctx.throw(403, 'You must be authenticated to access this resource')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,7 @@ export default class Jwt {
|
||||||
static jwtMiddleware() {
|
static jwtMiddleware() {
|
||||||
return koaJwt({
|
return koaJwt({
|
||||||
secret: (header, payload) =>
|
secret: (header, payload) =>
|
||||||
Staff.getSingle(payload.id)
|
`${config.get('jwt:secret')}${payload.email}`,
|
||||||
.then(staff => `${config.get('jwt:secret')}${staff.get('password')}`),
|
|
||||||
passthrough: true,
|
passthrough: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import http from 'http'
|
import http from 'http'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import Agent from 'socks5-http-client/lib/Agent'
|
||||||
|
|
||||||
let stub
|
let stub
|
||||||
|
|
||||||
|
@ -38,6 +39,11 @@ export function uploadFile(token, file) {
|
||||||
'Content-Type': 'multipart/form-data; boundary=' + boundary,
|
'Content-Type': 'multipart/form-data; boundary=' + boundary,
|
||||||
'Content-Length': multipartBody.length,
|
'Content-Length': multipartBody.length,
|
||||||
},
|
},
|
||||||
|
agentClass: Agent,
|
||||||
|
agentOptions: {
|
||||||
|
socksHost: '127.0.0.1',
|
||||||
|
socksPort: 5555,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const req = http.request(options)
|
const req = http.request(options)
|
||||||
|
|
|
@ -21,6 +21,11 @@ article.editcat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileupload {
|
||||||
|
margin: 0 20px 20px;
|
||||||
|
min-height: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
form {
|
form {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
|
@ -31,7 +36,7 @@ article.editcat {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-spinner {
|
& > .loading-spinner {
|
||||||
width: 240px;
|
width: 240px;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const m = require('mithril')
|
const m = require('mithril')
|
||||||
const Authentication = require('../authentication')
|
const Authentication = require('../authentication')
|
||||||
|
const FileUpload = require('../widgets/fileupload')
|
||||||
|
|
||||||
const EditCategory = {
|
const EditCategory = {
|
||||||
loading: true,
|
loading: true,
|
||||||
|
@ -16,7 +17,9 @@ const EditCategory = {
|
||||||
: m('div.admin-wrapper',
|
: m('div.admin-wrapper',
|
||||||
m('article.editcat', [
|
m('article.editcat', [
|
||||||
m('header', m('h1', 'Edit category')),
|
m('header', m('h1', 'Edit category')),
|
||||||
|
m(FileUpload),
|
||||||
m('form.editcat', [
|
m('form.editcat', [
|
||||||
|
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
20
app/api/common.js
Normal file
20
app/api/common.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
const m = require('mithril')
|
||||||
|
const Authentication = require('../authentication')
|
||||||
|
|
||||||
|
exports.sendRequest = function(options) {
|
||||||
|
let token = Authentication.getToken()
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
options.headers = options.headers || {}
|
||||||
|
options.headers['Authorization'] = 'Bearer ' + token
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.request(options)
|
||||||
|
.catch(function (error) {
|
||||||
|
if (error.code === 403) {
|
||||||
|
Authentication.clearToken()
|
||||||
|
m.route.set('/login', { redirect: m.route.get() })
|
||||||
|
}
|
||||||
|
return Promise.reject(error)
|
||||||
|
})
|
||||||
|
}
|
13
app/api/media.js
Normal file
13
app/api/media.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
const m = require('mithril')
|
||||||
|
const { sendRequest } = require('./common')
|
||||||
|
|
||||||
|
exports.uploadMedia = function(file) {
|
||||||
|
let formData = new FormData()
|
||||||
|
formData.append('file', file)
|
||||||
|
|
||||||
|
return sendRequest({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/api/media',
|
||||||
|
data: formData,
|
||||||
|
})
|
||||||
|
}
|
|
@ -110,3 +110,4 @@ article {
|
||||||
@import 'menu/menu';
|
@import 'menu/menu';
|
||||||
@import 'login/login';
|
@import 'login/login';
|
||||||
@import 'admin/admin';
|
@import 'admin/admin';
|
||||||
|
@import 'widgets/common';
|
||||||
|
|
|
@ -44,13 +44,13 @@ const Authentication = {
|
||||||
gscript.src = 'https://apis.google.com/js/platform.js?onload=googleLoaded'
|
gscript.src = 'https://apis.google.com/js/platform.js?onload=googleLoaded'
|
||||||
document.body.appendChild(gscript)
|
document.body.appendChild(gscript)
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
|
||||||
|
getToken: function() {
|
||||||
|
return localStorage.getItem(storageName)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Authentication.updateToken(localStorage.getItem(storageName))
|
Authentication.updateToken(localStorage.getItem(storageName))
|
||||||
|
|
||||||
if (Authentication.currentUser) {
|
|
||||||
// Authentication.createGoogleScript()
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Authentication
|
module.exports = Authentication
|
||||||
|
|
|
@ -4,6 +4,7 @@ const Authentication = require('../authentication')
|
||||||
const Login = {
|
const Login = {
|
||||||
loadedGoogle: false,
|
loadedGoogle: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
redirect: '',
|
||||||
error: '',
|
error: '',
|
||||||
|
|
||||||
initGoogleButton: function() {
|
initGoogleButton: function() {
|
||||||
|
@ -29,7 +30,7 @@ const Login = {
|
||||||
})
|
})
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
Authentication.updateToken(result.token)
|
Authentication.updateToken(result.token)
|
||||||
m.route.set('/')
|
m.route.set(Login.redirect || '/')
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
Login.error = 'Error while logging into NFP! ' + error.code + ': ' + error.response.message
|
Login.error = 'Error while logging into NFP! ' + error.code + ': ' + error.response.message
|
||||||
|
@ -48,7 +49,8 @@ const Login = {
|
||||||
Authentication.createGoogleScript()
|
Authentication.createGoogleScript()
|
||||||
},
|
},
|
||||||
|
|
||||||
oninit: function() {
|
oninit: function(vnode) {
|
||||||
|
Login.redirect = vnode.attrs.redirect || ''
|
||||||
if (Authentication.currentUser) return m.route.set('/')
|
if (Authentication.currentUser) return m.route.set('/')
|
||||||
Login.error = ''
|
Login.error = ''
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
fileupload {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: stretch;
|
||||||
|
|
||||||
|
.showicon,
|
||||||
|
.display {
|
||||||
|
border: 3px solid $title-fg;
|
||||||
|
border-style: dashed;
|
||||||
|
flex-grow: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.showicon {
|
||||||
|
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHaSURBVHhe7dfPScRAAIXxFSxAPHjUkrx61DaswCJsw5MdCDYkgs6DDIQlu5l/Sd5Ovh88WDJ7yPCdcgAAAAAAAEDvHofBwFPYzzD9xoaew37D/obpt55hAy9h4xjjKDrDik7FiCPKiuZixBFlBakx4oiyoNwYcURZQGmMOKI0VBsjjigNtIoRR5QKrWPEEaVASoyPiWdx5840omRIifEe9nD0bDyd6T9TZ3FESZAa4yrsfvTseDrTf4hSISeGzAURohTKjSEpQYQomUpiSGoQIUqi0hiSE0SIMqMmhuQGEaKcUBtDSoIIUY60iCGlQYQog1YxpCaI7D5KyxhSG0R2G+U67Cts6sJxOTGkRRBJiaJ31x26chv2HTZ14dwY0iqInIuid9a7d2kqSkkMaRlEpqJ0HSMaRymNIa2DyDjKLmJEuuhrWGkMWSKI6J30bruJ0cpSQVCIIGYIYoYgZghihiBmCGKGIGYIYoYgZghihiBmCGKGIGYIYoYgZghihiBmCGKGIGYIYoYgZghihiBmCGKGIGYIYoYgZghihiBmCGKGIGYIYoYgZggCAACAjd2FfXY+3fFinPtG6GUX9a1DEDMEMUMQMwQxcxP21vl0RwAAAAAAAGCnDod/1p4xx4l+w0cAAAAASUVORK5CYII=');
|
||||||
|
background-position: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-size: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.display {
|
||||||
|
border: none;
|
||||||
|
background-size: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: #33333388;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
opacity: 0.01;
|
||||||
|
width: 100%;
|
||||||
|
cursor: pointer;
|
||||||
|
text-indent: -9999px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,27 @@
|
||||||
const m = require('mithril')
|
const m = require('mithril')
|
||||||
|
const { uploadMedia } = require('../api/media')
|
||||||
|
|
||||||
|
const FileUpload = {
|
||||||
|
uploadFile(vnode, event) {
|
||||||
|
if (!event.target.files[0]) return
|
||||||
|
vnode.state.loading = true
|
||||||
|
|
||||||
|
uploadMedia(event.target.files[0])
|
||||||
|
.then(function(res) {
|
||||||
|
vnode.state.media = res
|
||||||
|
console.log(vnode.state.media)
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
vnode.state.loading = false
|
||||||
|
m.redraw()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
const Login = {
|
|
||||||
oninit: function(vnode) {
|
oninit: function(vnode) {
|
||||||
|
vnode.state.loading = false
|
||||||
vnode.state.media = null
|
vnode.state.media = null
|
||||||
vnode.state.error = ''
|
vnode.state.error = ''
|
||||||
},
|
},
|
||||||
|
@ -11,16 +31,22 @@ const Login = {
|
||||||
|
|
||||||
return m('fileupload', [
|
return m('fileupload', [
|
||||||
(media ?
|
(media ?
|
||||||
m('a', {
|
m('a.display', {
|
||||||
href: media.large_url,
|
href: media.large_url,
|
||||||
style: {
|
style: {
|
||||||
'background-image': 'url(' + media.medium_url + ')',
|
'background-image': 'url(' + media.medium_url + ')',
|
||||||
}
|
}
|
||||||
}) :
|
}) :
|
||||||
m('div.empty')
|
m('div.showicon')
|
||||||
),
|
),
|
||||||
|
m('input', {
|
||||||
|
accept: 'image/*',
|
||||||
|
type: 'file',
|
||||||
|
onchange: FileUpload.uploadFile.bind(this, vnode),
|
||||||
|
}),
|
||||||
|
(vnode.state.loading ? m('div.loading-spinner') : null),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Login
|
module.exports = FileUpload
|
||||||
|
|
|
@ -38,6 +38,6 @@
|
||||||
"fileSize": 524288000,
|
"fileSize": 524288000,
|
||||||
"upload": {
|
"upload": {
|
||||||
"name": "nfpmoe-dev",
|
"name": "nfpmoe-dev",
|
||||||
"secret": "TJlAbWgpQy0zMGu01XoW"
|
"secret": "nfpmoe-dev"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,8 @@
|
||||||
"multer": "^1.4.1",
|
"multer": "^1.4.1",
|
||||||
"nconf": "^0.10.0",
|
"nconf": "^0.10.0",
|
||||||
"pg": "^7.8.0",
|
"pg": "^7.8.0",
|
||||||
"sharp": "^0.21.3"
|
"sharp": "^0.21.3",
|
||||||
|
"socks5-http-client": "^1.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "^16.2.3",
|
"browserify": "^16.2.3",
|
||||||
|
|
Loading…
Reference in a new issue