2
0
Эх сурвалжийг харах

Added own profile save + dependencies update

NGPixel 8 жил өмнө
parent
commit
f2dd84a0e4

+ 2 - 1
agent.js

@@ -42,6 +42,7 @@ var _ = require('lodash');
 var moment = require('moment');
 var Promise = require('bluebird');
 var fs = Promise.promisifyAll(require("fs-extra"));
+var klaw = require('klaw');
 var path = require('path');
 var cron = require('cron').CronJob;
 
@@ -92,7 +93,7 @@ var job = new cron({
 							jobCbStreamDocs_resolve = resolve;
 						});
 
-				fs.walk(repoPath).on('data', function (item) {
+				klaw(repoPath).on('data', function (item) {
 					if(path.extname(item.path) === '.md' && path.basename(item.path) !== 'README.md') {
 
 						let entryPath = entries.parsePath(entries.getEntryPathFromFullPath(item.path));

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
assets/js/app.js


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
assets/js/libs.js


+ 31 - 1
client/js/pages/admin.js

@@ -1,5 +1,35 @@
 
-if($('#page-type-admin-users').length) {
+if($('#page-type-admin-profile').length) {
+
+	let vueProfile = new Vue({
+		el: '#page-type-admin-profile',
+		data: {
+			password: '********',
+			passwordVerify: '********',
+			name: ''
+		},
+		methods: {
+			saveUser: (ev) => {
+				if(vueProfile.password !== vueProfile.passwordVerify) {
+					alerts.pushError('Error', "Passwords don't match!");
+					return;
+				}
+				$.post(window.location.href, {
+					password: vueProfile.password,
+					name: vueProfile.name
+				}).done((resp) => {
+					alerts.pushSuccess('Saved successfully', 'Changes have been applied.');
+				}).fail((jqXHR, txtStatus, resp) => {
+					alerts.pushError('Error', resp);
+				})
+			}
+		},
+		created: function() {
+			this.name = usrDataName;
+		}
+	});
+
+} else if($('#page-type-admin-users').length) {
 
 	//=include ../modals/admin-users-create.js
 

+ 29 - 0
controllers/admin.js

@@ -23,6 +23,35 @@ router.get('/profile', (req, res) => {
 
 });
 
+router.post('/profile', (req, res) => {
+
+	if(res.locals.isGuest) {
+		return res.render('error-forbidden');
+	}
+
+	return db.User.findById(req.user.id).then((usr) => {
+		usr.name = _.trim(req.body.name);
+		if(usr.provider === 'local' && req.body.password !== '********') {
+			let nPwd = _.trim(req.body.password);
+			if(nPwd.length < 6) {
+				return Promise.reject(new Error('New Password too short!'))
+			} else {
+				return db.User.hashPassword(nPwd).then((pwd) => {
+					usr.password = pwd;
+					return usr.save();
+				});
+			}
+		} else {
+			return usr.save();
+		}
+	}).then(() => {
+		return res.json({ msg: 'OK' });
+	}).catch((err) => {
+		res.status(400).json({ msg: err.message });
+	})
+
+});
+
 router.get('/stats', (req, res) => {
 
 	if(res.locals.isGuest) {

+ 10 - 9
package.json

@@ -51,13 +51,14 @@
     "farmhash": "^1.2.1",
     "file-type": "^4.0.0",
     "filesize.js": "^1.0.2",
-    "fs-extra": "^1.0.0",
+    "fs-extra": "^2.0.0",
     "git-wrapper2-promise": "^0.2.9",
     "highlight.js": "^9.9.0",
-    "i18next": "^4.1.4",
+    "i18next": "^6.0.3",
     "i18next-express-middleware": "^1.0.2",
     "i18next-node-fs-backend": "^0.1.3",
     "js-yaml": "^3.7.0",
+    "klaw": "^1.3.1",
     "lodash": "^4.17.3",
     "markdown-it": "^8.2.2",
     "markdown-it-abbr": "^1.0.4",
@@ -79,14 +80,14 @@
     "passport-local": "^1.0.0",
     "passport-windowslive": "^1.0.2",
     "passport.socketio": "^3.7.0",
-    "pug": "^2.0.0-beta6",
+    "pug": "^2.0.0-beta10",
     "read-chunk": "^2.0.0",
     "remove-markdown": "^0.1.0",
-    "requarks-core": "github:requarks/core",
+    "requarks-core": "^0.2.0",
     "request": "^2.79.0",
     "search-index": "^0.9.9",
     "serve-favicon": "^2.3.2",
-    "sharp": "^0.17.0",
+    "sharp": "^0.17.1",
     "simplemde": "^1.11.2",
     "socket.io": "^1.7.2",
     "sticky-js": "^1.0.7",
@@ -112,7 +113,7 @@
     "gulp-tar": "^1.9.0",
     "gulp-uglify": "^2.0.0",
     "gulp-watch": "^4.3.11",
-    "gulp-zip": "^3.2.0",
+    "gulp-zip": "^4.0.0",
     "istanbul": "^0.4.5",
     "jquery": "^3.1.1",
     "jquery-contextmenu": "^2.4.1",
@@ -123,10 +124,10 @@
     "mocha-lcov-reporter": "^1.2.0",
     "nodemon": "^1.11.0",
     "run-sequence": "^1.2.2",
-    "snyk": "^1.22.1",
-    "sticky-js": "^1.1.6",
+    "snyk": "^1.24.6",
+    "sticky-js": "^1.1.8",
     "twemoji-awesome": "^1.0.4",
-    "vue": "^2.1.7"
+    "vue": "^2.1.10"
   },
   "snyk": true
 }

+ 42 - 38
views/pages/admin/profile.pug

@@ -1,45 +1,49 @@
 extends ./_layout.pug
 
 block adminContent
-	.hero
-		h1.title#title My Profile
-		h2.subtitle Profile and authentication info
-	.form-sections
-		.columns.is-gapless
-			.column.is-two-thirds
-				section
-					label.label Email
-					p.control.is-fullwidth
-						input.input(type='text', placeholder='Email', value=user.email, disabled=(user.provider !== 'local'))
-				if user.provider == 'local'
+	#page-type-admin-profile
+		.hero
+			h1.title#title My Profile
+			h2.subtitle Profile and authentication info
+		.form-sections
+			.columns.is-gapless
+				.column.is-two-thirds
 					section
-						label.label Password
+						label.label Email
 						p.control.is-fullwidth
-							input.input(type='password', placeholder='Password', value='********')
+							input.input(type='text', placeholder='Email', value=user.email, disabled)
+					if user.provider == 'local'
+						section
+							label.label Password
+							p.control.is-fullwidth
+								input.input(type='password', placeholder='Password', value='********', v-model='password')
+						section
+							label.label Verify Password
+							p.control.is-fullwidth
+								input.input(type='password', placeholder='Password', value='********', v-model='passwordVerify')
 					section
-						label.label Verify Password
+						label.label Display Name
 						p.control.is-fullwidth
-							input.input(type='password', placeholder='Password', value='********')
-				section
-					label.label Display Name
-					p.control.is-fullwidth
-						input.input(type='text', placeholder='John Smith', value=user.name)
-				section
-					button.button.is-green
-						i.icon-check
-						span Save Changes
-			.column
-				.panel
-					label.label Provider
-					p.control.account-profile-provider
-						case user.provider
-							when 'local': i.icon-server
-							when 'windowslive': i.icon-windows2.is-blue
-							when 'google': i.icon-google.is-blue
-							when 'facebook': i.icon-facebook.is-purple
-							default: i.icon-warning
-						= t('auth:providers.' + user.provider)
-					label.label Member since
-					p.control= userMoment(user.createdAt).format('LL')
-					label.label Last Profile Update
-					p.control= userMoment(user.updatedAt).format('LL')
+							input.input(type='text', placeholder='John Smith', v-model='name')
+					section
+						button.button.is-green(v-on:click='saveUser')
+							i.icon-check
+							span Save Changes
+				.column
+					.panel
+						label.label Provider
+						p.control.account-profile-provider
+							case user.provider
+								when 'local': i.icon-server
+								when 'windowslive': i.icon-windows2.is-blue
+								when 'google': i.icon-google.is-blue
+								when 'facebook': i.icon-facebook.is-purple
+								default: i.icon-warning
+							= t('auth:providers.' + user.provider)
+						label.label Member since
+						p.control= userMoment(user.createdAt).format('LL')
+						label.label Last Profile Update
+						p.control= userMoment(user.updatedAt).format('LL')
+
+	script(type='text/javascript').
+		var usrDataName = "!{user.name}";

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно