Added QRcode generation to Web UI
https://fedorahosted.org/freeipa/ticket/3369 Reviewed-By: Adam Misnyovszki <amisnyov@redhat.com>
This commit is contained in:
1 parent
57021d1a50
commit
6d1ef651db
9 files changed
+246
-7
No files matched your search
@@ -40,6 +40,9 @@ Dojo, Dojo Builder - dual licensed under BSD license and AFL version 2.1
|
||||
* util/build/_base/*.js
|
||||
* build/dojo/dojo.js
|
||||
|
||||
QRCode.js - licensed under MIT license
|
||||
* qrcode.js
|
||||
|
||||
Full license texts and copyright notices are listed below.
|
||||
|
||||
= jQuery copyright notice with MIT license =
|
||||
@@ -194,6 +197,27 @@ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
= The MIT License (MIT) - QRCcode.js =
|
||||
Copyright (c) 2012 davidshimjs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
= MIT license template =
|
||||
Copyright (C) <year> <copyright holders>
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
'js/libs/bootstrap.js',
|
||||
'js/libs/jquery.ordered-map.js',
|
||||
'js/libs/browser.js',
|
||||
'js/dojo/dojo.js'
|
||||
'js/dojo/dojo.js',
|
||||
'js/libs/qrcode.js'
|
||||
];
|
||||
ipa_loader.scripts(scripts, function() {
|
||||
require(['freeipa/app'], function(app){ app.run(); });
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
.otp-uri {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.qrcode-widget img {
|
||||
margin: 0 auto;
|
||||
}
|
||||
@@ -8,4 +8,5 @@
|
||||
@import "rcue/forms";
|
||||
@import "dialog";
|
||||
@import "brand";
|
||||
@import "forms-override.less";
|
||||
@import "forms-override";
|
||||
@import "plugins/otp";
|
||||
@@ -84,7 +84,7 @@ IPA.entity_adder_dialog = function(spec) {
|
||||
that.hide_message();
|
||||
that.add(
|
||||
function(data, text_status, xhr) {
|
||||
that.added.notify();
|
||||
that.added.notify([data], that);
|
||||
that.show_message(that.get_success_message(data));
|
||||
that.reset();
|
||||
that.focus_first_element();
|
||||
@@ -100,7 +100,7 @@ IPA.entity_adder_dialog = function(spec) {
|
||||
that.hide_message();
|
||||
that.add(
|
||||
function(data, text_status, xhr) {
|
||||
that.added.notify();
|
||||
that.added.notify([data], that);
|
||||
that.close();
|
||||
var result = data.result.result;
|
||||
that.show_edit_page(that.entity, result);
|
||||
@@ -129,7 +129,7 @@ IPA.entity_adder_dialog = function(spec) {
|
||||
that.hide_message();
|
||||
that.add(
|
||||
function(data, text_status, xhr) {
|
||||
that.added.notify();
|
||||
that.added.notify([data], that);
|
||||
that.close();
|
||||
that.notify_success(data);
|
||||
},
|
||||
|
||||
@@ -26,10 +26,10 @@ define([
|
||||
'./reg',
|
||||
'./details',
|
||||
'./facet',
|
||||
'./qrcode',
|
||||
'./search',
|
||||
'./entity'],
|
||||
function(IPA, $, menu, phases, reg, mod_details, mod_facet) {
|
||||
|
||||
function(IPA, $, menu, phases, reg, mod_details, mod_facet, QRCode) {
|
||||
/**
|
||||
* OTP tokens module
|
||||
* @class
|
||||
@@ -200,6 +200,9 @@ return {
|
||||
$pre_ops: [
|
||||
otptoken.adder_dialog_preop
|
||||
],
|
||||
$post_ops: [
|
||||
otptoken.adder_dialog_qrcode_post_op
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
$type: 'radio',
|
||||
@@ -307,6 +310,176 @@ otptoken.adder_dialog = function(spec) {
|
||||
return that;
|
||||
};
|
||||
|
||||
/**
|
||||
* Displays text as QR code
|
||||
* @class
|
||||
* @extends IPA.widget
|
||||
*/
|
||||
otptoken.qr_widget = function(spec) {
|
||||
|
||||
var that = IPA.widget(spec);
|
||||
|
||||
/**
|
||||
* Text to be displayed as QR Code
|
||||
* @property {string}
|
||||
* @readonly
|
||||
*/
|
||||
that.text = spec.text;
|
||||
|
||||
/**
|
||||
* Show link with the text instead of QR code
|
||||
* @property {boolean}
|
||||
*/
|
||||
that.show_link = !!spec.show_link;
|
||||
|
||||
/** @inheritDoc */
|
||||
that.create = function(container) {
|
||||
|
||||
that.widget_create(container);
|
||||
container.addClass('qrcode-widget');
|
||||
|
||||
that.div_link_control = $('<a/>', {
|
||||
name: that.name,
|
||||
href: ''
|
||||
}).appendTo(that.container);
|
||||
|
||||
that.qr_control = $('<div/>', {
|
||||
name: that.name
|
||||
}).appendTo(that.div_link_control);
|
||||
|
||||
that.uri_control = $('<div/>', {
|
||||
name: 'uri-control',
|
||||
'class': 'otp-uri',
|
||||
style: 'display: none;'
|
||||
}).appendTo(container);
|
||||
|
||||
that.link_container = $('<div/>', {
|
||||
style: 'padding: 5px 0;'
|
||||
}).appendTo(container);
|
||||
|
||||
that.show_uri_link = $('<a/>', {
|
||||
name: 'show-uri',
|
||||
href: '#',
|
||||
text: 'Show configuration uri',
|
||||
click: function(e) {
|
||||
e.preventDefault();
|
||||
that.update_display_mode(!that.show_link);
|
||||
}
|
||||
}).appendTo(that.link_container);
|
||||
|
||||
that.qrcode = new QRCode(that.qr_control[0], {
|
||||
text: "",
|
||||
width: 450,
|
||||
height: 450,
|
||||
colorDark : "#000000",
|
||||
colorLight : "#ffffff",
|
||||
correctLevel : QRCode.CorrectLevel.M
|
||||
});
|
||||
|
||||
that.update(that.text);
|
||||
that.update_display_mode(that.show_link);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update displayed information with supplied values.
|
||||
* @param {String|Array|null} values
|
||||
*/
|
||||
that.update = function(values) {
|
||||
|
||||
var val;
|
||||
if (typeof values === 'string') {
|
||||
val = values;
|
||||
} else if (values.length) {
|
||||
val = values[0];
|
||||
} else {
|
||||
val = '';
|
||||
}
|
||||
that.text = val;
|
||||
that.qrcode.makeCode(that.text);
|
||||
that.uri_control.text(that.text);
|
||||
that.div_link_control.prop('href', that.text);
|
||||
};
|
||||
|
||||
/**
|
||||
* Switches between QR code and link
|
||||
* @protected
|
||||
* @param {boolean} show_link
|
||||
*/
|
||||
that.update_display_mode = function(show_link) {
|
||||
|
||||
that.show_link = !!show_link;
|
||||
|
||||
if (that.show_link) {
|
||||
that.show_uri_link.text('Show QR code');
|
||||
that.qr_control.hide();
|
||||
that.uri_control.show();
|
||||
} else {
|
||||
that.show_uri_link.text('Show configuration uri');
|
||||
that.qr_control.show();
|
||||
that.uri_control.hide();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
that.clear = function() {
|
||||
that.qrcode.clear();
|
||||
that.link_control.text('');
|
||||
};
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
/**
|
||||
* Displays text as QR code in a dialog
|
||||
* @class
|
||||
* @extends IPA.message_dialog
|
||||
*/
|
||||
otptoken.qr_dialog = function(spec) {
|
||||
|
||||
var that = IPA.message_dialog(spec);
|
||||
|
||||
/**
|
||||
* Uses IPA.dialog UI
|
||||
*/
|
||||
that.create_content = that.dialog_create_content;
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
/**
|
||||
* OTP adder dialog post-op which enables showing of QR code after token is
|
||||
* successfully added by displaying QR dialog.
|
||||
* @member otptoken
|
||||
*/
|
||||
otptoken.adder_dialog_qrcode_post_op = function(object) {
|
||||
|
||||
object.added.attach(function(data) {
|
||||
|
||||
var uri = data.result.result.uri;
|
||||
var qr_dialog = otptoken.qr_dialog({
|
||||
name: 'qr_dialog',
|
||||
title: 'Configure your token',
|
||||
widgets: [
|
||||
{
|
||||
$type: 'qrcode',
|
||||
name: 'qr',
|
||||
text: uri
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
qr_dialog.open();
|
||||
qr_dialog.show_message('Configure your token by scanning the QR code \
|
||||
below. Click on the QR core if you see this on \
|
||||
the device you want to configure.');
|
||||
});
|
||||
|
||||
|
||||
return object;
|
||||
};
|
||||
|
||||
/**
|
||||
* Entity specification object
|
||||
* @member otptoken
|
||||
@@ -319,7 +492,10 @@ otptoken.spec = make_spec();
|
||||
*/
|
||||
otptoken.register = function() {
|
||||
var e = reg.entity;
|
||||
var w = reg.widget;
|
||||
|
||||
e.register({type: 'otptoken', spec: otptoken.spec});
|
||||
w.register('qrcode', otptoken.qr_widget);
|
||||
};
|
||||
|
||||
phases.on('registration', otptoken.register);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/* Authors:
|
||||
* Petr Vobornik <pvoborni@redhat.com>
|
||||
*
|
||||
* Copyright (C) 2013 Red Hat
|
||||
* see file 'COPYING' for use and warranty information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//
|
||||
// AMD Wrapper for QRCode.js library
|
||||
// It expects that the library was already loaded.
|
||||
//
|
||||
define(function() {
|
||||
return window.QRCode;
|
||||
});
|
||||
@@ -9,6 +9,7 @@ app_DATA = \
|
||||
jquery-ui.js \
|
||||
json2.js \
|
||||
loader.js \
|
||||
qrcode.js \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this.parsedData=[];for(var b=[],d=0,e=this.data.length;e>d;d++){var f=this.data.charCodeAt(d);f>65536?(b[0]=240|(1835008&f)>>>18,b[1]=128|(258048&f)>>>12,b[2]=128|(4032&f)>>>6,b[3]=128|63&f):f>2048?(b[0]=224|(61440&f)>>>12,b[1]=128|(4032&f)>>>6,b[2]=128|63&f):f>128?(b[0]=192|(1984&f)>>>6,b[1]=128|63&f):b[0]=f,this.parsedData=this.parsedData.concat(b)}this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function b(a,b){this.typeNumber=a,this.errorCorrectLevel=b,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}function i(a,b){if(void 0==a.length)throw new Error(a.length+"/"+b);for(var c=0;c<a.length&&0==a[c];)c++;this.num=new Array(a.length-c+b);for(var d=0;d<a.length-c;d++)this.num[d]=a[d+c]}function j(a,b){this.totalCount=a,this.dataCount=b}function k(){this.buffer=[],this.length=0}function m(){return"undefined"!=typeof CanvasRenderingContext2D}function n(){var a=!1,b=navigator.userAgent;return/android/i.test(b)&&(a=!0,aMat=b.toString().match(/android ([0-9]\.[0-9])/i),aMat&&aMat[1]&&(a=parseFloat(aMat[1]))),a}function r(a,b){for(var c=1,e=s(a),f=0,g=l.length;g>=f;f++){var h=0;switch(b){case d.L:h=l[f][0];break;case d.M:h=l[f][1];break;case d.Q:h=l[f][2];break;case d.H:h=l[f][3]}if(h>=e)break;c++}if(c>l.length)throw new Error("Too long data");return c}function s(a){var b=encodeURI(a).toString().replace(/\%[0-9a-fA-F]{2}/g,"a");return b.length+(b.length!=a?3:0)}a.prototype={getLength:function(){return this.parsedData.length},write:function(a){for(var b=0,c=this.parsedData.length;c>b;b++)a.put(this.parsedData[b],8)}},b.prototype={addData:function(b){var c=new a(b);this.dataList.push(c),this.dataCache=null},isDark:function(a,b){if(0>a||this.moduleCount<=a||0>b||this.moduleCount<=b)throw new Error(a+","+b);return this.modules[a][b]},getModuleCount:function(){return this.moduleCount},make:function(){this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var d=0;d<this.moduleCount;d++){this.modules[d]=new Array(this.moduleCount);for(var e=0;e<this.moduleCount;e++)this.modules[d][e]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(a,c),this.typeNumber>=7&&this.setupTypeNumber(a),null==this.dataCache&&(this.dataCache=b.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,b){for(var c=-1;7>=c;c++)if(!(-1>=a+c||this.moduleCount<=a+c))for(var d=-1;7>=d;d++)-1>=b+d||this.moduleCount<=b+d||(this.modules[a+c][b+d]=c>=0&&6>=c&&(0==d||6==d)||d>=0&&6>=d&&(0==c||6==c)||c>=2&&4>=c&&d>=2&&4>=d?!0:!1)},getBestMaskPattern:function(){for(var a=0,b=0,c=0;8>c;c++){this.makeImpl(!0,c);var d=f.getLostPoint(this);(0==c||a>d)&&(a=d,b=c)}return b},createMovieClip:function(a,b,c){var d=a.createEmptyMovieClip(b,c),e=1;this.make();for(var f=0;f<this.modules.length;f++)for(var g=f*e,h=0;h<this.modules[f].length;h++){var i=h*e,j=this.modules[f][h];j&&(d.beginFill(0,100),d.moveTo(i,g),d.lineTo(i+e,g),d.lineTo(i+e,g+e),d.lineTo(i,g+e),d.endFill())}return d},setupTimingPattern:function(){for(var a=8;a<this.moduleCount-8;a++)null==this.modules[a][6]&&(this.modules[a][6]=0==a%2);for(var b=8;b<this.moduleCount-8;b++)null==this.modules[6][b]&&(this.modules[6][b]=0==b%2)},setupPositionAdjustPattern:function(){for(var a=f.getPatternPosition(this.typeNumber),b=0;b<a.length;b++)for(var c=0;c<a.length;c++){var d=a[b],e=a[c];if(null==this.modules[d][e])for(var g=-2;2>=g;g++)for(var h=-2;2>=h;h++)this.modules[d+g][e+h]=-2==g||2==g||-2==h||2==h||0==g&&0==h?!0:!1}},setupTypeNumber:function(a){for(var b=f.getBCHTypeNumber(this.typeNumber),c=0;18>c;c++){var d=!a&&1==(1&b>>c);this.modules[Math.floor(c/3)][c%3+this.moduleCount-8-3]=d}for(var c=0;18>c;c++){var d=!a&&1==(1&b>>c);this.modules[c%3+this.moduleCount-8-3][Math.floor(c/3)]=d}},setupTypeInfo:function(a,b){for(var c=this.errorCorrectLevel<<3|b,d=f.getBCHTypeInfo(c),e=0;15>e;e++){var g=!a&&1==(1&d>>e);6>e?this.modules[e][8]=g:8>e?this.modules[e+1][8]=g:this.modules[this.moduleCount-15+e][8]=g}for(var e=0;15>e;e++){var g=!a&&1==(1&d>>e);8>e?this.modules[8][this.moduleCount-e-1]=g:9>e?this.modules[8][15-e-1+1]=g:this.modules[8][15-e-1]=g}this.modules[this.moduleCount-8][8]=!a},mapData:function(a,b){for(var c=-1,d=this.moduleCount-1,e=7,g=0,h=this.moduleCount-1;h>0;h-=2)for(6==h&&h--;;){for(var i=0;2>i;i++)if(null==this.modules[d][h-i]){var j=!1;g<a.length&&(j=1==(1&a[g]>>>e));var k=f.getMask(b,d,h-i);k&&(j=!j),this.modules[d][h-i]=j,e--,-1==e&&(g++,e=7)}if(d+=c,0>d||this.moduleCount<=d){d-=c,c=-c;break}}}},b.PAD0=236,b.PAD1=17,b.createData=function(a,c,d){for(var e=j.getRSBlocks(a,cLine truncated
|
||||
Reference in new issue
Block a user