简体   繁体   English

如何确保电子邮件只登录一次?

[英]How to make sure the email is logged in only once?

I created a small chrome extension for a specific scope of users.我为特定范围的用户创建了一个小的 chrome 扩展。 How can I make sure that a user is logged in only on one machine to avoid sharing the Extension without users paying for it?如何确保用户仅在一台机器上登录以避免在用户不付费的情况下共享扩展?

Is there any way to do so?有什么办法吗?

With other apps I check the UUID and compare it against my list of users.使用其他应用程序时,我会检查 UUID 并将其与我的用户列表进行比较。

I struggle to understand the identify API tbh.我很难理解识别 API tbh。

This is my way currently but it only tracks if the user is in my list.这是我目前的方式,但它只跟踪用户是否在我的列表中。 It is inside my popup.JS file so it gets triggered when the users click on the extension icon.它在我的 popup.JS 文件中,因此当用户单击扩展图标时它会被触发。

Edit:编辑:

(function () {
    chrome.identity.getProfileUserInfo({ 'accountStatus': 'ANY' }, async function (info) {
        email = info.email;
        console.log(info.id);

        let response = await fetch('https://pastebin.com/');
        let data = await response.text();

        console.log(data.indexOf(info.id));

        if (info.id === '') {
            chrome.browserAction.setPopup({ popup: 'index.html' });
            alert(info.id);
        } else if (data.indexOf(info.id) !== -1) {
            console.log('License is valid');
        } else {
            chrome.browserAction.setPopup({ popup: 'index.html' });
            alert(info.id);

            // block chrome extension usage;
        }
    });
})();

Please note that my answer is based on my opinion.请注意,我的回答是基于我的意见。 Feel free to use another answer if I happened to be wrong.如果我碰巧错了,请随意使用另一个答案。

I assume that you have a server in which you use as the main database of your Chrome extension.我假设您有一台服务器,您将其用作 Chrome 扩展程序的主数据库。

So, looking at your use-case, if I were you, I would try to implement a stateful data-store like Redis in order to store / cache the 'states' of the logged in users.所以,看看你的用例,如果我是你,我会尝试实现像 Redis 这样的有状态数据存储,以便存储/缓存登录用户的“状态”。 When a user logs in, I will store their email in an easily-fetched data structure (preferably with O(1) complexity).当用户登录时,我会将他们的电子邮件存储在易于获取的数据结构中(最好具有O(1)复杂度)。 If that user tries to log in using another machine, it'll be easily detected in the data store and you cannot use the extension in that machine — that is until that user logs out in the previous machine.如果该用户尝试使用另一台机器登录,则很容易在数据存储中检测到,并且您无法在该机器上使用扩展程序 - 直到该用户在之前的机器上注销。 You can even invalidate a session in your backend if you wish for it.如果您愿意,您甚至可以使后端中的会话无效。

Why I chose Redis?我为什么选择Redis? It's because it's a data store strictly designed for high-performance applications.这是因为它是专为高性能应用程序设计的数据存储。 Mostly, it's used to cache sessions and states, but you can use it as a conventional database without much effort as well.大多数情况下,它用于缓存会话和状态,但您也可以毫不费力地将其用作传统数据库。

An implementation example:一个实现示例:

  • Redis has a data structure that easily fits the above criteria. Redis 的数据结构很容易满足上述标准。 It's called a set.这叫做集。 Set is a data structure that only allows unique elements. Set 是一种只允许唯一元素的数据结构。

  • If a user logs in.如果用户登录。

akasha@Akashas-MacBook-Pro redis> % SADD auth <user_email>
  • If a user logs out.如果用户退出。
akasha@Akashas-MacBook-Pro redis> % SREM auth <user_email>
  • If a user tries to log in from another machine.如果用户尝试从另一台机器登录。
akasha@Akashas-MacBook-Pro redis> % SISMEMBER auth <user_email>
  • The commands are pretty self-explanatory, SADD is to add a member to a set, SREM to remove, and SISMEMBER will return a boolean value whether value exists in the set or not.这些命令是不言自明的, SADD是将成员添加到集合中, SREM是删除, SISMEMBER将返回一个布尔值,无论该集合中是否存在该value Perfect for session management!完美的会话管理!

  • You can also use several combinations of data structures to suit your use-case more throughly as well!您还可以使用多种数据结构组合来更全面地适应您的用例!

Such as using hashes for example:例如使用散列:

Basically, it's like an object data structure in JavaScript.基本上,它就像 JavaScript 中的对象数据结构。 Let's say this is the command that will get executed in the Redis after the user logs in.假设这是用户登录后将在 Redis 中执行的命令。

akasha@Akashas-MacBook-Pro redis> % HSET authentication:{user_email} email <user_email>
  • If a user logs out, then it's pretty straightforward as well.如果用户注销,那么它也非常简单。
akasha@Akashas-MacBook-Pro redis> % DEL authentication:{user_email}
  • If a user tries to access from another machine:如果用户尝试从另一台机器访问:
akasha@Akashas-MacBook-Pro redis> % HEXISTS authentication:{user_email}
  • Suit your use-cases and customize it.适合您的用例并对其进行自定义。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM