Parcourir la source

Check for auth session on new object. Add auth link to auth template.

Harry Hedger il y a 9 ans
Parent
commit
ea81ec9e8c
1 fichiers modifiés avec 17 ajouts et 1 suppressions
  1. 17 1
      src/plugins/GoogleDrive.js

+ 17 - 1
src/plugins/GoogleDrive.js

@@ -1,5 +1,7 @@
 // import Utils from '../core/Utils'
 // import Utils from '../core/Utils'
 import Plugin from './Plugin'
 import Plugin from './Plugin'
+// temporarily using superagent
+import request from 'superagent'
 
 
 export default class Drive extends Plugin {
 export default class Drive extends Plugin {
   constructor (core, opts) {
   constructor (core, opts) {
@@ -8,9 +10,13 @@ export default class Drive extends Plugin {
     this.authenticate = this.authenticate.bind(this)
     this.authenticate = this.authenticate.bind(this)
     this.connect = this.connect.bind(this)
     this.connect = this.connect.bind(this)
     this.render = this.render.bind(this)
     this.render = this.render.bind(this)
+    this.renderAuthentication = this.renderAuthentication.bind(this)
+    this.checkAuthentication = this.checkAuthentication.bind(this)
     this.files = []
     this.files = []
     this.currentDir = '/'
     this.currentDir = '/'
 
 
+    this.checkAuthentication()
+
     this.isAuthenticated = false
     this.isAuthenticated = false
   }
   }
 
 
@@ -23,6 +29,16 @@ export default class Drive extends Plugin {
     }
     }
   }
   }
 
 
+  checkAuthentication () {
+    request.get('http://localhost:3002/drive/auth/authorize')
+    .set('Content-Type', 'application/json')
+    .end((err, res) => {
+      if (err) { return new Error(err) }
+      this.isAuthenticated = res.body.isAuthenticated
+      this.authUrl = res.body.authUrl
+    })
+  }
+
   authenticate () {
   authenticate () {
   }
   }
 
 
@@ -39,7 +55,7 @@ export default class Drive extends Plugin {
   }
   }
 
 
   renderAuthentication () {
   renderAuthentication () {
-    return `<div><h1>Authenticate With Google Drive</h1><button>Authenticate</button></div>`
+    return `<div><h1>Authenticate With Google Drive</h1><a href=${ this.authUrl || '#' }>Authenticate</a></div>`
   }
   }
 
 
   render (files) {
   render (files) {