mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 03:41:01 +00:00
generate token via the UI
This commit is contained in:
parent
9c62d0b883
commit
8535ea44fd
4 changed files with 26 additions and 82 deletions
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,56 +1,20 @@
|
|||
<main>
|
||||
<article>
|
||||
<section>
|
||||
<h2>Login info</h2>
|
||||
<div class="row">
|
||||
<div>Login</div>
|
||||
<div>{{ user.login }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div>Full Name</div>
|
||||
<div>{{ user.name }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div>Email</div>
|
||||
<div>{{ user.email }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div>Token</div>
|
||||
<div ng-if="!token" style="color: #1E88E5;text-decoration: underline;cursor: pointer;" ng-click="showToken()">Click to Display Token</div>
|
||||
<div ng-if="token">{{ token }}</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Tokens</h2>
|
||||
<form>
|
||||
<div style="padding-left: 20px; float: left;">
|
||||
<input type="label" ng-model="newToken.label" />
|
||||
</div>
|
||||
<div style="padding-top: 20px; padding-left: 20px; float: left;">
|
||||
<button ng-click="createToken(newToken)">Create</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="alert" ng-if="tokens && tokens.length === 0">No Personal Tokens Exist</div>
|
||||
|
||||
<table ng-if="tokens && tokens.length !== 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Label</th>
|
||||
<th>Issued</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat-start="token in tokens">
|
||||
<td>{{ token.label }}</td>
|
||||
<td>{{ token.issued_at | fromNow }}</td>
|
||||
<td><button ng-click="revokeToken(token)">delete</button></td>
|
||||
</tr>
|
||||
<tr ng-repeat-end ng-if="token.hash">
|
||||
<td colspan="3">
|
||||
<span>Make sure to copy your new personal access token now. You won't be able to see it again!</span>
|
||||
<pre style="white-space: pre-line;overflow-wrap: break-word;">{{ token.hash }}</pre>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue