My user login function includes a method called logincheck, which takes in parameters and sends a request to the server. Upon success, it redirects the user to the dashboard with the member ID.
this.logincheck = function(log) {
var parameter ={
"mail" :log.mail,
"password" :log.passwords
}
alert(JSON.stringify(parameter));
$http({
url: '---------',
-----------
}).success(function(data,status) {
if(data.status=="success") {
var sessionid = data.member.member_id;
$state.go('dashboardsnewsucc.dashboardefault', {userid: sessionid});
}
else{
alert("Invalid Username or Password try again. !!!");
}
});
};
In addition to the member ID, I also want the entire member data. To achieve this, the following controller and states are set up:
.state('dashboardsnew', {
abstract: true,
url: "/dashboardsnew",
templateUrl: "views/common/content-empty.html",
})
.state('dashboardsnew.dashboardefault', {
url: "/dashboardefault",
templateUrl: "views/userdashboard.html",
data: { pageTitle: 'Hive Dashboard',specialClass: 'loginscreen-gray-bg' },
})
The JSON data received from the web service after a successful login contains details about the member and society:
{
"member": {
"member_id": 51,
"first_name": "Deepak",
"last_name": "Verma",
"phone": 6886438910,
"password": "sushil",
"role": [
{
"role_id": 2,
"name": "Society Admin"
}
],
"associated": []
},
"society": {
"society_id": 10,
"society_name": "Green Velley"
},
"status": "success",
"message": "member data details !"
}
To display the above JSON data on the login home page using AngularJS, the following code snippet can be used:
$http.get('http://192.168.1.7:8080/apartment//member/details/' + myParamtr).then(function(response) {
$scope.myData = response.data.member;
}
Finally, in the front end, the member's username can be displayed by using the following syntax:
{{myData.user_name}}