48 - User Authentication - Register, Login and Logout - Django | DRF | React w. Data Analysis

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello hello and welcome back today we are talking about authentication so again django comes with a lot of functionality and one of the functionalities that i really appreciate is the authentication and security django is not you know lightweight it comes with a lot of bells and whistles that often we don't use because it's just like it's there if you want it and you don't have to use it security is probably something that we all want to use and authentication and and you know making sure that that we handle user credentials in a secure way this is something we don't want to think about it involves a lot of work and django gives it to us for free so for that i'm gonna create a new new app let's call it startup and let's call it accounts and you can call it whatever you want you can call it my auth because auth already exists in in django uh you can call it users i like to call it accounts because the first tutorial i did with django uh called accounts and just i'm sticking to this okay so what's the first step after creating a new app we go to mark's portfolio settings and we add that to here so let me just add it here okay accounts so that's in here and then i want to lay out what are we gonna do uh with those accounts so what kind of views are we gonna create there and i was thinking should we go with class based views or or function based views and i mean if if we use class-based views um the beauty of that is you can simply put them into your urls and they will work uh but i think we want to have a bit more control and also change some forms for logging in and registering so i'm gonna go with the function based views so the views i want to build are register login and logout we're not gonna look at forgot password just yet because i want to set up the email sending service for us so before that we are gonna just stick to the basic register login and logout okay so here is a boilerplate that i want to use so we'll have register login view and logout view i put that view suffix here because um login and logout already exist in django so i just don't want to have a conflict there so now we have to build those and obviously these are not finished it's just a boilerplate for us to use um just because i want to put that into urls and then we have to build those htmls and put the logic here okay so let's create a urls file you can add that there and in urls we want to go from from [Music] django.urls import path and from here import views okay and the app name is accounts and for url patterns turns we want to put those okay so path and the first one will be register slash and that's going to take the views on the register um function and the name is register okay comma duplicate and login and we're going to use login view and that's our login and the last one will be logout we take the logout view and we call it logout okay so we have our three views here and obviously they have to go to the main urls file the same way as for example air pollution so i'm going to just do a duplication here and go to here and do accounts and go to accounts urls okay so that makes uh the views um hooked up we still don't have the templates so let's turn let's close the urls settings can go as well and let's build a register html first so maybe i'll just make those two um boilerplates as well so let's go to templates and in here we want to create a new file and it's going to be accounts slash register html okay add it as a boilerplate we want to add obviously the extends base html base html uh i want to load static just in case we use any static and then obviously we need to put this block content on in this block and block okay and that's where all of the html goes in and oh let me just stop this let me just copy this and create the login html2 so now our so urls can go register let me see views okay so as you can see it's not highlighted anymore by pycharm so it means that those two files exist so now we can test them very quick just to make sure that we have them where we want to have them so let's start the server here and i can see okay i made a mistake somewhere ah yes i left those brackets here they shouldn't be here because it's uh we're not calling this um function we are only passing it as an object okay now it works let's go to our website and let's go so again if you set it up this way that in main urls you have account slash and we include whatever is in accounts urls and in accounts urls we have register login and logout we should be able to access those urls this way accounts login okay and login seems to be working it is extending our base and it's putting nothing into the content and as you can see it it's the url is there register seems to be there as well and if i go to login sorry log out it does redirect me to login so it seems to be working okay the last file we need is the forms and i think it's going to be a great practice for for using forms as the last time we spoke about uh customizing forms and it's always going to be a great practice here so let's add a forms dot py you can add it now okay so we need to get from django import forms that's the first one and i want to start with the user creation form for register okay so let's from django dot contrib dot auth dot forms import user creation form okay that's going to be the one that we want to customize and then there is from django dot contrib dot dot models so you can see that in the same kind of package in auth we took from forms this form and then from models we want to uh get import models import user okay and that's a model just like we built before models but it's a built-in um django model that comes with django automatically uh in a package for free so we will use it to use it with the user creation form okay so let's go and build this class called let's say custom and then just user creation form so it's the same name but with custom inside and then we're gonna pass here user creation form okay uh and first you might remember class meta and we pass this model there so this is where we specify what kind of model we're gonna use for this creation okay so that's our model form which is called user creation form because it's somehow customized model form so if it's a model form you need to pass the the user in here so the model that we're using for this model form and then we need to specify what fields we're using and it's a list of strings by default as far as i know django gives you a username email password1 and password2 and we want to change it slightly we want to give it a first name last name email and password1password2 okay uh let's go down here and in here we're gonna customize those fields right and by the way just as a as a cheat we can go and using command button uh we can go into this user creation form and see how it was written uh by default so as i mentioned we have this password one password two in here and then let me see so we might wanna go to model form no so in here we have password one password two i'm pretty sure i could see more somewhere so we have user name and you just use username field and then we have this password one password two so at least we have this uh you know we can see that okay they're using something called password input for passwords so maybe we can get some inputs for text for email and so on so let's go back here and what i want is we actually yeah we want to specify different input types for different fields so let's go and do first name will be some forms dot field and we're going to pass some stuff in here then we are going to have last name and then there is email then we have password one and password two and if you remember to specify what kind of widget would be used for this what kind of field in html is supposed to be used for this uh we go inside of the brackets here and we specify okay i want this to be forms dot text input okay that's for the first name i want it to be text input which is like inline text text input and i want to pass some attributes there okay simple html attributes go in here so i'm going to just put a line right here and we can specify whatever classes id whatever html attributes you can put into text input you can put it in put it in here so i want to give it a class and what class do i want to give um in here let me see let me go back to my files and i want to open um document downloads i want to open my templates and go to register html so inside let me just show you here inside of this bootstrap sb admin 2 the stuff that we download from bootstrap templates site there's this register html in here so let me just like put it in here it's not in our project but we can still open it in our ide so let me just push it all the way to the right so i can i can see that it's not in our project but it's you can see i highlighted already stuff that i want to copy because i i worked with it already but basically yeah i would do this i'll just go into this html template and it doesn't recognize base like we built this base html for django but obviously plain html wouldn't see it it would just copy and paste the base every every single time so we need to recognize where's our base and where is our content and that's what i did i found the body and then this container here and i know that we built it around this container so whatever is inside is whatever we want to copy so i have it selected already it's between these two divs so i'm going to just copy this and go to register html and paste it in here and let's have a quick look at the at the classes that are being passed to the text inputs we have form control and form user so i can just take this okay and i can see this placeholder here so anyway let's go back to forms and now we pass this in here so the class is form control and form control user and that's how we get this specific template styling okay and you'll see what i'm talking about in a second and the next element here was a placeholder which was first name it's gonna be pretty similar to all of those fields which is uh we're gonna change this for email and password but i can copy this and one by one we can fill it fill it out so this will be only different in here so that's the last name uh in here we want to put in the instead of text input we want to make it email input and put the attributes will be pretty much the same except for this placeholder if you want to have a placeholder you don't have to because we're going to have the labels uh and you'll see in a second how okay and then we have this password one password two so this is going to be slightly different so again that's going to be password input uh the same classes that's going to be the password here and so what we can pass except for the for the attributes so here we are passing the attributes but we can also add a little bit more to customize more than just the field which in this case i want to customize the label and you know what i'm going to leave it for now and you'll see what i'm talking about when we generate it without putting the label in and then you'll see why would you want to change the label so password input that's all the same and in here we just say confirm password okay so we have our simple um boilerplate for this user creation form we can pass it to our view now so let's go to the views so in our views i want to add my custom from forms import custom create using user creation form and i want to pass it in here at the beginning form is our custom user creation form and i instantiate it in here and now so if we post it to the same view to register we want to actually save it so if request that method is post then do this the form is actually something else form will be also the custom creation form but that's going to take some data in so request.post so now we are handling the post the information from the post request and we pass it to this custom user creation form and it knows what to do with it already we just have to validate it so if form dot is valid we can go ahead and do form dot save so look how much abstraction uh we get from from this uh form uh we just have to check if it's valid obviously we can overwrite is valid and we can overwrite save and we will by the way for for this form in a second and then we want to send a message so we need to go to contrib uh from django.contrib import messages okay we want to say here messages dot success we pass the request in here and then some message here let's make it so we make a formatted string and from form as you might remember we take the clean data and we want to take the email here so let's use the double quotes here um email okay on having this email we can say registered successfully okay so email registered registered successfully okay registered successfully and in here we have some context so we want to pass it in here we want to use that form in our register html okay so let's go here and let's say that in context form is our form so into a context variable name form we're passing our form either from here or from here okay and then we can very easily use that in our html so let's go to accounts register and in here so we have already something and if you want to see what it was you can go and go to start bootstrap themes go to our sb2 which is that one here open and if you go to components no utilities no pages register so that's the default that's what they want it to look like we have some so that's the rounded uh thing that we get from this class that i put into our form let's go to forms that's the form control user that makes this so nice and round so one thing is we can lay it out the same way it's a lot of more work but we can get exactly the same view or we can do a very simple shortcut which i prefer because it's way less work way less customizing here's our form we can rip it all out whatever was in here it can go and by the way we also won't be using the gmail and facebook register uh for now at least and in here i'm gonna do this csrf token you always have to pass that inside of a form uh also in here you might wanna mention that it's gonna be method post okay crs token and then having this form in the context we can do this form uh let me see if it works yeah i think we have to also say it's crispy so let's all go here and let's load crispy forms tags crispy forms tags okay it's gonna show as if it was not recognized but it should work and if i pass the pipe in here and say make it crispy it should use some of the crispy formatting which makes it just look nice and also it uses our classes that we pass in there okay so what about we check what we can find on our site so let's go to register now okay we have to run our okay reload and as you can see the difference is visible so if i go to the sb it looks somehow you know fancier because you see first name and second name is in the same line and then you know it's it more is happening in here this one is a bit more plain we have to have those labels here and i'm i'm thinking it's fine like i like it i don't mind that it's this way we have a label we have those it's it still looks nice so i'm gonna just stick to this i'm gonna i'm gonna leave it that way because it's so much quicker uh instead of going through line by line uh through all those inputs i can just say hey form b crispy and and print out whatever i told you to print out in the in the forms file i forgot about the button here so i think it was there but i can create it very quick that's going to be type submit and we have to pass classes here and that was the button button that was i think primary primary and then button user and i know that because i have a cheat sheet on my right side and then we had i just deleted too much uh block okay that's gonna be the block you can close this and inside of that button we just say register account okay so if i go back here and refresh we have our register account which will send us to register v with post request so one thing that i wanted to show you is what happens with the labels without passing the label we just get a capitalized field name without underscore so for example first name uh we capitalized it and we took the underscore we put a space in here so that's the difference and also with the password here instead of having a password and confirm password we just have the field name which is capitalized and we don't want that we want that to be password and this to say confirm password so let's go here and it can be very easily changed so outside of attributes so we need to be outside of attributes in here i want to say label oh no sorry just here okay so we have to be outside of widget actually so it's not going to be the password input we just do it outside and one of the attributes we can we can pass to the field itself is the label that's going to be password and that's going to be label is confirm password okay and let's refresh reload password and confirm password is here it's a duplicate of what is inside of a placeholder so it's your choice if you want to stick to both of them or maybe just get rid of the placeholders i was just showing you that you can pass that in there and it works if you want if you want them to work there so now the way the registration works here is that we have this first name last name email and password so these will be the the fields that will be filled out and we do want to have a username for each user it's it's actually a good idea to have a username and what do you think what the user name should be first name last name email i'd say email is the most unique thing email is always unique to an account so what i want to do is whenever we save this form i want this form to say okay email is this so also username will be this okay and that's where we can use the save method of the of the uh form here so we can override the save method so let's go down here and overwrite save and pycharm is already being uh helpful and gives me all the attributes that i need for over overriding save which is very nice so first thing i want to get the instance and to get that and instance is just like the user being saved but what i want to say is okay do whatever you do super do whatever you do with the save but you know what don't commit yet i don't want to commit just yet asked which means don't save in database i just want to get the instance the object in python and do something to it and then save instance dot username so what i want to do is i want to pass the email of the instance email into username okay it was it was blank before because we don't have that field in here so it would be blank but what i want to say is hey pass that email into username and then if commit is true or just you can say commit instance save save and we're saving not with the form but we are saving with the user model so it's a different method so we basically save it to the database and then we have to return the instance okay so that's all you have to do for overriding save and adding this feature that is saving an email in the username so let's try it out let me just refresh here so let's register a person here so let's do marek and then kubiak and then maybe abcd at gmail.com and then some password here and the password has to be like django password so if i make it too short for example and try to register we already get this this password is too short it must contain eight characters because that that's what comes with django forms which is beautiful like you don't have to set it up obviously you can change it in validation if you want and also in settings you can change the typical um let me see here i was looking at some constraints here so we have like minimum length validator common password validator so we have a couple of different validators here um but yeah so like you can change everything but it's nice to keep uh those is that enough yeah that should be enough okay and let's register and abcdgmail.com registered successfully so where is it now let's go to admin so localhost 8080 admin and login as an admin and let's go here okay and we are in the users so we have this admin user here that we built using create super user in the console at the very beginning uh and in here we have the new user which uses the username abcd and then email also is abcd gmail.com then we have first name second name it's not a staff account so which means like it's not an admin so right now i'm logged in as an admin uh if i logged in as abcd gmail.com i wouldn't be able to see this okay and whoever would try to get into admin they wouldn't if they don't have this staff status if i go in and i change that i can still change that and by the way you have a couple of nifty functionalities coming with users it's not just name and surname you have like groups and and different permissions so it's pretty cool and i'm not going to go through it today but it's it's interesting stuff can be very useful for general kind of user management and permission management just in register html one last thing is we have those two references here that we don't want to reference to simple html we want them to be links to like django system url thing uh for now we are not doing forgot password we wait for email to be hooked up so i'm gonna just get rid of this and in here we can change this to account login so just change it to the typical url tag with [Music] accounts login okay let's check this out here refresh and if we go to register so accounts slash register we should have this link here already have an account login okay and we're in login but we don't have the html done yet okay so let's work on login now i would like to start with the views so in here we have our place for login view and let's start working on it so one thing is that let me just put a breakpoint here and change this into the debugger and go here and try to open login and let's have a look what do we have in request and how can we say if we are logged in or not so here is a user that is okay so i am an admin so i am already using the authentication from just the beginning just from the the moment i created this admin and i started using this i already tapped in into the you know the user django user system uh so you can see that in here we are authenticated and is authenticated is true okay if i looked out let me go here and log out and let's refresh our login again you'll see that the user's false is not authenticated it's an anonymous user okay so we can use that here we can say if the user is not authenticated uh sorry if the user is authenticated then just don't try to log in just redirect me somewhere else to home page maybe and say that i'm already logged in so let's do that if user dot is authenticated uh just message and i'm gonna use info because it's not a big deal i'm not gonna say a warning or error it's just you know you're still logged in if you want to log out and just go to logout and by the way i want to put a bit of html in this message i don't want it to be plain just text i want to put a bit of styling there so let's try that i don't know if i can do it now so let's try you are already logged in as on let's just put f in here so we can put a bit of data request dot user dot email and let's put b around this okay let's let's try to put it into bold uh okay just period and let's give it a go let's see if i save this and it refreshes if i log in so let me and it's not going to show anything so let me change that to username okay let me log back in as admin so just log back in as admin and i'm in here um so i'm going to try to go to login enter and it took me here it uh okay let's take this out so let's just uh see what we got in here so there is the info message that puts this b in here instead of using it as an actual html tag and i know the reason uh we it's a security thing if you passed some malicious html into messages you could you could break some things and to be super airtight you don't want to allow your messaging to to do safe uh safe html there is a tag that we can use in in messages.html and just say give me a message pipe safe and that's gonna do the you know that's gonna allow um the html to be analyzed and used uh but we don't want to do that on a global scale we just wanna use that in here just for security so let's go to utils so from jungle.utils dot save string save string import mark save okay and so just remember that something like this exists and in here we can change that to mark save and put that into brackets okay so now if we refresh and go here and refresh you're logged in as admin and now it's in bold and we're using the html here perfect so obviously what we want to do also is redirect redirect i think the best place would be website index and that's going to take us all the way to the uh to the home page what's going on here okay i have to return it okay beautiful so it just run this and basically it uh kind of prepared redirection but it didn't actually redirect us there okay so now we've been redirected to the home page and we have this message so if i refresh now there is no message because we are not trying to go to login okay cool next we have to take care of the post method so if request dot method equals post capital letters so we are going to get the information that we pass with the form from the login page which is username password and remember me okay so let's do it username is request dot post all capitals dot get so it's a dictionary that we're getting stuff from user name and i'm going to just duplicate it three times thrice password password remember me and remember me so what do we do with this um there is something very simple that we can use from django we want to grab some stuff from auth so from django.comtrip.off import a couple of things we want to import authenticate we also want to import login and we want to import logout for the future and we are good to go okay so we want to authenticate this uh those credentials now okay so let's go down here and do authenticate we need to pass the request then the username which is username on password which will be password and that needs to be passed into a user okay now we need to check if users so if user and we just want to make sure that we are authenticated that we found the user with this username and this password we want to say okay login we pass this request on that user and in here we can put a message messages dot success we pass the request first and then the message saying [Music] user and here we're gonna say user dot username logged in successfully okay and so what do we do with this remember me and by the way i don't know what is not working um but it didn't work for me what i found uh is we're supposed to do something very simple which is if not remember me so if it's not and if it's if it's selected by the way it's supposed to pass a string on and if it's not selected then it's it passes string uh an empty string so if it's not remember me so empty string is still false you should say request dot session dot set expiry expiry to zero okay uh we'll see how it works so it what it's supposed to do is it's supposed to log you out the moment you um close the browser maybe this shouldn't be here maybe it should go above the login i'm not sure um so but for now i'm gonna just leave it here and i'll try to figure it out later okay and then the last thing is return and we can just redirect redirect to website index if everything went right else messages dot warning so we assumed that in here credentials were wrong and we couldn't log in could not authenticate check credentials okay so if that happens so let me have a look at the workflow here so what happens here and let me just take this context because it doesn't seem like we need it actually so if the user is authenticated then uh just give me a message that it's already done and take me to index then if we authenticate try to authenticate using post with a form we try to authenticate if and and and if everything is right we go to redirect website index um otherwise we put that message here and we go to login again what we could do also is something like this we could say username is nothing and we pass it in here so in context we actually use some context and it's going to be user name which is our user name okay so it's either nothing if we don't try to authenticate if we're not imposed or if we are in post and we also did not authenticate we pass that username here so then we can put that back into the field so the user doesn't have to put it back in in case they made a mistake in a pa in password field and not the user field at least one part is done for them okay cool so the last bit is html for the login so let's go here and open login and the same story as with the register we go to our template we open login page and as you can see again it's already selected because i did that already just to make sure i know what i'm doing and i know that i'm inside of body container and whatever is inside this is what i'm selecting so i'm selecting this copy and go let's go to accounts login oops i didn't copy let's copy again and let's paste it in here so we can close this and we are not going to render any form because we don't have a form here all i passed was this user so let's go on just customize whatever we need to customize here for login so we have welcome back we can leave that and then we have this input here and i guess just to stick to the same pattern uh let me see here if you go to account and register you have those labels here and by default we didn't have those labels so i suppose we were going to just put them in here just to keep stuff in the same way so label for and as you can see here we have an email field and i think i'm going to keep it i'll change this id to email and that's going to be four for email and what i'm going to put here is email okay and then we have okay so it's email class whatever class you need there um so okay i'm gonna just leave this by default and i'm gonna just put name username and that name is passed to views and that's how we get it from here that's why you know username is taken from request post get username because in html we pass that as name of that field and remember name is being passed to the form okay and please email address okay so we can leave that as it is and then we have this password here so let's just change it to password and put that label here for password and just say password and obviously here we need to add that name which is password uh sorry and here what do we have we have this check box which is uh for remember me so let me just let me just change that too okay um we have remember me and we need to add a name to this input okay that's a check uh and i'm gonna do name which is remember me because we want to pass it to the backend with this with this name remember me is what it's going to look for okay and then we have this button that's fine it should work except for this href it's just a part of the form and i just want that to be a submit button so i'm going to just get rid of this a in here and if i select it and just type button it's going to change both opening and closing tag and as a type i want to make it submit okay we don't want to have that href and by the way we have some references here to google and facebook we don't want them we can just get rid of those from here and then we have this forgot password we don't have that just yet so i'm gonna get rid of that too and we only have this create an account and i'm to just change that to register using jungle tag url accounts register okay and so let's go to our website so that's our register and if i go to login and i am already logged in as an admin so let me just log out from an admin page okay i'm logged out let me refresh and again try to go to an admin account login and that's our login so that's our register and that's the login perfect i think it's it's it's looking really good last functional bit is logout so let's just go to views and logout is super easy to log out all we have to do is we have to say log out no log out request and that's it and then you just redirect to whatever you want to go i think login is kind of fair enough because if you log out maybe you want to log in as somebody else or you can go to login we can put a message here saying success request we can say logged out successfully okay and this way we say okay this is uh everything went right and we're logged out so let me register now uh not as an admin register and my name is marek kubiak marek gmail.com let's say i'm gonna put some easy password here which is at least eight letters long we have that message here and so let's go and try to log in okay marek gmail.com and let's use that password there and i forgot to put the post and and there was my password my funny password there um so let me just go back to the login html and just go here and it's a good mistake um is post it's a good good error because it's good to know that if you don't don't put that post in here you send your form by using get which basically puts that in here puts your credentials here which is not a very good thing and one more thing that i just noticed now obviously i forgot you probably thought that okay it's not going to work because he forgot about csrf token which always has to be included in a form so we have a secure connection there okay and password remember me uh login user marek gmail.com logged in successfully and welcome cool uh it seems to be working but we don't have our template to work with it completely we want to be able to log out which doesn't work and we want to see our name in here for now we are not going to do any profile settings or whatever but we at least will see a bit better html in our base and now let's go to base html and by the way there is one more thing that i wanted to do before we go to base because i want to be able to tap into a user in any in an easy way so let's go to marek's portfolio no miscellaneous yeah here context processor so i want to add a user in here so i want to pass user from the request dot user if request user dot is authenticated okay else none just pass nothing in there it will be easier to specify what to do so instead of always asking for is authenticated i can just say if user then do this if it's none then it's not gonna do that and if okay and that's it um if i go here and refresh and try to log out so let's just do um accounts oops slash account slash log out enter uh logged out successfully and now i don't see my finances up anymore okay you can see those are being too long so i'm gonna just do option command l so it's all nice and formatted here and let's just go down what else do we have to change we have to change this uh douglas monkey so let's just look for it douglas maggie so we don't want any of that if we're not logged in so we can leave this li in here and go inside of it and do if user and i suppose we're gonna stop it just before this ally ends so all the way here and if but there's going to be an else as well here else we're going to do something here okay but before that we're going to just have a look here and change some bits and pieces so if there is a user we want to keep this that's fine that's fine that's fine and just change this to user last name okay so that's going to do exactly the same thing but using my actual name and then we have something here which is a static that's okay we can leave it for now we might add a like a picture but for now we're gonna just leave it as it is um we can leave those they're not harmful i might just like maybe get rid of these for now just so it doesn't take too much space but we have like some sort of a boilerplate um maybe just call it placeholder for now and this logout needs to be taken care of so we have that href here which is supposed to be just a hash because look what happens here if you do log out it gives you this this pop-up here which i want to tap into so let's look for logout so we have this logout here that goes to logout model so let's look for this next one is in here somewhere and that's where we want to do here this logout html that should be url for accounts log out okay let me now refresh i refresh here and do something so now you can see that we are not logged in so let me login login and now we can log out and log out and now we successfully log out cool so let's do something what is that do something do something here some okay i don't i can't spell so i guess if we are not logged in so let me just put that back so it looks right so if you're not logged in we can do two things we can log in or register right so let me just copy this part from here okay and paste it here i'll just change whatever we have to change for it to work so we have this uh user drop down so let's change it to auth drop down okay and then we have a button here that's fine that's fine it's fine and then it says so it's going to say something else uh for this i just want to put an icon here so that's going to be i class far fa user that's the font awesome class and by clicking on this we are gonna open a drop down menu we don't need that picture here and let's go and have a look here so we have a couple of options so i can see there's a placeholder there's this divider that we don't need so i can delete that and there's our log out so let's just change it to login and register or register and log in so this will be href url accounts and i suppose i can delete that and just put on change that to register copy paste beautify accounts login and login okay let me see if it works so let's refresh it seems that we are in here so as you can see let's go to the index and here we have register and login so if i go to register i have this and if i have login we have this and i can see that the icons are wrong so let me just fix that very quick that icon shouldn't be fa user what i wanted to use was user plus and in here it's going to be sign in sign in alt alternative okay and let me see if i refresh that what do we see we have a register which has this little sign plus sign here and here we have like log in just walk in okay and that's how you get to places okay if i go to again to register it takes me to register and if i wanna log in i can log in like this and then i can just do marek the gmail.com and then put my password on login and i'm logged in and there you see my name and there is a placeholder for nothing for now and i can log out if i press on this i can see my finances here so everything works fine one last bit i just wanted to change was um this message here if i now that i'm logged in if i go to accounts login you get this message here that doesn't tell you where to log out and maybe you're in a rush you want to get that message and you want to put a bit more html into your message that's fine too if you go to views so in accounts views and let's go back to login you're logged in on what if you want to add a bit more information here what if you want to say something like to switch user and then we're going to say log out here but we're going to use whatever we're using for log out so let's find logout model and this is the button that we use for logout so we want to go back and get where do we call this logout so this is the logout model let's look for this and let's go and look for the use of it here and that's our button there so let me just copy this and paste it right here okay and i can see that obviously it's uh trying to get to um get the line breaks there so let me just delete that and just go shift command up no i'm gonna go shift up and command right i'll just delete that now we have our text which goes like this and let me just put the line breaks where i need to put them so let me see model blah blah blah text and that should be fine so let me see to switch user blah blah blah blah blah blah blah blah log out okay we don't need this actually here so i can just get rid of that we don't need to have this icon there so let's just have a look here log out here okay and let's see what do we get now accounts login that's a it's not supposed to be a button so that's a drop down item it's not a drop down item it's just a a link so we might be able to put that here and here and now it should work let's put that account here again and log in and now we have this okay to switch user log out here and then you can log out and log in again so it's a little bit more friendly cool so we have our users working um we don't have the forgot password just yet but i don't want to mess with emails and stuff i want to get that done later after we finish the my finances app because i'm really eager to put my hands on my finances it's going to be so cool i kind of want to start using it as well like i'm gonna i'm pretty sure i'm gonna just like log in and start using it for my finances because why not um so yeah i'm super excited and um i know it took a while to get those users working but now that we have them working we can get our hands dirty with the my finances app okay thanks guys and see you in the next one bye
Info
Channel: Sugarloaf And a Cup of Joe
Views: 1,886
Rating: 4.9285712 out of 5
Keywords: django, authentication, login, register, logout
Id: NbbNRcJxFHY
Channel Id: undefined
Length: 53min 17sec (3197 seconds)
Published: Wed May 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.