Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. ! function() {
  2. function n(n, e) {
  3. n.when("/", {
  4. templateUrl: "home/home.view.html",
  5. controller: "homeCtrl",
  6. controllerAs: "vm"
  7. }).when("/register", {
  8. templateUrl: "/auth/register/register.view.html",
  9. controller: "registerCtrl",
  10. controllerAs: "vm"
  11. }).when("/login", {
  12. templateUrl: "/auth/login/login.view.html",
  13. controller: "loginCtrl",
  14. controllerAs: "vm"
  15. }).when("/profile", {
  16. templateUrl: "/profile/profile.view.html",
  17. controller: "profileCtrl",
  18. controllerAs: "vm"
  19. }).otherwise({
  20. redirectTo: "/"
  21. }), e.html5Mode(!0)
  22. }
  23.  
  24. function e(n, e, t) {
  25. n.$on("$routeChangeStart", function(n, o, r) {
  26. "/profile" !== e.path() || t.isLoggedIn() || e.path("/")
  27. })
  28. }
  29. angular.module("meanApp", ["ngRoute"]), angular.module("meanApp").config(["$routeProvider", "$locationProvider", n]).run(["$rootScope", "$location", "authentication", e])
  30. }(),
  31. function() {
  32. function n() {
  33. console.log("Home controller is running")
  34. }
  35. angular.module("meanApp").controller("homeCtrl", n)
  36. }(),
  37. function() {
  38. function n(n, e) {
  39. var t = this;
  40. t.user = {}, e.getProfile().success(function(n) {
  41. t.user = n
  42. }).error(function(n) {
  43. console.log(n)
  44. })
  45. }
  46. angular.module("meanApp").controller("profileCtrl", n), n.$inject = ["$location", "meanData"]
  47. }(),
  48. function() {
  49. function n(n, e) {
  50. var t = this;
  51. t.credentials = {
  52. email: "",
  53. password: ""
  54. }, t.onSubmit = function() {
  55. e.login(t.credentials).error(function(n) {
  56. alert(n)
  57. }).then(function() {
  58. n.path("profile")
  59. })
  60. }
  61. }
  62. angular.module("meanApp").controller("loginCtrl", n), n.$inject = ["$location", "authentication"]
  63. }(),
  64. function() {
  65. function n(n, e) {
  66. var t = this;
  67. t.credentials = {
  68. name: "",
  69. email: "",
  70. password: ""
  71. }, t.onSubmit = function() {
  72. console.log("Submitting registration"), e.register(t.credentials).error(function(n) {
  73. alert(n)
  74. }).then(function() {
  75. n.path("profile")
  76. })
  77. }
  78. }
  79. angular.module("meanApp").controller("registerCtrl", n), n.$inject = ["$location", "authentication"]
  80. }(),
  81. function() {
  82. function n(n, e) {
  83. var t = function(n) {
  84. e.localStorage["mean-token"] = n
  85. },
  86. o = function() {
  87. return e.localStorage["mean-token"]
  88. },
  89. r = function() {
  90. var n, t = o();
  91. return t ? (n = t.split(".")[1], n = e.atob(n), n = JSON.parse(n), n.exp > Date.now() / 1e3) : !1
  92. },
  93. i = function() {
  94. if (r()) {
  95. var n = o(),
  96. t = n.split(".")[1];
  97. return t = e.atob(t), t = JSON.parse(t), {
  98. email: t.email,
  99. name: t.name
  100. }
  101. }
  102. };
  103. return register = function(e) {
  104. return n.post("/api/register", e).success(function(n) {
  105. t(n.token)
  106. })
  107. }, login = function(e) {
  108. return n.post("/api/login", e).success(function(n) {
  109. t(n.token)
  110. })
  111. }, logout = function() {
  112. e.localStorage.removeItem("mean-token")
  113. }, {
  114. currentUser: i,
  115. saveToken: t,
  116. getToken: o,
  117. isLoggedIn: r,
  118. register: register,
  119. login: login,
  120. logout: logout
  121. }
  122. }
  123. angular.module("meanApp").service("authentication", n), n.$inject = ["$http", "$window"]
  124. }(),
  125. function() {
  126. function n(n, e) {
  127. var t = function() {
  128. return n.get("/api/profile", {
  129. headers: {
  130. Authorization: "Bearer " + e.getToken()
  131. }
  132. })
  133. };
  134. return {
  135. getProfile: t
  136. }
  137. }
  138. angular.module("meanApp").service("meanData", n), n.$inject = ["$http", "authentication"]
  139. }(),
  140. function() {
  141. function n(n, e) {
  142. var t = this;
  143. t.isLoggedIn = e.isLoggedIn(), t.currentUser = e.currentUser()
  144. }
  145. angular.module("meanApp").controller("navigationCtrl", n), n.$inject = ["$location", "authentication"]
  146. }(),
  147. function() {
  148. function n() {
  149. return {
  150. restrict: "EA",
  151. templateUrl: "/common/directives/navigation/navigation.template.html",
  152. controller: "navigationCtrl as navvm"
  153. }
  154. }
  155. angular.module("meanApp").directive("navigation", n)
  156. }();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement