Anvil: Web Apps with Nothing but Python Transcripts
Chapter: User management and authentication
Lecture: Registering a new user

Login or purchase this course to watch this video and the rest of the course contents.
0:00 With our user service set up let's go back to our HomeForm here and work on register. So if somebody comes in here and clicks register
0:09 we want to show them a form, gather their information create an account and then set a cookie potentially to remember across at least this session.
0:18 We're going to do that, and then once we have the ability to create accounts, we'll be able to later log in and log out of those accounts.
0:25 So here's our register, click handler and turn out if we go way to the top we have anvil.users, and this is the thing
0:32 that we're going to use, to actually interact with it so let's go back down here, our register and we say anvil.users.signup_with_form.
0:44 You can say sign up with just email, just Google or whatever. We're just going to say sign up with form and we're just going to run it for a second
0:51 and show you something that's kind of annoying. We don't need a pass here. Once you do this we maybe want to refresh
0:56 and send you back home, say go home. Now that we have accounts, what we want to do when you go home, is to, let me load up this HomeForm here.
1:06 Let's say that's over here. We want to check and determine whether or not there is an account.
1:12 If there is an account, show the anonymous component here or just hey welcome to our app, you should sign in create an account.
1:19 Or, the one that is the details hey welcome to your account, here are your details. So we're going to deal with that in just a second.
1:26 Let's take it one thing at a time but it turns out to be pretty easy. So down here, we going to go and register and then we're going to go back home.
1:34 Just to refresh the screen here. Let's go ahead and run this. So we're on our anonymous page if we click register, now all of a sudden
1:41 we get this cool signup. So we can sign up with an email or we can sign up with Google. Now, how do I decide that I didn't like that form?
1:53 Huh, well it turns out if for some reason you click that and you don't actually want to register to bad, you've got to refresh the page.
2:00 So let's go fix that really quick. That's kind of annoying but I wanted to show you that so we have this allow_cancel is True
2:07 and now if we run it, it's probably the right experience that we're looking for. So click here, and sign up with email or with Google
2:13 or you know what, actually never mind, forget it. So we're going to go over here and we're going to sign up.
2:20 We just going to sign up with a simple email. No problem there, and say remember me. So we'll say sign up. Give this just a second, and it went home.
2:29 We got some output over here. So it automatically created some columns in that table which didn't exist before right
2:37 so it basically created that table over in the user service, and now you should be logged in. Our app didn't understand that.
2:45 It do anything. So, that's okay though. We've already signed up. Let's see what else we can do here. We can also say remember by default, that is true
2:53 but you could disable that if you want. Last thing, let's see if our user actually got created here. We go to our data tables.
3:01 Look at that, there's a michael@talkpython.fm. This account is enabled, is_pro is unset. But check this out, we have a nice password hash here.
3:11 We have the remember login details that have been set and the last time that we logged in. Super cool huh?
3:19 So really really great to be able to just check a few boxes, call a simple function, and have Envol handle all the tricky user management stuff for us.


Talk Python's Mastodon Michael Kennedy's Mastodon