|
1 | 1 | angular.module('mainApp')
|
2 | 2 |
|
3 |
| -.controller('miPerfilController', function ($scope, SweetAlert, dataService, authService, $rootScope, $location, $window) { |
| 3 | +.controller('miPerfilController', function ($scope, SweetAlert, dataService, authService, $rootScope, $location, $window, Upload) { |
4 | 4 |
|
5 | 5 | $scope.username = $rootScope.loggedUser
|
6 | 6 | $scope.mail = $rootScope.mailLoggedUser
|
@@ -38,7 +38,7 @@ angular.module('mainApp')
|
38 | 38 | };
|
39 | 39 |
|
40 | 40 | $scope.save = function(toggle) {
|
41 |
| - let {username, mail, leng} = $scope |
| 41 | + let {username, mail, leng, profileImg} = $scope |
42 | 42 | if (toggle === 'username') {
|
43 | 43 | dataService.editProfile(username, toggle)
|
44 | 44 | .then(() => {
|
@@ -82,4 +82,32 @@ angular.module('mainApp')
|
82 | 82 | })
|
83 | 83 | }
|
84 | 84 | }
|
| 85 | + |
| 86 | + $scope.fileSelected = (files) => { |
| 87 | + if (files && files.length) { |
| 88 | + $scope.file = files[0]; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + $scope.uploadFile = function() { |
| 93 | + const url = '/users/edit-profile' |
| 94 | + const file = $scope.file |
| 95 | + |
| 96 | + // show spinning when uploading |
| 97 | + // $scope.uploading = true; |
| 98 | + // document.querySelector('.preview').onload = () => { |
| 99 | + // $scope.$apply( () => $scope.uploading = false ) |
| 100 | + // } |
| 101 | + |
| 102 | + Upload.upload({ url, file }) |
| 103 | + .success( ({imageLink}) => { |
| 104 | + authService.logout() |
| 105 | + $location.path('/') |
| 106 | + } ) |
| 107 | + //.progress( console.log ) |
| 108 | + } |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
85 | 113 | })
|
0 commit comments