P
P
Pogran2016-12-19 16:20:29
Angular
Pogran, 2016-12-19 16:20:29

How to make complex access rights?

I want to make the access rights that the user will constantly change, i.e. not just admin, user, etc. For example, we have a user. He has access to a course. And this course is only the first lesson. And until he passes the first lesson, others will not be available to him. Also, the administrator, for example, can randomly open one of the lessons. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitaly, 2016-12-20
@Pogran

All logic in Angular 2 is done through service classes, in which you can perform checks of any complexity. It is enough to perform 3 simple steps:
1. For example, in user.service.ts we will add information about the authorized user.
2. Let's create the AuthGuard service, which will be responsible for authorization. It must implement the CanActivate interface

@Injectable()
export class AuthGuard implements CanActivate {
  constructor(private userService: UserService) {}

  canActivate(route: ActivatedRouteSnapshot, state:RouterStateSnapshot): Promise<boolean>|boolean {
    return this.userService.isAuth;
  }
}

3. In the description of the paths, we indicate the class responsible for checking access:
{
    path: 'logout',
    component: LogoutComponent,
    canActivate: [AuthGuard]
  },
  {
    path: 'login',
    component: LoginComponent,
    canActivate: [GuestGuard]
  },

In this example, all complex checks can be done in the get isAuth() of the UserService.

D
D3lphi, 2017-05-09
@lemonlimelike

You first use mysqli_query(), and then mysql_fetch_array(), that is, in the first case, you use the mysql php extension, and in the second, mysqli. You already decide. To fix the error add the letter i to get mysql i _fetch_array.
As a result, the code will look like:

<?php
  $res = mysqli_query($connection, "SELECT videos.* FROM video_category join category ON category.id = video_category.category_id JOIN videos ON videos.id = video_category.video_id");
  $video = array();
  while($row = mysqli_fetch_array($res)){
    $videos[] = $row;
  }
?>

T
Twelfth Doctor, 2017-05-09
@verdex

Your $connection variable is not declared anywhere, as you can see from this code. In general, you gave him an object instead of a resource ($connection)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question