Friday, 15 April 2011

javascript - getting error in the javascipt ,when authenticate the username and password using digest authentication -



javascript - getting error in the javascipt ,when authenticate the username and password using digest authentication -

here want authenticate username , password .here im getting username ,password vlues succesfully in console(valuesuser). tried next code,

ext.define('form.controller.digestauth', { extend: 'ext.app.controller', requires:['registerform.view.login','registerform.view.main'], config:{ refs:{ loginform: '#loginform' }, control: { '#loginbutton': { tap: function(){ var valuesuser = this.getloginform().getvalues(); console.log(valuesuser); console.log(valuesuser.username); $.class("pl.arrowgroup.digestauthentication",{ max_attempts : 1, authorization_header : "authorization", www_authenticate_header : 'www-authenticate', nc : "00000001", //currently nc value fixed not incremented http_method : "get", /**   * settings json:   * - onsuccess - on success callback   * - onfailure - on failure callback   * - username - user name   * - password - user password   * - cnonce - client nonce   */ init : function(settings) { this.settings = settings; }, setcredentials: function(username, password){ this.settings.username = valuesuser.username; this.settings.password = valuesuser.userpassword; }, phone call : function(uri){ this.attempts = 0; this.invokecall(uri); }, invokecall: function(uri,authorizationheader){ var digestauth = this; $.ajax({ url: uri, uri:'http://localhost/sencha2011/registerform/newuser.php?action=check', type: this.http_method, beforesend: function(request){ if(typeof authorizationheader != 'undefined'){ request.setrequestheader(digestauth.authorization_header, authorizationheader); } }, success: function(response) { digestauth.settings.onsuccess(response); }, error: function(response) { if(digestauth.attempts == digestauth.max_attempts){ digestauth.settings.onfailure(response); return; } var paramparser = new pl.arrowgroup.headerparamsparser(response.getresponseheader(digestauth.www_authenticate_header)); var nonce = paramparser.getparam("nonce"); var realm = paramparser.getparam("realm"); var qop = paramparser.getparam("qop"); var response = digestauth.calculateresponse(uri, nonce, realm, qop); var authorizationheadervalue = digestauth.generateauthorizationheader(paramparser.headervalue, response, uri); digestauth.attempts++; digestauth.invokecall(uri, authorizationheadervalue); } }); }, calculateresponse : function(uri, nonce, realm, qop){ var a2 = this.http_method + ":" + uri; var a2md5 = hex_md5(a2); var a1md5 = hex_md5(this.settings.username + ":" + realm + ":" + this.settings.password); var digest = a1md5 + ":" + nonce + ":" + this.nc + ":" + this.settings.cnonce + ":" + qop + ":" +a2md5; homecoming hex_md5(digest); }, generateauthorizationheader : function(wwwauthenticationheader, response, uri){ homecoming wwwauthenticationheader+', username="'+this.settings.username+'", uri="'+ uri+'", response="'+response+'", nc='+ this.nc+', cnonce="'+this.settings.cnonce+'"'; } }); $.class("pl.arrowgroup.headerparamsparser",{ init : function(headervalue) { this.headervalue = headervalue; this.headerparams = this.headervalue.split(","); }, getparam: function(paramname){ var paramval = null; $.each(this.headerparams, function(index, value){ if(value.indexof(paramname)>0){ paramval = value.split(paramname+"=")[1]; paramval = paramval.substring(1, paramval.length-1); } }); homecoming paramval; } }); } } } } });

to write above code ,i take help of "http://marcin-michalski.pl/2012/11/01/javascript-digest-authentication-restful-webservice-spring-security-javascript-ajax/" link digest-auth.js file

im getting error :uncaught referenceerror: $ not defined.can help me .thanks in advance

you need include jquery. defines global $ variable, error complaining about. phone call $.ajax.

check out getting started section here: http://docs.jquery.com/

javascript sencha-touch-2

No comments:

Post a Comment