Skip to content

Instantly share code, notes, and snippets.

@sushmasonus
Created September 2, 2016 09:21
Show Gist options
  • Save sushmasonus/f61aa093d68ca6ae0d6594fb509e4e94 to your computer and use it in GitHub Desktop.
Save sushmasonus/f61aa093d68ca6ae0d6594fb509e4e94 to your computer and use it in GitHub Desktop.
angular.module('app', ['ngRoute'])
.config(function($httpProvider,$routeProvider) {
$routeProvider
.when('/login', {
templateUrl: 'index.html',
controller: 'postserviceCtrl'
})
.when('/register', {
templateUrl: 'sign-up-user-account.html',
controller: 'postregisterCtrl'
})
.otherwise({
redirectTo: '/login'
});
$httpProvider.interceptors.push(function($q, $rootScope, ConfigService) {
return {
request: function(config) {
ConfigService.getHttpUrl(config);
ConfigService.setApiKey(config);
return config;
}
}
})
})
.factory('ConfigService', function() {
var base_url = "http://localhost:80/Lumen-5.2-Swagger-2.0/Trunk/public/v1";
var App_key = "123";
return {
getHttpUrl: function(config) {
config.url = base_url + config.url;
},
setApiKey: function(config) {
config.headers['Api_key'] = App_key;
config.headers['session_token'] = '$2y$10$eqCudTg2xrJVpydokr.L1eXFGaEm1XgX8DnO.YyDw4aCh.SRPirqO';
// config.headers['Access-Control-Allow-Origin'] = '*';
// config.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT';
// config.headers['Access'] = '*';
// config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
}
};
})
//Login
.controller('postserviceCtrl', function($scope, $http) {
$scope.email = null;
$scope.password = null;
$scope.postdata = function(email, password) {
var data = {
email: email,
password: password,
login_type:1
};
console.log(data);
//Call the services
$http.post('/login', JSON.stringify(data)).success(function(data, status) {
$scope.msg = "Post Data Submitted Successfully!";
console.log(data);
}).error(function(data, status) {
$scope.msg = "Invalid Login!";
});
};
});
//Registration
.controller('postregisterCtrl', function($scope, $http) {
$scope.first_name = null;
$scope.last_name = null;
$scope.email = null;
$scope.password = null;
$scope.gender = null;
$scope.dob = null;
$scope.postdata = function(email, password) {
var data = {
first_name:first_name,
last_name:last_name,
email: email,
password: password,
gender:gender,
dob:dob,
device_id:1,
fb_token:nmm,
reg_type:1
};
console.log(data);
//Call the services
$http.post('/register', JSON.stringify(data)).success(function(data, status) {
$scope.msg = "Post Data Submitted Successfully!";
console.log(data);
}).error(function(data, status) {
$scope.msg = "Invalid Register!";
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment