I have an ionic project with side menu and all. Now I want to add in simple way and login cool form, like http://ionicmaterial.com/ But the issue I didn't see any examples how to add it in exciting project that it will load the login form first and after that will redirect to regular page. My project looks like:
app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.placeslists', {
url: "/placeslists",
views: {
'menuContent': {
templateUrl: "templates/placeslists.html",
controller: 'PlaceslistsCtrl'
}
}
})
How can I add the login page with authentication (token) that it will load first and how can I add the material for login page in easy way.
Thanks!!!
For implementing login, you would require these things
In your DoLogin function, you would need to handle hit your API for login, and receive your token. You would need to store this token. I use SQLlite plugin to store my token into a token table. There are different ways of storing token.
and many more, I can provide you with code snippet using SQLlite.
Don't just copy paste from the code (it wont work), you would need build the logic on where to place all this code and in which order.
After you have received the authToken, you can set it as a common header for all you $http requests, and when user clicks on logout, just drop the table or drop the DB. ( go through the blogs in the link)
I found at the end all info with demos you can find also in: https://github.com/zachsoft/Ionic-Material
you can add new state login in app.js which will load login.html and controller and load it by defalut like:
.state('login', { url: '/login', templateUrl: 'templates/login.html', controller: 'LoginCtrl' })
// if none of the above states are matched, use this as the fallback $urlRouterProvider.otherwise('/login');
and in login controller when you successfully login then you can redirect it to any page using $state.go('app.placeslists'); it will load regular pages.