Golang HTTP User Authentication Yabi Series 4 | Golang Web Development | WebAssembly Auth System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys welcome back to the channel this is series number 24 here in maharlikan's code okay so we will continue guys uh in our users registration here uh here in um uh what they call this yabby series uh okay guys so we will continue this a complete uh user's registration then we can probably insert our new users information to our mysql database okay guys let's dive into this tutorial okay guys welcome back to the channel okay well we will continue now guys our thing so we have uh already created in our previous discussion we already hash our password and then we already have the insert statement here by using this prepare statement here in what i call this mysql golang's mysql driver okay so and then we will insert it here guys and then we also have a new uh user's id here so the last inserted id so we also want to capture that one guys in this function so of course this one is very useful when when you have other functions that might need or might need probably you will need on the new user's id because every time when you register there is a certain unique id for each user guys so this function create user function will return with the valid of course the latest inserted id okay so we will continue on uh we will go back to our oauth.go under this api uh we will now proceed uh with our mysql here guys so we will probably create what they call this we need to open open up our database connection here guys to feed our i mean our mysql database okay so we will continue on okay okay guys okay sql that open okay so probably we have a mysql here this is the syntax set but i think we need to create some function first guys because uh okay guys uh we will proceed with our uh what do you call this um because this one is we need to have the connection string guys so this one is always repeat one so we we would like to create a separate function guys uh we called it probably in our uh here guys we try we try here first guys uh i think this one is okay now it's good enough here uh because this one is your connection string so every time this one you can we can probably place paste in our config i mean con okay so we will continue we'll create this function guys so uh db name so we require db name as a string here and then we will return as a string as well this function so uh so that we will feed this into our sql open guys so we nee we only want we only require a database name or we will set also some default database name in our config guide so we will set up everything for this one is the connection is the connection string guys for your database okay um okay that's good enough so we will your local variable here so we we will set uh the default there if the user will key in this database then we will just pass on the localized variable here guys so if this one is leave as empty trim space db name oops and then zero then we will set the db db localized variable here to our config guy so probably we don't have yet we will go with our config guys so this is our db here uh we will try uh removing this one we don't want to use uh yes so this one is the the real connection string in our previous discussion so right now we will have the exact uh kind and this one is the exact thing guys in our functions there instead of using this constant constant string we will we will try to reuse this function and then we will come up with this kind of a string guys so this one our database there is not mkc so we will uh this one is for my dummy only so we will have marlikan's code this is our database name so this is our database name we also want to have a constant for the db user name in this case we just say root this one is a db username is your database uh username okay so this one also constant db password uh this one you can leave it blank this one is now you can just specify the password guys my local mysql we don't have a password here but when we publish this in our production uh definitely we have of course we have a password guys okay this one is a db password okay is your database password okay so this one would be um this is the exact string that we will we will do it here guys so no worries we can just uh remove this okay so db host name we can just put this as a db host name so this one is for your this one is your database server host name or ip address okay i will uh layout for you guys uh we of course uh with the port number okay uh example this one i just illustrate you guys that we don't want to lose all this information okay the default one is 3306 okay so we will continue db host name probably now is a 127.000 or localhost name guys this one we can change later in our production guys so no worries okay so we we all have this uh under this package now we have this db information okay guys uh this one you can always encrypt this password with our encryption but uh for the sake of simplicity now we don't want to provide any password yet because my local databases we don't have password but in our production we have the password so uh probably we can try to encrypt this uh in our next i mean we published it in into our production guys okay so we will continue on config that this one is the uh db name so this is our default database name which is the market's code so um okay so we will provide this function here okay so we will just continue okay then we can return this with the fmt then sprint f so this time is uh we will contact concatenate together guys all these uh with s uh the one the exact string that we have removed in our config guys so colon here this is our username and then the next one is our password and then up tcp and then we will open close monocle now open close parenthesis here then put s here the string so these are all the tcp which is the ip address and then slash for slash this is our database name and then uh always have this parse time argument as part of our connection string guys to capture all those uh time time stamp for the mysql database don't forget this one guys the parts time okay and then the character set this one all the standard one character set is equal to utf um 8 then mb4 and then no space atf then utf-8 okay so okay then we need the config this one is we need the config i cannot see okay username and then we will just continue here below guys okay uh db password so in our configuration now and then config dot uh db host name okay and then our database name uh okay so we all have now a reusable uh db connection string guys for our mysql so okay in this case now we can continue with our registration there so we can probably we can pass on now this uh what i call this create user on so here this one uh we are still in the sql open and then right now we need a dsn so data source name so we can reuse this our function name called db cone string then we leave it default case as a blank one then it then it can capture our uh default database name which is the markets code if you have multiple database of course you can pass on here guys like a new db name or like that guys and then you can connect with the same ip address or host name um normally in our host name in our database we have multiple databases there so we can just with same server name or hostname or ip address we can have multiple databases there inside in that mysql server there so you know in this case we have a fully reusable uh connections guys so we can just pass on with a necessary database name and then we can connect directly okay so we can it's easy for us to reconnect our database okay so we have this uh check as usual the error guys okay so uh we has our itr log here we can log everything here guys so then uh ensure that you have a d4 guys so it will uh just not uh hanging there if it's not used so we can just close this connection uh from our by using this defer guys okay after this we will form or create our um [Music] inputs or any guys so we can just um new just say new yearb user information okay and just pass on like this and then uh new user local variable yabi.user so we will use now our strategize to fill in all the necessary fields there so in this case we have a username okay on top we have a username so we can now reuse uh use all these uh arguments or the payload guys so we can pass on with our yabby user struct there so the password password also from the parameter payload okay and then we have some email and then of course we have the email we can it's super user uh we just say it's false guys so this one is the highest privilege guys though so don't forget all these things um this one must turn off is uh admin um this one we can remove later part guys we will enhance this uh later part guys so we will just fill in with the whole false guys so let's see it's active and then he's active okay so we have done all this and then we have already have some information here guys for our new user okay but the email part we will uh leave it for a while so just copy this so now we will continue on with our new create user what they call this job user here this one is a db con so we have a db be ready guys so we can pass on ready and then a new user struct so this is our data and then after that the email we don't have yet uh we have some confirm password we'll just pass on and then the tools okay so we will have this in now okay sorry so okay as usual if um error not equal to nil and then we will continue ipr log we will log all the errors guys so at least we will know in our back end is there any errors so this is very important for us for to troubleshoot in in our later part so we'll have this return back to the user case if any errors there we will prompt it with the user there guys so okay so later we will test this together okay bye we need this byte and then cut it and then okay guys uh i captured our time um this one is already pre-populated guys so every time there is an error there in uh from this function from the yabi crate user uh we will say like uh uh is success uh insured it one this one is should not be a true guys okay uh should be false because even it will throw an error so it's not a successful user creation okay so alert title we just have this fixed error here new user creation failed but this alert message is how we capture it from here yes so remember that we have this um this user here we have all this error message message like this username is required email is required all these things guys so these are these are all some basic um what they call this validation later we'll enhance this further guys our goal is we need to insert uh first from our mysql because right now it's totally empty so we would like to uh populate that okay so in this case this is um is active here this is active account is what we call this uh this one when it is true then we don't want to send an email to uh to the user guys okay so okay guys so after this we will like like there is a new user if successful then it will proceed here guys okay so this one we don't have like a welcome you can uh we will enhance this later on we will have some kind of after the user registration successful the new user popup will come out some information to inform the user and then we will redirect back to some kind of page there but in this case we don't have some kind of a page at the moment guys so probably we can um block this one first because we don't have page but this one is in our future future layout guys after some kind of a registration so okay so uh insert new users registration here if this one is um false in this case our thing here is false so we will uh send some what do you call this email so we will uh at the moment we don't want to send first guys so we will probably disable this one first so we will try to use true first because we don't have email yet okay so this one is automatic update guys i mean the status is activated for the new users account so remember that we have two options here there is an automatic user's account activation if it is a locally or internally created user any other purpose there you can use this feature guys for our yabi uh authentication system here and the another one is the for the user's registration this one is uh we require uh for the public pages there so but at the moment we don't have some email features here but definitely in our next discussion we will have some email um automatic email notification using sun green or the classic smtp there okay so uh we will continue on uh this one is for the true statement here i mean false statement for the public users registration so we also cater here okay successful in a different kind of a message like a registration is successful but whatsoever guys so this one is in in your part uh this is your customized part here so but uh you just want to use this create user to insert a new my new users to our yob user there okay so i think it's all done here guys now we would like to test our application here so by saying this we need to set again our goose every time you want to export to wasam guy so set go arcs go go arcs okay then go arc then wassum okay so uh i need to check guys one hold on power go environment and the name i complain go arc is correct okay so already set okay so we can now go build okay then i need this um we need to throw to this okay this is the one okay ensure that you have in the root directory of your uh these uh wasab guys okay okay so uh we need to use this as oat wasa and then the main go press enter okay so no errors so the new file is should be there okay there is a new file exported so this one we can ensure that you you are under this uh directory guys or whatever your project there so before you execute this uh wasam uh build okay so this one we don't need anymore this one we can now um we already have a new file there that wasn't file we will run this out we'll run our server and go run main.go and then we can access our registration page okay so it will reload this is our login so we need to go to our registrations okay ensure that we have uh our console here if any errors okay so we will try to validate now guys uh okay some errors there um register api register okay okay guys uh last time we have some error guys so this one we need to import this um this kind of uh configuration i mean you need to only import only in this main.go the main goal in your root directory guys okay this is the main thing uh you cannot use um probably it's not ideal to import from here guys this is the blank import for the mysql driver so this is the from the instruction from the github guy so we can just put this into our main.go in your root directory okay not the main that go from the wasam okay uh anyways no awesome no mysql driver uh that you can import there so only you can import into into your original i say another term is what they call the original may not go inside your root main goal so just ensure that you have this one yes that's why it will throw an error so uh always check your log there then you can always have this uh error uh message there or something the detailed error guys so uh right now we can uh try to that is the the only missing part only okay so we just ensure that this um driver will store in your main.go uh the route may not go okay so just pay it there and then you just save then we can just close that one guys so we can now uh explore our mysql here the registration so when we try okay now uh this is uh from our yabi authentication guys so okay this one is username is required this is from our yabi package this one so the new user registration file so we need to fill up guys we try admin and then we will try the basic one versus new user occasion paid again okay email is required so if we put some funny email here i'll try again i think uh password is required okay i think the email we never set first okay okay new user creation failed new user password didn't match so it's uh working our basic one guys basic authentication thing the basic validation so okay so we will just uh pass on all this information new user creation failed terms of service is required by joining marligan's code you are agreeing to our terms and conditions okay so we need to tick this okay okay now is email user i think we need to add the email validation part guys so we miss out this one now it says a new user uh successfully created guys okay we'll we'll see if this one is having here or not okay it's good guys we have already inserted the new user here from our mar from harlequins code yabby user table okay so we have this uh information we have the first name middle name last name all these things are optional at the moment guys because in our registration here we don't require it's up to you guys if you require here but the basic techniques for the user to sign up guys is give them very basic information to start on okay so don't require too much of information because user may may say me may go away or something that is off for them so okay so we just fill in with the username and the password okay now as we totally inserted a new record guys so by doing this from our on this one itr log we know no longer using so later where we will enhance uh okay we will add at this at this time we still have uh time to to further enhance this okay so okay guys uh we will use our uh existing package called the sakto again okay so we will check if email address is valid or not okay so if this one will return true or false guys uh suck to that uh is email valid so okay i already provided in this uh our own package guys okay and then we will check return zero then errors dot new and then it say just say invalid um email address let's say like that guys okay so this is our uh from our package here great user so we will just update uh invalid email address okay please try again or something maybe we can add please try uh again okay so we will run this one is not part of our webassembly so it's just a normal go script guys so we can just uh try again now okay so i mean we'll try uh the same thing guys uh just a funny email there okay this one already is validating properly we will try the email okay so now it's popping up guys uh even in violent email address please try again so if we try um like aaa dot uh something like that guys we'll try okay still validating invalid email so we'll try a uh a that one again let's see if it's working or not invalid email address okay and just say it's dot invalid again uh we will try dot com or something um that one is uh okay we will try with dot com one in valiant guys okay so we will see we just try to remove new user created okay we'll check again although it's a duplicate guys we don't want to duplicate here uh later we will create a new function to validate all those a unique one okay so we don't want the duplicate username and then this is our next topic guys so just um hang on for okay so probably we can now insert and then validate some good information here guys so we can then our wasam is no error at the moment okay so probably we can end this part guys we will continue on we will enhance this the username we will we will block if any exists we don't want the duplicate one guys and then the password also is properly hashed from the golang itself there using the b and then the datejoin is also properly added and then it's active is a one means it's true guys it's active okay so we have done this guys okay guys uh thank you so much for watching my video here i'll teach you a series here in mahleke's code okay so we will uh we have done successfully our registration there the user's registration so just okay so uh it's totally done and then uh we will enhance that one guys another one is a very basic one because our goal is we want to insert the new user registration to our mysql database so we have done that successfully uh in our next uh discussion we'll we will enhance our validation there uh we will block any duplicate uh username and then of course when um of course we will have some automatic email confirmation and then the user will receive an email from our yabi system there the authentication and then they will click on that link or that button there we will design that one for our for the email layout the html email layout we will probably use the send grid and then the classic smtp okay so we have done this uh successfully guys we can probably rest okay so i hope you enjoy our tatura series here in marlingan's code and i hope it i imparted with you and contributed with to you almost especially to our students students or all those just started learning programming language or enhance golang programming language there or whatsoever from other languages they came from and then welcome aboard here in marlick's code kindly subscribe to my channel so that you can have more videos like this you will be notified don't forget the notification bell guys thank you so much for your support and then may god bless us all keep safe everyone thank you so much um may god bless us all thank you and love [Music] bye-bye
Info
Channel: Maharlikans Code
Views: 117
Rating: undefined out of 5
Keywords: go, golang web development series 24, golang web development course, web development with go, golang tutorial, learn to create web applications using golang, building scalable web apps in golang, golang http user authentication, golang http authentication, golang user registration, golang authentication microservice, golang session authentication, golang webassembly, golang mysql, golang mysql tutorial, golang sql, Life As Software Developer
Id: vEyRgiwYeqk
Channel Id: undefined
Length: 32min 42sec (1962 seconds)
Published: Tue Dec 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.