mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-03-28 23:49:11 +08:00
31 lines
869 B
CoffeeScript
31 lines
869 B
CoffeeScript
child_process = require 'child_process'
|
|
express = require 'express'
|
|
|
|
plugin = require '../../core/plugin'
|
|
|
|
mAccount = require '../../core/model/account'
|
|
|
|
module.exports = exports = express.Router()
|
|
|
|
exports.use (req, res, next) ->
|
|
mAccount.authenticate req.token, (account) ->
|
|
unless account
|
|
return res.json 400, error: 'auth_failed'
|
|
|
|
unless 'ssh' in account.attribute.service
|
|
return res.json 400, error: 'not_in_service'
|
|
|
|
req.account = account
|
|
next()
|
|
|
|
exports.post '/update_passwd/', (req, res) ->
|
|
unless req.body.passwd or not /^[A-Za-z0-9\-_]+$/.test req.body.passwd
|
|
return res.json 400, error: 'invalid_passwd'
|
|
|
|
plugin.systemOperate (callback) ->
|
|
child_process.exec "echo '#{req.account.username}:#{req.body.passwd}' | sudo chpasswd", (err, stdout, stderr) ->
|
|
throw err if err
|
|
callback()
|
|
, ->
|
|
res.json {}
|