dpoxk64080 2015-10-27 21:32
浏览 6

宁静的查询权限

I am creating a simple app to control user access.

I have one database table which have all user information and I need to create different privilege for different user group. For example, the manager can search all people, the Team leader can only list all team members.

I would like to know how I can approach this.

  • 写回答

1条回答 默认 最新

  • dongwang3066 2015-10-27 21:37
    关注

    Authenticate based on session via cookie, or an authentication token.

    For example: /api/userinfo?api_key={insert key here}.

    In your back end (Sudo code):

    <?php
    $user = $db->query("SELECT * FROM users where api_key = `{$_GET[api_key]}`");
    
    if ( $user is manager ) {
       $results = $db->query("RUN THIS QUERY, because user is a manager, and return results");
    } else {
       $results = $db->query("RUN THIS QUERY, because user is normal users, and return results");
    }
    
    echo json_parse($results);
    
    评论

报告相同问题?

悬赏问题

  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题