2016-08-24 26 views
0

我想處理不活動的用戶,只要他們不活躍即可將其保留。目前,我只是提醒他們,他們不活躍,並讓他們登錄。但是,我只是想拋出登錄錯誤,只要他們不活躍,就把它們放在外面。我的意思是說,他們沒有激活電子郵件令牌。angularjs在登錄時處理非活動用戶

'use strict'; 

angular.module('myapp').controller('LoginCtrl', function ($scope, alert, auth, $state, $auth, $timeout) { 

    $scope.submit = function() { 
    $auth.login({ 
     email: $scope.email, 
     password: $scope.password 
    }) 
     .then(function(res) { 
     var message = 'Thanks for coming back ' + res.data.user.email + '!'; 
     if (!res.data.user.active) 
      message = 'Just a reminder, please activate your account soon :)'; 
     alert('success', 'Welcome', message); 
     return null; 
     }) 
     .then(function() { 
     $timeout(function() { 
      $state.go('main'); 
     }); 
     }) 
     .catch(handleError); 
    } 

    function handleError(err) { 
    alert('warning', 'oops there is a problem!', err.message); 
    } 


}); 

回答

0

您可以隨時用$auth.logout()立即註銷它們。

+0

之後,我應該把這個代碼位? – qpro

+0

在'if(!res.data.user.active)'塊內。您還可以在該塊內顯示警報消息,並告訴他們需要激活。 – peaches