From 8535ea44fdb5004015514fa2ca1c2c3e417003bb Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 9 Sep 2015 14:34:28 -0700 Subject: [PATCH] generate token via the UI --- .../static/scripts/controllers/users.js | 20 ++------ .../static/scripts/services/tokens.js | 22 +-------- .../static/scripts/views/profile/content.html | 46 ++----------------- pkg/server/user.go | 20 ++++++-- 4 files changed, 26 insertions(+), 82 deletions(-) diff --git a/cmd/drone-server/static/scripts/controllers/users.js b/cmd/drone-server/static/scripts/controllers/users.js index 8a25254bc..d5447bfe3 100644 --- a/cmd/drone-server/static/scripts/controllers/users.js +++ b/cmd/drone-server/static/scripts/controllers/users.js @@ -40,23 +40,9 @@ $scope.user = payload.data; }); - // Gets the user tokens - tokens.list().then(function(payload){ - $scope.tokens = payload.data || []; - }); - - $scope.newToken={Label: ""}; - $scope.createToken = function(newToken) { - tokens.post(newToken).then(function(payload) { - $scope.tokens.push(payload.data); - $scope.newToken={Label: ""}; - }); - } - - $scope.revokeToken = function(token) { - tokens.delete(token).then(function() { - var index = $scope.tokens.indexOf(token); - $scope.tokens.splice(index, 1); + $scope.showToken = function() { + tokens.post().then(function(payload) { + $scope.token = payload.data; }); } } diff --git a/cmd/drone-server/static/scripts/services/tokens.js b/cmd/drone-server/static/scripts/services/tokens.js index c71a7b061..22ba77ccd 100644 --- a/cmd/drone-server/static/scripts/services/tokens.js +++ b/cmd/drone-server/static/scripts/services/tokens.js @@ -9,28 +9,10 @@ function TokenService($http, $window) { /** - * Gets a list of all repositories. - */ - this.list = function() { - return $http.get('/api/user/tokens'); - }; - - /** - * Creates a new token. - * - * @param {object} JSON representation of a repository. + * Generates a user API token. */ this.post = function(token) { - return $http.post('/api/user/tokens', token); - }; - - /** - * Deletes a repository. - * - * @param {string} Name of the repository. - */ - this.delete = function(token) { - return $http.delete('/api/user/tokens/' + token.label); + return $http.post('/api/user/token'); }; } diff --git a/cmd/drone-server/static/scripts/views/profile/content.html b/cmd/drone-server/static/scripts/views/profile/content.html index af2551695..2225e6646 100644 --- a/cmd/drone-server/static/scripts/views/profile/content.html +++ b/cmd/drone-server/static/scripts/views/profile/content.html @@ -1,56 +1,20 @@
-

Login info

Login
{{ user.login }}
-
-
Full Name
-
{{ user.name }}
-
Email
{{ user.email }}
+
+
Token
+
Click to Display Token
+
{{ token }}
+
-
-

Tokens

-
-
- -
-
- -
-
- -
No Personal Tokens Exist
- - - - - - - - - - - - - - - - - - - -
LabelIssued
{{ token.label }}{{ token.issued_at | fromNow }}
- Make sure to copy your new personal access token now. You won't be able to see it again! -
{{ token.hash }}
-
-
\ No newline at end of file diff --git a/pkg/server/user.go b/pkg/server/user.go index 4fc3cb56f..47399d2a5 100644 --- a/pkg/server/user.go +++ b/pkg/server/user.go @@ -1,6 +1,8 @@ package server import ( + // "crypto/sha1" + "github.com/drone/drone/Godeps/_workspace/src/github.com/gin-gonic/gin" "github.com/drone/drone/Godeps/_workspace/src/github.com/gin-gonic/gin/binding" "github.com/drone/drone/Godeps/_workspace/src/github.com/ungerik/go-gravatar" @@ -16,7 +18,17 @@ import ( // GET /api/user // func GetUserCurr(c *gin.Context) { - c.JSON(200, ToUser(c)) + u := ToUser(c) + // f := fmt.Printf("% x", sha1.Sum(u.Hash)) + + // v := struct { + // *types.User + + // // token fingerprint + // Token string `json:"token"` + // }{u, f} + + c.JSON(200, u) } // PutUserCurr accepts a request to update the currently @@ -81,11 +93,11 @@ func GetUserFeed(c *gin.Context) { func PostUserToken(c *gin.Context) { user := ToUser(c) - t := token.New(token.UserToken, user.Login) - s, err := t.Sign(user.Hash) + token := token.New(token.UserToken, user.Login) + tokenstr, err := token.Sign(user.Hash) if err != nil { c.Fail(500, err) } else { - c.String(200, "application/jwt", s) + c.String(200, tokenstr) } }