extjs - How to get authenticated user? -


i following 'getting started tutorial' , have simple ext.js code:

ext.define('tutorialapp.view.main', {     extend: 'ext.container.container',     requires:[         'ext.tab.panel',         'ext.layout.container.border'     ],       xtype: 'app-main',       layout: {         type: 'border'     },       items: [{         region: 'west',         xtype: 'panel',         title: 'west',         width: 150     },{         region: 'center',         xtype: 'tabpanel',         items:[{             title: 'center tab 1'         }]     }],     listeners: {         afterrender: function () {            alert('hi there')         }     } }); 

i'd know how "alert" pop say, "hi there red" "red" user has performed basic authentication.

it depends on whether basic authentication performed on accessing whole page, or on client side application accessing restricted area on same domain via ajax.

in first case need server side pass basic auth username client (there no way javascript can access otherwise). may done getting server insert custom bit of javascript containing username (and potentially other useful stuff server knows):

<script type="text/javascript"> window.context = {     // other useful stuff     username: 'red' } </script> 

with above in place, alert simply:

alert('hi there ' + context.username) 

in second case (sending basic auth credentials via ajax) client side know username in first place, upon authentication success know name show in alert. actual code depend on component doing authentication, approach have singleton have methods performing authentication, telling whether user authenticated , username is. alert call it:

alert('hi there ' + tutorialapp.auth.getusername()) 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

android - Pass an Serializable object in AIDL -