D
D
Dmitry Kuznetsov2016-04-24 22:05:57
Angular
Dmitry Kuznetsov, 2016-04-24 22:05:57

Templates for authorized users and not authorized?

I am writing a website in Angular. Wrote a simple authorization. I have a side menu (like enter/register), which should disappear and another one should appear, there is a user authorized. So what's the best way to do this?
Not only is the menu supposed to change like this...
And one more thing:
How to configure the Apache server to work with Angular?
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2016-04-24
@dima9595

When starting the application, do this:

angular
    .module('App')
    .run(['$rootScope', 'authFactory', function ($rootScope, authFactory){
      $rootScope.isAuth = function () {
        return authFactory.SessionState();  // в методе проверяем состояние сессии, например наличие нужных кукисов или данных в локалсторадж, и возвращаем true или false
      }
    }]);

In the template we write like this:
li(ng-if='!isAuth()')
  a(ui-sref='login')
    span.glyphicon.glyphicon-lock
    |  Вход

li(ng-if='isAuth()')
  a(ng-click='logOut()')
    span.glyphicon.glyphicon-log-out
    |  Выход

This is to globally, for the entire page. In general, use directives and controller methods

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question