Retrieving a New License

To retrieve a new license, we have to gather the email, password, and a corporate identifier from the user. If you're retrieving a demo license, the corporate id is optional. In this example application, we achieve the showing and hiding of the login input fields using states. This could just as easily be done using a modal dialog box or some other method. It's up to the developer to sculpt the licensing experience the way they see fit.

<mx:State name="login">
	<mx:AddChild>
		<mx:VBox horizontalAlign="center" verticalAlign="middle">
			<mx:Form id="form1" defaultButton="{submit}">
				<mx:FormHeading label="Nitro-LM Login"/>
				<mx:FormItem id="emailItem" required="true">
					<flexlib:PromptingTextInput id="email" prompt="E-Mail" width="200"/>
				</mx:FormItem>
				<mx:FormItem id="passwordItem" required="true">
					<flexlib:PromptingTextInput id="password" prompt="password" displayAsPassword="true" width="200"/>
				</mx:FormItem>
				<mx:FormItem id="corpIdItem" required="true">
					<flexlib:PromptingTextInput id="corpid" prompt="corporate id" displayAsPassword="true" width="200"/>
				</mx:FormItem>
			</mx:Form>
			<mx:HBox>
				<mx:Button id="register" label="Register" icon="@Embed(source='/assets/icons/16x16/user_add.png')" click="currentState='RegisterNewUser'"/>
				<mx:Spacer width="10"/>
				<mx:ComboBox id="typeCombo" dataProvider="['Floating','Checked Out', 'Demo']" change="currentState = typeCombo.selectedLabel=='Demo' ? 'login_demo' : 'login'"/>
				<mx:Button label="Cancel" click="this.close()" icon="@Embed(source='/assets/icons/16x16/cancel.png')"/>
				<mx:Button id="submit" label="Submit" click="doLogin()" icon="@Embed(source='/assets/icons/16x16/accept.png')"/>
			</mx:HBox>
			<mx:Text id="login_status" text="" color="#FF0000" width="100%" textAlign="center"/>
		</mx:VBox>
	</mx:AddChild>
	<mx:RemoveChild target="{tabNav}"/>
</mx:State>
<mx:State name="login_demo" basedOn="login">
	<mx:RemoveChild target="{corpIdItem}"/>
</mx:State>

After the information has been gathered, doLogin() is called to handle the request for a license from Nitro-LM.

private function doLogin():void
{
	CursorManager.setBusyCursor();
	licenseClient.addEventListener(LicenseClientEvent.LICENSE_RESPONSE, handleLoginResponse);
	
	if(typeCombo.selectedLabel == "Demo")
	{
		//get a 5-day demo license (demo licenses behave like checkout licenses)
		//corporate id isn't necessary for demo licenses (their corporation hasn't
//purchased anything yet, so they have no Customer entry(corp_id) in NitroLM
		licenseClient.getLicense(email.text, password.text, null, product_name, "1", NLMConstants.LOCK_DEMO, 5, "", false);
	}
	else if(typeCombo.selectedLabel == "Floating")
	{
		//get a floating license
		licenseClient.getLicense(email.text, password.text, corpid.text, product_name, "1", NLMConstants.LOCK_FLOATING, 0, "", false);
	}
	else
	{
		//get a checked out license for 1 day
		licenseClient.getLicense(email.text, password.text, corpid.text, product_name, "1", NLMConstants.LOCK_FIXED, 1, "", false);
	}
}

private function handleLoginResponse(event:LicenseClientEvent):void
{
	CursorManager.removeBusyCursor();
	licenseClient.removeEventListener(LicenseClientEvent.LICENSE_RESPONSE, handleLoginResponse);
	if(event.response == NLMConstants.RESPONSE_OK)
	{
		//re-validate our license
		initNitroLM(new Event(Event.COMPLETE));
	}
	else
	{
		login_status.text = NLMConstants.responseToString(event.response);
	}
}

Now that we've requested a license, handleLoginResponse() is called to determine whether we were successful in retrieving a license. If we were, we call initNitroLM() to re-validate our license and remove the login screen. This gives the authenticated user access to our application.

Comments