Skip to content

Instantly share code, notes, and snippets.

(function() {
angular.module('app')
.factory('AuthService', ['$http',
function($http) {
var AuthService = {};
AuthService.login = function(data) {
return $http.post('/login', data)
}
(function(){
angular.module('app')
.directive('logout', ['$http', function($http) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.on('click', function(e) {
$http.post('/logout');
});
}
(function() {
angular.module('app')
.controller('ProfileController', ['$http', '$scope', '$location',
function($http, $scope, $location) {
$http.get('/api/userData')
.success(function(response) {
console.log('user data success')
console.log(response)
$scope.user = response; //Expose the user data to your angular scope
})
.when('/profile', {
templateUrl: '/views/profile.html',
controller: 'ProfileController'
})
<div class="page-header text-center">
<h1><span class="fa fa-anchor"></span> Profile Page</h1>
<a logout href="/logout" class="btn btn-default btn-sm">Logout</a>
</div>
<div class="row">
<!-- LOCAL INFORMATION -->
<div class="col-sm-12">
<div class="well">
app.post('/signup', function(req, res, next) {
// if email or password is missing, return an error message
if (!req.body.email || !req.body.password) {
return res.status(400).json({ error: 'Email and Password required' });
}
passport.authenticate('local-signup', function(err, user, info) {
if (err) {
return res.status(400).json(err);
}
(function() {
angular.module('app')
.controller('LoginController', ['$http', '$location',
function($http, $location) {
var vm = this;
vm.login = function() {
$http
.post('/login', {
email: vm.email,
password: vm.password
(function() {
angular.module('app')
.controller('SignupController', ['$http', '$location',
function($http, $location) {
var vm = this;
vm.signup = function() {
$http
.post('/signup', {
email: vm.email,
password: vm.password
// defining our routes
(function() {
angular.module('app')
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: '/views/landing.html',
})
.when('/login', {
templateUrl: '/views/login.html',
// defining our angular app, the first arguement is the name of our application
// second argument is an array that loads the dependencies into the application
(function() {
angular.module('app', ['ngRoute']);
})();