Browse Source

修复密码输错后不能重新输入的问题。 #149

oldj 8 years ago
parent
commit
7355a52cbb
1 changed files with 17 additions and 3 deletions
  1. 17 3
      app/server/apply.js

+ 17 - 3
app/server/apply.js

@@ -17,6 +17,19 @@ const platform = process.platform
 
 let sudo_pswd = ''
 
+function needPswd(str) {
+  str = str.toLowerCase()
+
+  console.log('---')
+  console.log(str)
+  let keys = [
+    'Permission denied'
+    , 'incorrect password'
+    , 'Password:Sorry, try again.'
+  ]
+  return !!keys.find(k => str.includes(k.toLowerCase()))
+}
+
 function apply_Unix (content, callback) {
   let tmp_fn = path.join(work_path, 'tmp.txt')
 
@@ -49,11 +62,12 @@ function apply_Unix (content, callback) {
     .then(cmd => {
       exec(cmd, function (error, stdout, stderr) {
         // command output is in stdout
-        if (error) {
-          callback(!sudo_pswd ? 'need_sudo' : error)
-        } else {
+        if (!error) {
           callback()
+          return
         }
+
+        callback(!sudo_pswd || needPswd(stdout + stderr) ? 'need_sudo' : error)
       })
     })
 }