javascriptangularjssatellizer

angularjs to handle inactive users when login


I want to handle the inactive users and keep them out as long as they are not active. Currently, I am just alerting them that they are not active and letting them log in. However, I just want to throw in a login error and keep them out as long as they are not active. By "active" I mean, they haven't activated the email token.

'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);
  }


});

Solution

  • You could always log them out immediately with $auth.logout().