【问题标题】:Database issue - how do I set up user accounts/pswds so they can ONLY add/change THEIR data?数据库问题 - 我如何设置用户帐户/pswd,以便他们只能添加/更改他们的数据?
【发布时间】:2014-02-01 16:27:30
【问题描述】:

好的...我正在努力创建一个移动应用程序,它允许两组用户做两件不同的事情。

基本上,该项目的目标是这样的:

A 组用户:创建帐户/pswd,并可以将他们的数据输入数据库和/或更改他们现有的数据(但仅限于他们的数据)

B 组用户:可以在数据库中搜索 A 组插入的信息。接下来我想设置它,以便他们可以创建一个用户帐户,这样他们也可以将关键信息保存到他们的帐户以便更快地回忆(这样他们就不必定期查找他们搜索的信息)——但这是不正确的。

我使用我的网络托管帐户提供的 mySQL 设置了一个关系数据库(这似乎是最简单的方法)。

我只是想弄清楚如何处理用户帐户创建/身份验证位,因为每个组应该只能更改/插入数据到他们自己的帐户,但可以搜索其他人提交的信息。

提前致谢。

【问题讨论】:

  • 请添加您的代码。

标签: mysql relational-database user-accounts authentication


【解决方案1】:

使用 mysql 设施来管理权限:角色、用户和权限。

浏览 mysql 官方文档(即http://dev.mysql.com/doc/workbench/en/wb-adding-roles.html)。

您可以创建两个角色:可以INSERT/SELECT/UPDATE 一组表的 groupA,可以在另一组表中执行相同操作的 groupB。

您可以只在您想要的表中分配INSERT 权限,但在所有表中分配SELECT 权限。

希望这些信息能给你带来一些启发......

【讨论】:

    【解决方案2】:

    首先,这听起来像是一个巨大的项目,我相信有一些框架可以为您做到这一点。但是,如果您尝试自己执行此操作,请继续阅读。 这可以通过多种方式完成。我会尽量详细。这需要 SQL 以及应用程序开发/软件工程知识。

    第 1 步:设置数据库 您将需要以下表格:所有 id 都是自动递增的主键,其他字段可以是 varchar,但名称中包含日期的字段除外

    1. 会话 [id, uid, random_token, datecreated]
    2. resourcescope [消除,名称]
    3. 用户 [uid, first, last, email, username, salted_pwd]
    4. user_type [id、名称、描述]
    5. user_resourcescope [id, uid, rid] //userid和resourcescope之间的查找表

    我更喜欢使用 Java 或 python,因为您可以使用依赖注入或装饰器。因此,在检查用户是否具有访问权限时,您不必编写大量代码。

    将这一切付诸实践。

    1. When a user signs up, you save them into a user database. Depending on the user type, you give them different permissions. Next, you save the user permissions inside the user_resourcescope table.
    

    您现在应该拥有以下内容。 用户表

    UID | first | last | email           | username  | salted_pwd    | usertype
     1  | james | iri  | example@isp.com | jiri1928  | klasdjf8$kljs |     1
    

    用户类型表

     usetype_id | Name
         1      | Basic users
         2      | Searcher 
    

    资源范围表

       rid    | Name
        1     | FindContent
        2     | CreateContent
        3     | DeleteContent
    

    User_Resourcescope

      id  | uid  | rid
       1  |  1   |  1
       2  |  1   |  3 
    

    会话

    id  | uid  | random_token    | datecreated
     1  |  1   | ldkjfald882u3u  | 1391274870322
    

    每个资源代表系统内的一个请求。例如,

    http://api.myapi.com/content/add - This would be associated with the ResourceScope CreateContent
    http://api.myapi.com/content/delete- This would be associated with the ResourceScope CreateDelete
    http://api.myapi.com/content/search - This would be associated with the ResourceScope SearchContent
    

    当有人尝试创建内容时,您可以通过验证他们的会话信息来检查他们的信任是否正确,并通过检查 User_Resourcescope 表来检查他们是否具有正确的权限。

    To prevent users from deleting content that is not theirs. Inside the content table you can add a creator field and put the user id associated with the content. And if someone try to delete content you can check their user id against the creator field. 
    

    【讨论】:

      猜你喜欢
      • 2011-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-23
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多