diff --git a/app_api/config/passport.js b/app_api/config/passport.js index 8fb7cef..5d1d6c8 100644 --- a/app_api/config/passport.js +++ b/app_api/config/passport.js @@ -7,12 +7,7 @@ passport.use(new LocalStrategy({ usernameField: 'email' }, function(username, password, done) { - console.log("Finding user: " + username + ";" + password); User.findOne({ email: username }, function (err, user) { - console.log("user found"); - console.log(user); - console.log("err found"); - console.log(err); if (err) { return done(err); } // Return if user not found in database if (!user) { diff --git a/app_api/controllers/profile.js b/app_api/controllers/profile.js index 6373173..15a03e3 100644 --- a/app_api/controllers/profile.js +++ b/app_api/controllers/profile.js @@ -9,7 +9,7 @@ module.exports.profileRead = function(req, res) { }); } else { User - .findById(req.params.userid) + .findById(req.payload._id) .exec(function(err, user) { res.status(200).json(user); }); diff --git a/app_api/routes/index.js b/app_api/routes/index.js index 7ced465..7cea5e8 100644 --- a/app_api/routes/index.js +++ b/app_api/routes/index.js @@ -10,7 +10,7 @@ var ctrlProfile = require('../controllers/profile'); var ctrlAuth = require('../controllers/authentication'); // profile -router.get('/profile/:userid', auth, ctrlProfile.profileRead); +router.get('/profile', auth, ctrlProfile.profileRead); // authentication router.post('/register', ctrlAuth.register); diff --git a/app_client/app.min.js b/app_client/app.min.js index 28e0a39..0cdac7c 100644 --- a/app_client/app.min.js +++ b/app_client/app.min.js @@ -1,2 +1,2 @@ -!function(){function n(n,t){n.when("/",{templateUrl:"home/home.view.html",controller:"homeCtrl",controllerAs:"vm"}).when("/register",{templateUrl:"/auth/register/register.view.html",controller:"registerCtrl",controllerAs:"vm"}).when("/login",{templateUrl:"/auth/login/login.view.html",controller:"loginCtrl",controllerAs:"vm"}).when("/profile",{templateUrl:"/profile/profile.view.html",controller:"profileCtrl",controllerAs:"vm"}).otherwise({redirectTo:"/"}),t.html5Mode(!0)}function t(n,t,e){n.$on("$routeChangeStart",function(n,o,r){"/profile"!==t.path()||e.isLoggedIn()||t.path("/")})}angular.module("meanApp",["ngRoute"]),angular.module("meanApp").config(["$routeProvider","$locationProvider",n]).run(["$rootScope","$location","authentication",t])}(),function(){function n(){console.log("Home controller is running")}angular.module("meanApp").controller("homeCtrl",n)}(),function(){function n(n){}angular.module("meanApp").controller("profileCtrl",n),n.$inject=["$location"]}(),function(){function n(n,t){var e=this;e.credentials={email:"",password:""},e.onSubmit=function(){t.login(e.credentials).error(function(n){alert(n)}).then(function(){n.path("profile")})}}angular.module("meanApp").controller("loginCtrl",n),n.$inject=["$location","authentication"]}(),function(){function n(n,t){var e=this;e.credentials={name:"Simon",email:"",password:""},e.onSubmit=function(){console.log("Submitting registration"),t.register(e.credentials).error(function(n){alert(n)}).then(function(){n.path("profile")})}}angular.module("meanApp").controller("registerCtrl",n),n.$inject=["$location","authentication"]}(),function(){function n(n,t){var e=function(n){t.localStorage["mean-token"]=n},o=function(){return t.localStorage["mean-token"]},r=function(){var n,e=o();return e?(n=e.split(".")[1],n=t.atob(n),n=JSON.parse(n),n.exp>Date.now()/1e3):!1},i=function(){if(r()){var n=o(),e=n.split(".")[1];return e=t.atob(e),e=JSON.parse(e),{email:e.email,name:e.name}}};return register=function(t){return n.post("/api/register",t).success(function(n){e(n.token)})},login=function(t){return n.post("/api/login",t).success(function(n){e(n.token)})},logout=function(){t.localStorage.removeItem("mean-token")},{currentUser:i,saveToken:e,getToken:o,isLoggedIn:r,register:register,login:login,logout:logout}}angular.module("meanApp").service("authentication",n),n.$inject=["$http","$window"]}(),function(){function n(n,t){var e=this;e.isLoggedIn=t.isLoggedIn(),e.currentUser=t.currentUser()}angular.module("meanApp").controller("navigationCtrl",n),n.$inject=["$location","authentication"]}(),function(){function n(){return{restrict:"EA",templateUrl:"/common/directives/navigation/navigation.template.html",controller:"navigationCtrl as navvm"}}angular.module("meanApp").directive("navigation",n)}(); +!function(){function n(n,e){n.when("/",{templateUrl:"home/home.view.html",controller:"homeCtrl",controllerAs:"vm"}).when("/register",{templateUrl:"/auth/register/register.view.html",controller:"registerCtrl",controllerAs:"vm"}).when("/login",{templateUrl:"/auth/login/login.view.html",controller:"loginCtrl",controllerAs:"vm"}).when("/profile",{templateUrl:"/profile/profile.view.html",controller:"profileCtrl",controllerAs:"vm"}).otherwise({redirectTo:"/"}),e.html5Mode(!0)}function e(n,e,t){n.$on("$routeChangeStart",function(n,o,r){"/profile"!==e.path()||t.isLoggedIn()||e.path("/")})}angular.module("meanApp",["ngRoute"]),angular.module("meanApp").config(["$routeProvider","$locationProvider",n]).run(["$rootScope","$location","authentication",e])}(),function(){function n(){console.log("Home controller is running")}angular.module("meanApp").controller("homeCtrl",n)}(),function(){function n(n,e){var t=this;t.user={},e.getProfile().success(function(n){t.user=n}).error(function(n){console.log(n)})}angular.module("meanApp").controller("profileCtrl",n),n.$inject=["$location","meanData"]}(),function(){function n(n,e){var t=this;t.credentials={email:"",password:""},t.onSubmit=function(){e.login(t.credentials).error(function(n){alert(n)}).then(function(){n.path("profile")})}}angular.module("meanApp").controller("loginCtrl",n),n.$inject=["$location","authentication"]}(),function(){function n(n,e){var t=this;t.credentials={name:"",email:"",password:""},t.onSubmit=function(){console.log("Submitting registration"),e.register(t.credentials).error(function(n){alert(n)}).then(function(){n.path("profile")})}}angular.module("meanApp").controller("registerCtrl",n),n.$inject=["$location","authentication"]}(),function(){function n(n,e){var t=function(n){e.localStorage["mean-token"]=n},o=function(){return e.localStorage["mean-token"]},r=function(){var n,t=o();return t?(n=t.split(".")[1],n=e.atob(n),n=JSON.parse(n),n.exp>Date.now()/1e3):!1},i=function(){if(r()){var n=o(),t=n.split(".")[1];return t=e.atob(t),t=JSON.parse(t),{email:t.email,name:t.name}}};return register=function(e){return n.post("/api/register",e).success(function(n){t(n.token)})},login=function(e){return n.post("/api/login",e).success(function(n){t(n.token)})},logout=function(){e.localStorage.removeItem("mean-token")},{currentUser:i,saveToken:t,getToken:o,isLoggedIn:r,register:register,login:login,logout:logout}}angular.module("meanApp").service("authentication",n),n.$inject=["$http","$window"]}(),function(){function n(n,e){var t=function(){return n.get("/api/profile",{headers:{Authorization:"Bearer "+e.getToken()}})};return{getProfile:t}}angular.module("meanApp").service("meanData",n),n.$inject=["$http","authentication"]}(),function(){function n(n,e){var t=this;t.isLoggedIn=e.isLoggedIn(),t.currentUser=e.currentUser()}angular.module("meanApp").controller("navigationCtrl",n),n.$inject=["$location","authentication"]}(),function(){function n(){return{restrict:"EA",templateUrl:"/common/directives/navigation/navigation.template.html",controller:"navigationCtrl as navvm"}}angular.module("meanApp").directive("navigation",n)}(); //# sourceMappingURL=app.min.js.map \ No newline at end of file diff --git a/app_client/app.min.js.map b/app_client/app.min.js.map index cc52abb..2786953 100644 --- a/app_client/app.min.js.map +++ b/app_client/app.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["app.min.js"],"names":["config","$routeProvider","$locationProvider","when","templateUrl","controller","controllerAs","otherwise","redirectTo","html5Mode","run","$rootScope","$location","authentication","$on","event","nextRoute","currentRoute","path","isLoggedIn","angular","module","homeCtrl","console","log","profileCtrl","$inject","loginCtrl","vm","this","credentials","email","password","onSubmit","login","error","err","alert","then","registerCtrl","name","register","$http","$window","saveToken","token","localStorage","getToken","payload","split","atob","JSON","parse","exp","Date","now","currentUser","user","post","success","data","logout","removeItem","service","navigationCtrl","navigation","restrict","directive"],"mappings":"CAAA,WAIE,QAASA,GAAQC,EAAgBC,GAC/BD,EACGE,KAAK,KACJC,YAAa,sBACbC,WAAY,WACZC,aAAc,OAEfH,KAAK,aACJC,YAAa,oCACbC,WAAY,eACZC,aAAc,OAEfH,KAAK,UACJC,YAAa,8BACbC,WAAY,YACZC,aAAc,OAEfH,KAAK,YACJC,YAAa,6BACbC,WAAY,cACZC,aAAc,OAEfC,WAAWC,WAAY,MAG1BN,EAAkBO,WAAU,GAG9B,QAASC,GAAIC,EAAYC,EAAWC,GAClCF,EAAWG,IAAI,oBAAqB,SAASC,EAAOC,EAAWC,GACpC,aAArBL,EAAUM,QAA0BL,EAAeM,cACrDP,EAAUM,KAAK,OAjCrBE,QAAQC,OAAO,WAAY,YAsC3BD,QACGC,OAAO,WACPrB,QAA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,KAAK,EAG/B,OAFAD,GAAUL,EAAQO,KAAKF,GACvBA,EAAUG,KAAKC,MAAMJ,IAEnBjB,MAAQiB,EAAQjB,MAChBS,KAAOQ,EAAQR,OAqBrB,OAhBAC,UAAW,SAASgB,GAClB,MAAOf,GAAMgB,KAAK,gBAAiBD,GAAME,QAAQ,SAASC,GACxDhB,EAAUgB,EAAKf,UAInBX,MAAQ,SAASuB,GACf,MAAOf,GAAMgB,KAAK,aAAcD,GAAME,QAAQ,SAASC,GACrDhB,EAAUgB,EAAKf,UAInBgB,OAAS,WACPlB,EAAQG,aAAagB,WAAW,gBAIhCN,YAAcA,EACdZ,UAAYA,EACZG,SAAWA,EACX5B,WAAaA,EACbsB,SAAWA,SACXP,MAAQA,MACR2B,OAASA,QAlEbzC,QACGC,OAAO,WACP0C,QAAQ,iBAAkBlD,GAE7BA,EAAea,SAAW,QAAS,cAoErC,WAOE,QAASsC,GAAepD,EAAWC,GACjC,GAAIe,GAAKC,IAETD,GAAGT,WAAaN,EAAeM,aAE/BS,EAAG4B,YAAc3C,EAAe2C,cAVlCpC,QACGC,OAAO,WACPhB,WAAW,iBAAkB2D,GAEhCA,EAAetC,SAAW,YAAY,qBAWxC,WAME,QAASuC,KACP,OACEC,SAAU,KACV9D,YAAa,yDACbC,WAAY,2BARhBe,QACGC,OAAO,WACP8C,UAAU,aAAcF","file":"app.min.js","sourcesContent":["!function(){function n(n,t){n.when(\"/\",{templateUrl:\"home/home.view.html\",controller:\"homeCtrl\",controllerAs:\"vm\"}).when(\"/register\",{templateUrl:\"/auth/register/register.view.html\",controller:\"registerCtrl\",controllerAs:\"vm\"}).when(\"/login\",{templateUrl:\"/auth/login/login.view.html\",controller:\"loginCtrl\",controllerAs:\"vm\"}).when(\"/profile\",{templateUrl:\"/profile/profile.view.html\",controller:\"profileCtrl\",controllerAs:\"vm\"}).otherwise({redirectTo:\"/\"}),t.html5Mode(!0)}function t(n,t,e){n.$on(\"$routeChangeStart\",function(n,o,r){\"/profile\"!==t.path()||e.isLoggedIn()||t.path(\"/\")})}angular.module(\"meanApp\",[\"ngRoute\"]),angular.module(\"meanApp\").config([\"$routeProvider\",\"$locationProvider\",n]).run([\"$rootScope\",\"$location\",\"authentication\",t])}(),function(){function n(){console.log(\"Home controller is running\")}angular.module(\"meanApp\").controller(\"homeCtrl\",n)}(),function(){function n(n){}angular.module(\"meanApp\").controller(\"profileCtrl\",n),n.$inject=[\"$location\"]}(),function(){function n(n,t){var e=this;e.credentials={email:\"\",password:\"\"},e.onSubmit=function(){t.login(e.credentials).error(function(n){alert(n)}).then(function(){n.path(\"profile\")})}}angular.module(\"meanApp\").controller(\"loginCtrl\",n),n.$inject=[\"$location\",\"authentication\"]}(),function(){function n(n,t){var e=this;e.credentials={name:\"Simon\",email:\"\",password:\"\"},e.onSubmit=function(){console.log(\"Submitting registration\"),t.register(e.credentials).error(function(n){alert(n)}).then(function(){n.path(\"profile\")})}}angular.module(\"meanApp\").controller(\"registerCtrl\",n),n.$inject=[\"$location\",\"authentication\"]}(),function(){function n(n,t){var e=function(n){t.localStorage[\"mean-token\"]=n},o=function(){return t.localStorage[\"mean-token\"]},r=function(){var n,e=o();return e?(n=e.split(\".\")[1],n=t.atob(n),n=JSON.parse(n),n.exp>Date.now()/1e3):!1},i=function(){if(r()){var n=o(),e=n.split(\".\")[1];return e=t.atob(e),e=JSON.parse(e),{email:e.email,name:e.name}}};return register=function(t){return n.post(\"/api/register\",t).success(function(n){e(n.token)})},login=function(t){return n.post(\"/api/login\",t).success(function(n){e(n.token)})},logout=function(){t.localStorage.removeItem(\"mean-token\")},{currentUser:i,saveToken:e,getToken:o,isLoggedIn:r,register:register,login:login,logout:logout}}angular.module(\"meanApp\").service(\"authentication\",n),n.$inject=[\"$http\",\"$window\"]}(),function(){function n(n,t){var e=this;e.isLoggedIn=t.isLoggedIn(),e.currentUser=t.currentUser()}angular.module(\"meanApp\").controller(\"navigationCtrl\",n),n.$inject=[\"$location\",\"authentication\"]}(),function(){function n(){return{restrict:\"EA\",templateUrl:\"/common/directives/navigation/navigation.template.html\",controller:\"navigationCtrl as navvm\"}}angular.module(\"meanApp\").directive(\"navigation\",n)}();"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["app.min.js"],"names":["config","$routeProvider","$locationProvider","when","templateUrl","controller","controllerAs","otherwise","redirectTo","html5Mode","run","$rootScope","$location","authentication","$on","event","nextRoute","currentRoute","path","isLoggedIn","angular","module","homeCtrl","console","log","profileCtrl","meanData","vm","this","user","getProfile","success","data","error","e","$inject","loginCtrl","credentials","email","password","onSubmit","login","err","alert","then","registerCtrl","name","register","$http","$window","saveToken","token","localStorage","getToken","payload","split","atob","JSON","parse","exp","Date","now","currentUser","post","logout","removeItem","service","get","headers","Authorization","navigationCtrl","navigation","restrict","directive"],"mappings":"CAAA,WAIE,QAASA,GAAQC,EAAgBC,GAC/BD,EACGE,KAAK,KACJC,YAAa,sBACbC,WAAY,WACZC,aAAc,OAEfH,KAAK,aACJC,YAAa,oCACbC,WAAY,eACZC,aAAc,OAEfH,KAAK,UACJC,YAAa,8BACbC,WAAY,YACZC,aAAc,OAEfH,KAAK,YACJC,YAAa,6BACbC,WAAY,cACZC,aAAc,OAEfC,WAAWC,WAAY,MAG1BN,EAAkBO,WAAU,GAG9B,QAASC,GAAIC,EAAYC,EAAWC,GAClCF,EAAWG,IAAI,oBAAqB,SAASC,EAAOC,EAAWC,GACpC,aAArBL,EAAUM,QAA0BL,EAAeM,cACrDP,EAAUM,KAAK,OAjCrBE,QAAQC,OAAO,WAAY,YAsC3BD,QACGC,OAAO,WACPrB,QAAQ,iBAAkB,oBAAqBA,IAC/CU,KAAK,aAAc,YAAa,iBAAkBA,OAGvD,WAMI,QAASY,KACPC,QAAQC,IAAI,8BALhBJ,QACGC,OAAO,WACPhB,WAAW,WAAYiB,MAO5B,WAOE,QAASG,GAAYb,EAAWc,GAC9B,GAAIC,GAAKC,IAETD,GAAGE,QAEHH,EAASI,aACNC,QAAQ,SAASC,GAChBL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,MAChBQ,KAAOQ,EAAQR,OAqBrB,OAhBAC,UAAW,SAASlB,GAClB,MAAOmB,GAAMe,KAAK,gBAAiBlC,GAAME,QAAQ,SAASC,GACxDkB,EAAUlB,EAAKmB,UAInBV,MAAQ,SAASZ,GACf,MAAOmB,GAAMe,KAAK,aAAclC,GAAME,QAAQ,SAASC,GACrDkB,EAAUlB,EAAKmB,UAInBa,OAAS,WACPf,EAAQG,aAAaa,WAAW,gBAIhCH,YAAcA,EACdZ,UAAYA,EACZG,SAAWA,EACXlC,WAAaA,EACb4B,SAAWA,SACXN,MAAQA,MACRuB,OAASA,QAlEb5C,QACGC,OAAO,WACP6C,QAAQ,iBAAkBrD,GAE7BA,EAAesB,SAAW,QAAS,cAoErC,WAOE,QAAST,GAAUsB,EAAOnC,GAExB,GAAIiB,GAAa,WACf,MAAOkB,GAAMmB,IAAI,gBACfC,SACEC,cAAe,UAAWxD,EAAewC,cAK/C,QACEvB,WAAaA,GAhBjBV,QACGC,OAAO,WACP6C,QAAQ,WAAYxC,GAEvBA,EAASS,SAAW,QAAS,qBAiB/B,WAOE,QAASmC,GAAe1D,EAAWC,GACjC,GAAIc,GAAKC,IAETD,GAAGR,WAAaN,EAAeM,aAE/BQ,EAAGmC,YAAcjD,EAAeiD,cAVlC1C,QACGC,OAAO,WACPhB,WAAW,iBAAkBiE,GAEhCA,EAAenC,SAAW,YAAY,qBAWxC,WAME,QAASoC,KACP,OACEC,SAAU,KACVpE,YAAa,yDACbC,WAAY,2BARhBe,QACGC,OAAO,WACPoD,UAAU,aAAcF","file":"app.min.js","sourcesContent":["!function(){function n(n,e){n.when(\"/\",{templateUrl:\"home/home.view.html\",controller:\"homeCtrl\",controllerAs:\"vm\"}).when(\"/register\",{templateUrl:\"/auth/register/register.view.html\",controller:\"registerCtrl\",controllerAs:\"vm\"}).when(\"/login\",{templateUrl:\"/auth/login/login.view.html\",controller:\"loginCtrl\",controllerAs:\"vm\"}).when(\"/profile\",{templateUrl:\"/profile/profile.view.html\",controller:\"profileCtrl\",controllerAs:\"vm\"}).otherwise({redirectTo:\"/\"}),e.html5Mode(!0)}function e(n,e,t){n.$on(\"$routeChangeStart\",function(n,o,r){\"/profile\"!==e.path()||t.isLoggedIn()||e.path(\"/\")})}angular.module(\"meanApp\",[\"ngRoute\"]),angular.module(\"meanApp\").config([\"$routeProvider\",\"$locationProvider\",n]).run([\"$rootScope\",\"$location\",\"authentication\",e])}(),function(){function n(){console.log(\"Home controller is running\")}angular.module(\"meanApp\").controller(\"homeCtrl\",n)}(),function(){function n(n,e){var t=this;t.user={},e.getProfile().success(function(n){t.user=n}).error(function(n){console.log(n)})}angular.module(\"meanApp\").controller(\"profileCtrl\",n),n.$inject=[\"$location\",\"meanData\"]}(),function(){function n(n,e){var t=this;t.credentials={email:\"\",password:\"\"},t.onSubmit=function(){e.login(t.credentials).error(function(n){alert(n)}).then(function(){n.path(\"profile\")})}}angular.module(\"meanApp\").controller(\"loginCtrl\",n),n.$inject=[\"$location\",\"authentication\"]}(),function(){function n(n,e){var t=this;t.credentials={name:\"\",email:\"\",password:\"\"},t.onSubmit=function(){console.log(\"Submitting registration\"),e.register(t.credentials).error(function(n){alert(n)}).then(function(){n.path(\"profile\")})}}angular.module(\"meanApp\").controller(\"registerCtrl\",n),n.$inject=[\"$location\",\"authentication\"]}(),function(){function n(n,e){var t=function(n){e.localStorage[\"mean-token\"]=n},o=function(){return e.localStorage[\"mean-token\"]},r=function(){var n,t=o();return t?(n=t.split(\".\")[1],n=e.atob(n),n=JSON.parse(n),n.exp>Date.now()/1e3):!1},i=function(){if(r()){var n=o(),t=n.split(\".\")[1];return t=e.atob(t),t=JSON.parse(t),{email:t.email,name:t.name}}};return register=function(e){return n.post(\"/api/register\",e).success(function(n){t(n.token)})},login=function(e){return n.post(\"/api/login\",e).success(function(n){t(n.token)})},logout=function(){e.localStorage.removeItem(\"mean-token\")},{currentUser:i,saveToken:t,getToken:o,isLoggedIn:r,register:register,login:login,logout:logout}}angular.module(\"meanApp\").service(\"authentication\",n),n.$inject=[\"$http\",\"$window\"]}(),function(){function n(n,e){var t=function(){return n.get(\"/api/profile\",{headers:{Authorization:\"Bearer \"+e.getToken()}})};return{getProfile:t}}angular.module(\"meanApp\").service(\"meanData\",n),n.$inject=[\"$http\",\"authentication\"]}(),function(){function n(n,e){var t=this;t.isLoggedIn=e.isLoggedIn(),t.currentUser=e.currentUser()}angular.module(\"meanApp\").controller(\"navigationCtrl\",n),n.$inject=[\"$location\",\"authentication\"]}(),function(){function n(){return{restrict:\"EA\",templateUrl:\"/common/directives/navigation/navigation.template.html\",controller:\"navigationCtrl as navvm\"}}angular.module(\"meanApp\").directive(\"navigation\",n)}();"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/app_client/auth/register/register.controller.js b/app_client/auth/register/register.controller.js index 99bf13d..8edaf22 100644 --- a/app_client/auth/register/register.controller.js +++ b/app_client/auth/register/register.controller.js @@ -9,7 +9,7 @@ var vm = this; vm.credentials = { - name : "Simon", + name : "", email : "", password : "" }; diff --git a/app_client/common/services/data.service.js b/app_client/common/services/data.service.js new file mode 100644 index 0000000..1b8baee --- /dev/null +++ b/app_client/common/services/data.service.js @@ -0,0 +1,23 @@ +(function() { + + angular + .module('meanApp') + .service('meanData', meanData); + + meanData.$inject = ['$http', 'authentication']; + function meanData ($http, authentication) { + + var getProfile = function () { + return $http.get('/api/profile', { + headers: { + Authorization: 'Bearer '+ authentication.getToken() + } + }); + }; + + return { + getProfile : getProfile + }; + } + +})(); \ No newline at end of file diff --git a/app_client/profile/profile.controller.js b/app_client/profile/profile.controller.js index b338548..b03db1b 100644 --- a/app_client/profile/profile.controller.js +++ b/app_client/profile/profile.controller.js @@ -4,9 +4,19 @@ .module('meanApp') .controller('profileCtrl', profileCtrl); - profileCtrl.$inject = ['$location']; - function profileCtrl($location) { + profileCtrl.$inject = ['$location', 'meanData']; + function profileCtrl($location, meanData) { var vm = this; + + vm.user = {}; + + meanData.getProfile() + .success(function(data) { + vm.user = data; + }) + .error(function (e) { + console.log(e); + }); } })(); \ No newline at end of file