Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <nav class="navbar navbar-default" id="header">
- ...
- non important tags
- ...
- <li ng-if="!session.logged"><a href="#/login">Enter</a></li>
- <li ng-if="session.logged"><a ng-click="logout()">Logout</a></li>
- </nav>
- export default function navigation(Auth, Session) {
- return {
- restrict: "E",
- replace: true,
- scope: {},
- templateUrl: directivesPath + "navigation.html",
- link: function(scope, element, attrs) {
- scope.session = Session.sessionData();
- scope.logout = function() {
- Auth.logout();
- scope.session = Session.sessionData();
- window.location = "#/";
- }
- }
- }
- }
- <!DOCTYPE html>
- <html lang="es" ng-app="movieApp">
- <head>
- ...
- </head>
- <body>
- <navigation></navigation>
- <div ui-view></div>
- </body>
- </html>
- UsersCtrl.$inject = ["$scope", "$http", "Session"];
- export function UsersCtrl($scope, $http, Session) {
- $http.get('http://localhost:3000/users').success(function (data) {
- console.log(data);
- $scope.users = data.data;
- $scope.session= Session.sessionData();
- });
- }
- export default angular.module('movieControllers').controller("LoginCtrl", ["$scope", "$rootScope", "Auth", "Session",
- function($scope, $rootScope, Auth, Session) {
- console.log("User is logged? " + Auth.loggedIn());
- if (Auth.loggedIn() === true) {
- window.location = "#/users/" + Auth.currentUser.username;
- }
- const button = document.getElementById('login');
- button.addEventListener("click", function() {
- const username = document.login.username.value;
- const password = document.login.password.value;
- Auth.login({username: username, password: password}, function() {
- $scope.session= Session.sessionData();
- window.location = "#/users/" + username;
- // $scope.$digest();
- });
- });
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement