-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright (c) 2016, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/** | ||
* view/tokens/new.js | ||
* | ||
* Posts the token with authorization token. | ||
* CHanges DOM to show user the received token. | ||
*/ | ||
|
||
import request from 'superagent'; | ||
const u = require('../utils'); | ||
const Authorization = u.getCookie('Authorization'); | ||
|
||
// set up constants | ||
const input = document.loginform.elements; | ||
const errorInfo = document.getElementById('errorInfo'); | ||
const successInfo = document.getElementById('successInfo'); | ||
const tokenInfo = document.getElementById('tokenInfo'); | ||
toggleVisibility(tokenInfo, false); | ||
successInfo.innerHTML = 'Max length 60 characters'; | ||
|
||
document.loginform.addEventListener('submit', (evt) => { | ||
evt.preventDefault(); | ||
const jsonData = { name: input.name.value }; | ||
post(jsonData, '/v1/token'); | ||
}); | ||
|
||
/** | ||
* Toggles DOM element visibility in-place, based on boolean input | ||
* @param {Boolean} visibility If true, set the element to visible. | ||
* Else hide element | ||
*/ | ||
function toggleVisibility(elem, visibility) { | ||
elem.style.visibility = visibility ? 'visible' : 'hidden'; | ||
} | ||
|
||
/** | ||
* Post request with given JSON, to given endpoint | ||
* Show token if succeeded, else display error. | ||
* @param {Object} jsonData JSON object payload | ||
* @param {String} address API endpoint | ||
*/ | ||
function post(jsonData, address) { | ||
request | ||
.post(address) | ||
.send(jsonData) | ||
.set('Authorization', Authorization) | ||
.end((error, res) => { | ||
if (error) { | ||
let errorText = 'An unexpected error occurred'; | ||
toggleVisibility(errorDiv, true); | ||
errorDiv.innerHTML = errorText; | ||
toggleVisibility(successInfo, false); | ||
toggleVisibility(tokenInfo, false); | ||
} else { | ||
toggleVisibility(successInfo, true); | ||
toggleVisibility(tokenInfo, true); | ||
successInfo.innerHTML = 'NOTE: Please save this token, you will not see this token again!'; | ||
tokenInfo.innerHTML = res.body.token; | ||
toggleVisibility(document.getElementById('errorInfo'), false); | ||
// reset value | ||
input.name.value = ''; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
Copyright (c) 2016, salesforce.com, inc. | ||
All rights reserved. | ||
Licensed under the BSD 3-Clause license. | ||
For full license text, see LICENSE.txt file in the repo root or | ||
https://opensource.org/licenses/BSD-3-Clause | ||
doctype html | ||
html | ||
head | ||
title Create new token | ||
meta(name='viewport', content='width=device-width, initial-scale=1.0') | ||
link(href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', rel='stylesheet', media='screen') | ||
link(rel="stylesheet", type="text/css", href="/static/authentication/login-style.css") | ||
body | ||
div.container | ||
div.row | ||
div.text-center.col-md-4.col-md-offset-4 | ||
h1 Create new token | ||
br | ||
div.local-form | ||
form(role='form', name='loginform') | ||
#errorInfo | ||
#successInfo | ||
#tokenInfo | ||
.form-group | ||
input.form-control(type='text', autofocus, name="name", maxlength='60' placeholder='Enter token name' required) | ||
button.btn.btn-primary.btn-block(type='submit') Submit | ||
script. | ||
var trackingId = '#{trackingId}'; | ||
script(src='/static/tokens/app.js') | ||
script(src='/static/analytics/app.js') |