Rapidly Build A Visually Stunning Login For Your Javascript Dashboards
The login functionality of an application is the first thing most people see when they go to use a product. It is the most essential, inevitable, and foundational part of any software system out there. A developer who is working on an application often looks for quick and easy ways in which they can build the login part of an application, and focus most of the energy on implementing the actual business logic. In this blog post, we’ll see a quick overview of how we can rapidly build a login system for your JavaScript dashboards using Sencha Ext JS. For a more in-depth version of this guide see the documentation. How can I generate an app using Sencha CMD? Sencha allows you to generate an application boilerplate using the Sencha CMD. Run the following command in your terminal or CLI to generate a LoginApp boilerplate code. sencha -sdk /path/to/ExtSDK generate app LoginApp ./LoginApp Once you have generated the app, navigate to {appRoot}/app.js and remove the mainView config from the application config. We are doing this because we want to perform some validations and evaluations before deciding the initial view when the application loads. For example, there is no need to instantiate the Main view if the user is logged out of the system. At this point, when we have removed the mainView config, the browser shows a blank page upon refreshing the page. This is because the app does not know which view to instantiate yet. We handle this by adding plugins: ‘viewport’ line to {appRoot}/app/view/main/Main.js file. How can I create the login view components? After handling all the configurations and setup prerequisites, navigate to app/view folder inside the LoginApp folder and create a new directory called login. Inside this new directory, create two files Login.js and LoginController.js. Your directory structure should look somewhat like this now. How to generate the login window in my application? To create the login window, open the {appRoot}/app/view/login/Login.js file and define the Login class as follows. Ext.define(‘LoginApp.view.login.Login’, { extend: ‘Ext.window.Window’, xtype: ‘login’ }); In the above code, we essentially extended the Ext.window.Window class to create our own Login class to be further in the application. Let’s add some basic dependencies and properties that our Login class should rely on. requires: [ ‘LoginApp.view.login.LoginController’, ‘Ext.form.Panel’ ], controller: ‘login’, bodyPadding: 10, title: ‘Login Window’, closable: false, autoShow: true Now comes the actual UI part. We need to create a form containing at least three entities in total; username text field, password text field, and login button itself. items: { xtype: ‘form’, reference: ‘form’, items: [{ xtype: ‘textfield’, name: ‘username’, fieldLabel: ‘Username’, allowBlank: false }, { xtype: ‘textfield’, name: ‘password’, inputType: ‘password’, fieldLabel: ‘Password’, allowBlank: false }, { xtype: ‘displayfield’, hideEmptyLabel: false, value: ‘Enter any non-blank password’ }], buttons: [{ text: ‘Login’, formBind: true, listeners: { click: ‘onLoginClick’ } }] } All in all, the final code for in Login.js file should look like below. Ext.define(‘LoginApp.view.login.Login’, { extend: ‘Ext.window.Window’, xtype: ‘login’, requires: [ ‘LoginApp.view.login.LoginController’, ‘Ext.form.Panel’ ], controller: ‘login’, bodyPadding: 10, title: ‘Login Window’, closable: false, autoShow: true, items: { xtype: ‘form’, reference: ‘form’, items: [{ xtype: ‘textfield’, name: ‘username’, fieldLabel: ‘Username’, allowBlank: false }, { xtype: ‘textfield’, name: ‘password’, inputType: ‘password’, fieldLabel: ‘Password’, allowBlank: false }, { xtype: ‘displayfield’, hideEmptyLabel: false, value: ‘Enter any non-blank password’ }], buttons: [{ […]
