How can we change the following code to work when the button is clicked. As of right now it's configured to a submit button, which the button is not.
Button:
<button class="btn btn-primary" ng-click="login()">Log in</button>
JavaScript:
dpd.users.me(function(user) {
if (user) {
location.href = "/";
}
});
$('form').submit(function() {
var username = $('#username').val();
var password = $('#password').val();
dpd.users.login({username: username, password: password}, function(session, error) {
if (error) {
alert(error.message);
} else {
location.href = "/welcome.html";
}
});
return false;
});
Controller:
$scope.showLogin = function(val) {
$scope.loginVisible = val;
if (val) {
$scope.username = '';
$scope.password = '';
}
};
$scope.login = function() {
dpd.users.login({
username: $scope.username,
password: $scope.password
}, function(session, error) {
if (error) {
alert(error.message);
} else {
$scope.showLogin(false);
getMe();
$scope.$apply();
}
});
};