Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.factory('Authentication', function($http,session){
- var service = {};
- service.login = function(username,password) {
- return $http
- .post('http://localhost:3000/loginfo',{
- username : username,
- password : password
- })
- .then(
- function successCallback(response){
- session.create(response.data.id,response.data.username);
- return response.data;
- });
- };
- service.isAuthenticated = function() {
- return !!session.username;
- };
- return service;
- });
- /*-----Main Controller-----*/
- app.controller('credientials',['$scope','$route','$http','Authentication',function($scope,$route,$http,Authentication) {
- $scope.isAuthenticated = false;
- $scope.userCred = {
- username: '',
- password: ''
- }
- /*-----Form Submition-----*/
- $scope.log = function(userCred){
- Authentication.login(userCred.username,userCred.password)
- .then(function(result){
- console.log(result);
- })
- .catch(function(err){
- console.error(err);
- });
Add Comment
Please, Sign In to add comment