What is canonical ID in Pyramid simpleauth - python

I just got started with Pyramid web development and want to use pyramid_simpleauth for my project. I'm not sure what canonical_id is in its User model.py.
It seems to be just a randomly generated string that gets used in its ACL somehow, can someone shed me some lights what this does and why it's needed?
Thank you.

The reason you want a canonical_id is so that you have something to refer the user by that is not their username or email address. Those two entities may change, whereas the canonical_id should never change.

Related

How to send different messages to users with different settings? discord.py

First of all, I'm a beginner at discord.py. It's hard to explain my problem but I'll try my best:
I'm trying to make a single command which sends different messages to users with different settings.
For example:
Let's say my bot has 2 commands !command and !settings.
A user changes his/her setting with the setting command: "!settings (setting1/setting2/setting3/setting4...)"
If the user uses the !command with (setting1), it will send "response1". But if user has (setting2) it will send "response2", and if user has (setting3) it will send "response3" and so on...
I will appreciate any help :)
I will try my best to explain to you!
To make it happen, we need to store those data in the database!(what is database? to store some data which we can update, delete, and use anytime.) So, we are going to store it in the database. (what we are going to store? we are going to store each user's settings)
For Example! if a person used !settings 1 then we are going to store it in database like this.
{ "user_id": discord_user_id_here,"settings":1}
the discord user id of each person is unique so we use that to store it in the database!.(but where we are going to store it? there is a free best company called "MongoDB" is providing us free database! we will save our data there. and we can completely control it with python)
Now we have saved that user in database and we can do anything in that! but now the important thing, after saved when he uses the first command "!command", we need to fetch the settings from the database! and we can run anything according to his settings!.
LINKS:
MongoDB - https://www.mongodb.com/
MongoDB python Docs - https://pymongo.readthedocs.io/en/stable/
Complete Best Tutorial For MongoDB python - https://www.youtube.com/watch?v=rE_bJl2GAY8

How to store predicates permanently?

When I’m chatting with my bot, it temporarily stores predicates about me in a session file, so that, for the current session, it knows my name, gender, age, etc, whatever comes up about me in that session. So question #1 would be: Is my understanding correct?
If so, where is that session data stored?
I want to put in persistent sessions, so that when I identify myself, the bot loads the predicates associated with me. If someone can help me figure out how to do that, or at least how AIML temporarily stores that info, I’m pretty sure I can capture that info and save it in a file that get’s loaded each time. From there it’s pretty trivial to have files for other users so the chat experience is a bit more personalized, ie: once the bot knows who you are it can retrieve the info it previously knew about you.
In the PyAIML docs there is a very brief discussion about persistent sessions, but I can’t seem to get it to work and I think it’s because I’m not asking it to retrieve the proper info. I’ve contacted Cort, and he’s been wonderful, but he has moved on to other things and doesn’t remember much about this project. He’s also a very busy guy with work and a new family and such, and I figured maybe someone here could help me figure it out as I don’t want to “overstay my welcome” as it were with him.
Any suggestions/ guidance?

public_schema_urlconfig not getting called using django-tenant-schema

I am new to multi tenancy & django. For my invoicing project, I'm using django-tenant-schemas. Now, I'm getting tenant websites up n running. However,its not working with a public client that I've created, with the domain of this public tenant being localhost, ie:
domain_url='{{ hostname }}'
and I've also set my
public_schema_urlconfig = 'invoicesolution.urls_public'
Now, my urls_public file is not getting called, although urls_tenant file gets called, which is in the same folder as the former.
What issue am I having? Any help will be greatly appreciated.
PS: I just edited the public_schema_urlconfig value to random things to see if the project breaks, however, it did not break.
Sorry for the late answer, but I had this exact same problem and just figured it out. You need to create a plublic tenant for your domain and then the urls will work.
https://django-tenant-schemas.readthedocs.io/en/latest/use.html

How to create a unique key from an ID

I am currently working on a text sharing website and I came across the following problem. Each post gets an ID and I would like to be able to easily access the post this by giving the id in the link as a parameter. But since you can simply enter the numbers manually, it is very insecure. My idea is to calculate a longer unique number from the ID. Of course, the number needs to be brought into its original state. The ideal would be a solution in a python. Thanks in advance!
Edit: Correct me if I am wrong but there is no way to reverse the uuid back to the original number?
First thing that needs to be said is that it's not insecure. Even if you calculate some longer number, there is still a chance to access it anyway. Imagine someone creating a generator script trying such numbers. Giving post an ID and security shouldn't be mixed up together.
The best solution would be to add some kind of privileges system or password protection. You can of course use some hash functions for making the id longer if you insist. Not sure what exactly is the idea behind the website, you mean something like Pastebin? Simply add an option for the password protection as I suggested before. Some might use it, some don't.

Query regarding data entry form

I am curious about something I encountered when I was registering on the wakari website. I entered my username which was something like abc.def.ghi and all other information and submitted the form ( or at least tried to submit! ). It threw up an error which said "username must be a valid python variable", so they were obviously doing something in their back-end with usernames as python variables. Would anyone explain to me if this is some sort of design scheme that they are using wherein they store user information as python variables or something like that. Again I apologize since this is not really a specific programming question but this is eating me up and I must know why that happened.
The following is the URL:
https://www.wakari.io/usermgmt/loginorregister
This is pure conjecture. One thing I could see wakiri doing is using the usernames as a module name for your code. That might be interesting. So storing user code as wakiri.<username>. Then the application might be doing an import wakiri.<username> with some interesting stuff in the __init__.py that runs whatever it finds.
Maybe that's it. Or maybe they are storing user code in files on disk. Maybe user code is written out to a file that contains lots of dictionaries that contain code and are named after the username?
Maybe they aren't even using it and just think it is cute to restrict people to valid Python variables.
I'm a Wakari developer, and we've only just caught this question. The short version is that you are pretty safe with a valid UNIX username, and the "error" text should say something using better "plain english" to this effect.
The reason we say the username needs to be a valid Python module name is that we're imagining a day when users could have something like ~/public_python as a place to put directly-shareable code, and then other users could access this via something like from wakari.users import steve. We'd leave it up to you to figure out if you trust user steve enough to import his code directly.

Categories

Resources