Advertisement
Guest User

Untitled

a guest
May 18th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <nav class="navbar navbar-default" id="header">
  2. ...
  3. non important tags
  4. ...
  5. <li ng-if="!session.logged"><a href="#/login">Enter</a></li>
  6. <li ng-if="session.logged"><a ng-click="logout()">Logout</a></li>
  7.  
  8. </nav>
  9.  
  10. export default function navigation(Auth, Session) {
  11. return {
  12. restrict: "E",
  13. replace: true,
  14. scope: {},
  15. templateUrl: directivesPath + "navigation.html",
  16. link: function(scope, element, attrs) {
  17. scope.session = Session.sessionData();
  18.  
  19. scope.logout = function() {
  20. Auth.logout();
  21. scope.session = Session.sessionData();
  22. window.location = "#/";
  23. }
  24. }
  25. }
  26. }
  27.  
  28. <!DOCTYPE html>
  29. <html lang="es" ng-app="movieApp">
  30. <head>
  31. ...
  32. </head>
  33. <body>
  34. <navigation></navigation>
  35. <div ui-view></div>
  36. </body>
  37. </html>
  38.  
  39. UsersCtrl.$inject = ["$scope", "$http", "Session"];
  40.  
  41. export function UsersCtrl($scope, $http, Session) {
  42. $http.get('http://localhost:3000/users').success(function (data) {
  43. console.log(data);
  44. $scope.users = data.data;
  45. $scope.session= Session.sessionData();
  46. });
  47. }
  48.  
  49. export default angular.module('movieControllers').controller("LoginCtrl", ["$scope", "$rootScope", "Auth", "Session",
  50. function($scope, $rootScope, Auth, Session) {
  51. console.log("User is logged? " + Auth.loggedIn());
  52. if (Auth.loggedIn() === true) {
  53. window.location = "#/users/" + Auth.currentUser.username;
  54. }
  55.  
  56. const button = document.getElementById('login');
  57. button.addEventListener("click", function() {
  58. const username = document.login.username.value;
  59. const password = document.login.password.value;
  60.  
  61. Auth.login({username: username, password: password}, function() {
  62. $scope.session= Session.sessionData();
  63. window.location = "#/users/" + username;
  64. // $scope.$digest();
  65. });
  66. });
  67. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement