User delete feature

pull/33/head v1.0-beta.3
NGPixel 8 years ago
parent 1fe7b68144
commit c6853a0315

@ -7,5 +7,5 @@ charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
[*.{jade,pug}] [*.{jade,pug,md}]
trim_trailing_whitespace = false trim_trailing_whitespace = false

@ -3,10 +3,13 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] ## [Unreleased]
## [v1.0-beta.3] - 2017-02-10
### Added ### Added
- Change log - Change log
- Added .editorconfig, .eslintrc.json and .pug-lintrc.json for code linting - Added .editorconfig, .eslintrc.json and .pug-lintrc.json for code linting
- Added Create / Authorize User feature - Added Create / Authorize User feature
- Added Delete / De-authorize User feature
- Added Login as... button to Forbidden page - Added Login as... button to Forbidden page
### Fixed ### Fixed
@ -16,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed ### Changed
- Updated dependencies + snyk policy - Updated dependencies + snyk policy
- Conversion to Standard JS compliant code - Conversion to Standard JS compliant code
- Accounts that are not pre-authorized are no longer added with no rights
## [v1.0-beta.2] - 2017-01-30 ## [v1.0-beta.2] - 2017-01-30
### Added ### Added
@ -24,5 +28,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed ### Changed
- Updated dependencies + snyk policy - Updated dependencies + snyk policy
[Unreleased]: https://github.com/Requarks/wiki/compare/v1.0-beta.2...HEAD [Unreleased]: https://github.com/Requarks/wiki/compare/v1.0-beta.3...HEAD
[v1.0-beta.3]: https://github.com/Requarks/wiki/releases/tag/v1.0-beta.3
[v1.0-beta.2]: https://github.com/Requarks/wiki/releases/tag/v1.0-beta.2 [v1.0-beta.2]: https://github.com/Requarks/wiki/releases/tag/v1.0-beta.2

@ -11,6 +11,7 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1d0217a3153c4595bdedb322263e55c8)](https://www.codacy.com/app/Requarks/wiki) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/1d0217a3153c4595bdedb322263e55c8)](https://www.codacy.com/app/Requarks/wiki)
[![Dependency Status](https://gemnasium.com/badges/github.com/Requarks/wiki.svg)](https://gemnasium.com/github.com/Requarks/wiki) [![Dependency Status](https://gemnasium.com/badges/github.com/Requarks/wiki.svg)](https://gemnasium.com/github.com/Requarks/wiki)
[![Known Vulnerabilities](https://snyk.io/test/github/requarks/wiki/badge.svg)](https://snyk.io/test/github/requarks/wiki) [![Known Vulnerabilities](https://snyk.io/test/github/requarks/wiki/badge.svg)](https://snyk.io/test/github/requarks/wiki)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
##### A modern, lightweight and powerful wiki app built on NodeJS, Git and Markdown ##### A modern, lightweight and powerful wiki app built on NodeJS, Git and Markdown
*Under active development* *Under active development*

File diff suppressed because one or more lines are too long

@ -1,11 +1,11 @@
/* global $, Vue */ /* global $, Vue, usrData, alerts */
// Vue Delete User instance // Vue Delete User instance
let vueDeleteUser = new Vue({ let vueDeleteUser = new Vue({
el: '#modal-admin-users-delete', el: '#modal-admin-users-delete',
data: { data: {
loading: false
}, },
methods: { methods: {
open: (ev) => { open: (ev) => {
@ -15,7 +15,18 @@ let vueDeleteUser = new Vue({
$('#modal-admin-users-delete').removeClass('is-active') $('#modal-admin-users-delete').removeClass('is-active')
}, },
deleteUser: (ev) => { deleteUser: (ev) => {
vueDeleteUser.loading = true
$.ajax('/admin/users/' + usrData._id, {
dataType: 'json',
method: 'DELETE'
}).then((rData, rStatus, rXHR) => {
vueDeleteUser.loading = false
vueDeleteUser.cancel() vueDeleteUser.cancel()
window.location.assign('/admin/users')
}, (rXHR, rStatus, err) => {
vueDeleteUser.loading = false
alerts.pushError('Error', rXHR.responseJSON.msg)
})
} }
} }
}) })

@ -194,6 +194,25 @@ router.post('/users/:id', (req, res) => {
}) })
}) })
/**
* Delete / Deauthorize a user
*/
router.delete('/users/:id', (req, res) => {
if (!res.locals.rights.manage) {
return res.status(401).json({ msg: 'Unauthorized' })
}
if (!validator.isMongoId(req.params.id)) {
return res.status(400).json({ msg: 'Invalid User ID' })
}
return db.User.findByIdAndRemove(req.params.id).then(() => {
return res.json({ msg: 'OK' })
}).catch((err) => {
res.status(500).json({ msg: err.message })
})
})
router.get('/settings', (req, res) => { router.get('/settings', (req, res) => {
if (!res.locals.rights.manage) { if (!res.locals.rights.manage) {
return res.render('error-forbidden') return res.render('error-forbidden')

@ -63,10 +63,9 @@ userSchema.statics.processProfile = (profile) => {
providerId: profile.id, providerId: profile.id,
name: profile.displayName || _.split(primaryEmail, '@')[0] name: profile.displayName || _.split(primaryEmail, '@')[0]
}, { }, {
new: true, new: true
upsert: true
}).then((user) => { }).then((user) => {
return user || Promise.reject(new Error('User Upsert failed.')) return user || Promise.reject(new Error('You have not been authorized to login to this site yet.'))
}) })
} }

@ -83,7 +83,7 @@
"pug": "^2.0.0-beta11", "pug": "^2.0.0-beta11",
"read-chunk": "^2.0.0", "read-chunk": "^2.0.0",
"remove-markdown": "^0.1.0", "remove-markdown": "^0.1.0",
"requarks-core": "^0.2.0", "requarks-core": "^0.2.1",
"request": "^2.79.0", "request": "^2.79.0",
"search-index": "^0.9.9", "search-index": "^0.9.9",
"serve-favicon": "^2.3.2", "serve-favicon": "^2.3.2",

@ -2,7 +2,9 @@
.modal-background .modal-background
.modal-container .modal-container
.modal-content .modal-content
header.is-red Delete User Account? header.is-red
span Delete User Account?
p.modal-notify(v-bind:class='{ "is-active": loading }'): i
section section
span Are you sure you want to delete this user account? This action cannot be undone! span Are you sure you want to delete this user account? This action cannot be undone!
footer footer

Loading…
Cancel
Save