Commit 95ca407d5d3c8f69d0cfa145d9a019ee51ca2a5a
1 parent
af3db65c
Exists in
master
and in
6 other branches
Fixes #7
Showing
3 changed files
with
46 additions
and
21 deletions
Show diff stats
src/app/components/auth/auth.service.js
| ... | ... | @@ -37,12 +37,22 @@ |
| 37 | 37 | .then(function(response) { |
| 38 | 38 | $log.debug('AuthService.register [SUCCESS] response', response); |
| 39 | 39 | |
| 40 | - var currentUser = Session.create(response.data); | |
| 40 | + var data = response.data; | |
| 41 | 41 | |
| 42 | - $rootScope.currentUser = currentUser; | |
| 43 | - $rootScope.$broadcast(AUTH_EVENTS.registerSuccess, currentUser); | |
| 44 | - $rootScope.$broadcast(AUTH_EVENTS.loginSuccess, currentUser); | |
| 42 | + if ( data.user && data.user.activated === false){ | |
| 43 | + // usuário criado E não verificado o e-mail | |
| 44 | + | |
| 45 | + } | |
| 46 | + | |
| 47 | + if ( data.user && data.user.activated === true){ | |
| 48 | + // usuário criado E não verificado o e-mail | |
| 49 | + var currentUser = Session.create(data); | |
| 45 | 50 | |
| 51 | + $rootScope.currentUser = currentUser; | |
| 52 | + $rootScope.$broadcast(AUTH_EVENTS.loginSuccess, currentUser); | |
| 53 | + } | |
| 54 | + | |
| 55 | + $rootScope.$broadcast(AUTH_EVENTS.registerSuccess, currentUser); | |
| 46 | 56 | return response; |
| 47 | 57 | }, function(response) { |
| 48 | 58 | $log.debug('AuthService.register [FAIL] response', response); | ... | ... |
src/app/pages/auth/auth.controller.js
| ... | ... | @@ -61,6 +61,7 @@ |
| 61 | 61 | // handle logout |
| 62 | 62 | vm.$scope.$on(vm.AUTH_EVENTS.logoutSuccess, function() { |
| 63 | 63 | vm.currentUser = vm.Session.getCurrentUser(); |
| 64 | + vm._attachCaptcha(); | |
| 64 | 65 | }); |
| 65 | 66 | }; |
| 66 | 67 | |
| ... | ... | @@ -83,16 +84,15 @@ |
| 83 | 84 | var vm = this; |
| 84 | 85 | |
| 85 | 86 | vm.$scope.$on(vm.AUTH_EVENTS.registerSuccess, function(event, response) { |
| 86 | - vm.$log.debug('TODO: handle register success'); | |
| 87 | 87 | vm.$log.debug('[register success] response', response); |
| 88 | 88 | }); |
| 89 | 89 | |
| 90 | 90 | vm.$scope.$on(vm.AUTH_EVENTS.registerFailed, function(event, response) { |
| 91 | - vm.$log.debug('TODO: handle register error'); | |
| 92 | 91 | vm.$log.debug('[register error] response', response); |
| 93 | 92 | |
| 94 | - var reason = response.data.message; | |
| 95 | - vm.errorMessage = reason; | |
| 93 | + // REMOVED: feedback alread on "reject handler" | |
| 94 | + // var reason = response.data.message; | |
| 95 | + // vm.errorMessage = reason; | |
| 96 | 96 | }); |
| 97 | 97 | |
| 98 | 98 | vm.$scope.$on('oauthClientPluginResult', function(event, response) { |
| ... | ... | @@ -103,6 +103,12 @@ |
| 103 | 103 | // var user = response.data.user; |
| 104 | 104 | }); |
| 105 | 105 | |
| 106 | + vm._attachCaptcha(); | |
| 107 | + }; | |
| 108 | + | |
| 109 | + AuthPageController.prototype._attachCaptcha = function() { | |
| 110 | + var vm = this; | |
| 111 | + | |
| 106 | 112 | var stop = null; |
| 107 | 113 | stop = vm.$interval(function(){ |
| 108 | 114 | var $el = angular.element('#serpro_captcha'); |
| ... | ... | @@ -137,17 +143,26 @@ |
| 137 | 143 | // TODO: mensagens de sucesso |
| 138 | 144 | // 'Cadastro efetuado com sucesso.' |
| 139 | 145 | // 'Verifique seu email para confirmar o cadastro.' |
| 140 | - vm.messageTitle = 'Cadastro efetuado com sucesso!'; | |
| 141 | - vm.successMessage = 'Verifique seu e-mail para confirmar o cadastro.'; | |
| 146 | + vm.signupMessageTitle = 'Cadastro efetuado com sucesso!'; | |
| 147 | + vm.signupSuccessMessage = 'Verifique seu e-mail para confirmar o cadastro.'; | |
| 142 | 148 | vm.redirectBack(); |
| 143 | 149 | }, function(response) { |
| 144 | 150 | vm.$log.debug('register error.response', response); |
| 145 | 151 | |
| 146 | - var message = response.data.message; | |
| 147 | - vm.errorMessage = message; | |
| 148 | - | |
| 149 | - if(response.data.code === 500){ | |
| 150 | - vm.internalError = true; | |
| 152 | + vm.internalError = true; | |
| 153 | + | |
| 154 | + switch (response.data.code) { | |
| 155 | + case 400: // bad request | |
| 156 | + var errors = JSON.parse(response.data.message); | |
| 157 | + if(errors && errors.email){ | |
| 158 | + vm.signupErrorMessage = "E-mail já está em uso." | |
| 159 | + } | |
| 160 | + break; | |
| 161 | + case 500: | |
| 162 | + vm.signupErrorMessage = message; | |
| 163 | + break; | |
| 164 | + default: | |
| 165 | + break; | |
| 151 | 166 | } |
| 152 | 167 | |
| 153 | 168 | ... | ... |
src/app/pages/auth/signin.html
| ... | ... | @@ -8,14 +8,14 @@ |
| 8 | 8 | <section role="main" class="section-gray auth-content"> |
| 9 | 9 | <div class="container"> |
| 10 | 10 | <div class="row"> |
| 11 | - <div ng-if="pageSignin.currentUser"> | |
| 11 | + <div ng-if="pageSignin.currentUser || pageSignin.signupMessageTitle"> | |
| 12 | 12 | <div class="row"> |
| 13 | 13 | <div class="col-sm-8 col-sm-offset-2"> |
| 14 | 14 | <div class="feedback-message"> |
| 15 | 15 | <show-message |
| 16 | 16 | type="'success'" |
| 17 | - message="pageSignin.messageTitle || 'Você está logado!'" | |
| 18 | - description="pageSignin.successMessage" | |
| 17 | + message="pageSignin.signupMessageTitle || 'Você está logado!'" | |
| 18 | + description="pageSignin.signupSuccessMessage" | |
| 19 | 19 | ></show-message> |
| 20 | 20 | |
| 21 | 21 | <div class="row"> |
| ... | ... | @@ -35,7 +35,7 @@ |
| 35 | 35 | </div> |
| 36 | 36 | </div> |
| 37 | 37 | </div> |
| 38 | - <div ng-if="!pageSignin.currentUser"> | |
| 38 | + <div ng-if="!pageSignin.currentUser && !pageSignin.signupMessageTitle"> | |
| 39 | 39 | <div class="col-sm-5"> |
| 40 | 40 | <div class="row"> |
| 41 | 41 | <div class="col-md-12"> |
| ... | ... | @@ -96,10 +96,10 @@ |
| 96 | 96 | </p> |
| 97 | 97 | </div> |
| 98 | 98 | </div> |
| 99 | - <div class="row" ng-if="pageSignin.errorMessage"> | |
| 99 | + <div class="row" ng-if="pageSignin.signupErrorMessage"> | |
| 100 | 100 | <div class="col-sm-12"> |
| 101 | 101 | <div class="alert alert-danger"> |
| 102 | - {{pageSignin.errorMessage}} | |
| 102 | + {{pageSignin.signupErrorMessage}} | |
| 103 | 103 | </div> |
| 104 | 104 | <div ng-if="vm.internalError"> |
| 105 | 105 | <p>Este erro parece ser um problema interno.<br/>Por favor, tente novamente mais tarde.</p> | ... | ... |