profile-edit-controller.js 888 B

123456789101112131415161718192021222324252627282930
  1. angular.module('NoteWrangler').controller('ProfileEditController', function($scope, $location, User, Session) {
  2. // Redirect if a user is not logged in
  3. Session.authenticate();
  4. // Grab the current session user for it's ID
  5. Session.sessionData().success(function(sessionUser) {
  6. // Create a new User from the session user data
  7. $scope.user = new User(sessionUser);
  8. });
  9. $scope.updateUser = function(user) {
  10. $scope.errors = null;
  11. $scope.updating = true;
  12. // Without NgResource
  13. // User.update($scope.user).catch(function(userData) {
  14. // $scope.errors = [userData.data.error];
  15. // }).finally(function() {
  16. // $scope.updating = false;
  17. // });
  18. // With NgResource
  19. user.$update().catch(function(userData) {
  20. $scope.errors = [userData.data.error];
  21. }).finally(function() {
  22. $scope.updating = false;
  23. });
  24. };
  25. });