Simple Login App using Database Tutorial - User Registration (PART 2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Professor DK and welcome to the second part of the tutorial on simple login app using the database without any further ado let's start with it quickly go ahead and create the database go to your browser and type in firebase so click on the first link that you see so it should the UL the URL goes something like this firebase dot google.com so firebase is a mobile and web development platform which was taken over by Google and now we have a lot of new features which have been added and every day we get to see a couple of changes happening so as you can see it offers us real time database it gives us the feature of authentication trash reporting cloud storage and there are plenty of other things which keep improving each and every day so so why are we using this and not anything else so most of you here are using database just for security purposes and for the authentication right now the problem with creating a database on a web hosting service and then writing the PHP file so all that gets complicated and your main work which is the app the main priority of our app so all the deviations from the app is basically going to this so you are you cannot focus on your main work and instead you need to make a database and focus on all these trivial things so to solve all that issues so firebase has come up with this platform where you only have to focus on your work and not focus on how you can expand your servers how you can you know send values to the database how you can provide authentication so all that is taken care by firebase you just need to focus on your work the main reason why you're doing the app all right so let's just quickly go ahead in and sign in to firebase so I already have my account here so I'm just gonna sign-in into that so once you sign in so you can see your profile picture here so you click on go to console so this is the console so here it gives you the option of adding a project so this is one of my projects so just go ahead and add a new project so I'll prompt you for your project name so I'm going to call this as login demo and it will assign a project ID and choose the country of origin okay and once you entered all these details or click on create project okay so we are inside the the login demo project so let's add authentication so in the right left corner rules you can see under develop you have authentication so I just click on it and let us set up the sign-in method so click on setup sign-in method and we need an email password verification so just click on this and click on enable so we have enabled email and password authentication so now that we have done that let's click on users so as you can see we do not have any users as of now click on templates you will see that ensure you email address verification password reset address change and these are the different things which we'll be seeing in the upcoming videos so far now just do not worry about all this and just click on user so now that we have created our project here you just need to implement this in our Android studio okay so to integrate firebase into our project so firstly go to project overview and we need to link it to our app so here under get started you can see that you can add firebase to your Android app so click on that and we need to provide our Android package names go to Android studio and at the top you can see that the package name is mentioned so copy that and paste it here so we have our package name just remove package ok and you have to we can either give a nickname to our app so let's just call this login demo and click on register app and it will give us a convict file which we need to add to our app folder so just click on download Google services dot JSON so navigate to your Android projects folder and inside that you need to paste this under the app folder so go to login demo wherever you have saved the file and under app just save the Google services dot JSON file so if you couldn't save properly so you can just save this onto your desktop and then you can just copy it and you can even paste it from Android stores you can just go to Android and click on project at the top and you can under app you can just do a paste here so you can just paste it here as well so that will also work so anyways if you see here I have saved the file and it is displayed here so I have my Google services JSON under my app folder so the last part is to add a couple of URLs onto your Gradle file so firstly let's add the first one into our dependencies inside the root Gradle file so go to Android again and here you can see that ok so here you can see that under Gradle scripts I have two Gradle files so you must go to the root Gradle file which will be shown as project login demo or text beside that so click on that and under dependencies just add this line and also add and also we need to add a plug-in at the bottom of the app level built out Gradle file so copy this as well and I'm gonna paste this in our App level built our Gradle file at the bottom so outside dependencies and we will apply our plug-in and we just need to click on sync now okay so we have successfully added firebase onto our app so now to add the authentication so go to authentication under-developed column and we need to you know check how we can add the authentication right so click on go to Doc's and under that you can see get started for Android so click on that and here if you scroll down you can see that it asks you to repeat some of the steps so they have done this already but we are not added Google's moment repository so under build-out Gradle so we need to add this file so add this URL so go to build at the root level build out Gradle file and under repositories just paste this and click on sync now okay and after we've done that we can go to app slash build or Gradle file so we have added our plug-in but we are not added this dependency so so this line basically imports all the core utilities of firebase onto our app so just copy this and we are going to add this in our build or Gradle file in our app level folder so paste it here and again click on sync now to go ahead to their website they say that if you want to add a couple of libraries for different features you need to you know add these dependency lines in our app dot Gradle file so so since you are using authentication we need to copy this line of code in our dependency file so goto dependencies and just paste this as well and we need to add the compiled need to add compile okay so we have authentication files also imported in our project so click on sync now so now that we have done all this so we are good to go and we have created our email slash login email slash verification project here so you notice that once our app is ready the registered users are displayed here let's start with how we can go to the app so so on the registration activity dot Java so we need to create an instance of fire firebase Authenticator right so we have firebase auth you can give it any name that you want so we need to create an instance of this in our app so for that insert on create so type in firebase auth is equal to firebase auth dot get instance so that'll get an instance of our Authenticator into this variable so this is basically an object of this main class alright so next inside this so here is where we will be uploading the data on to the database so as you saw on firebase we have done an email slash password login verification so we need to post the email first so user email is equal to user email dot text dot to string dot and we also need to give the password so string password is equal to user password dot attached not to string dots so here basically we are getting whatever the user has entered and we are trimming it so this is basically this line is converting it to a string and the dot trim function is to remove all the white spaces that the user might have entered so now we only need to push it to the database so firebase or dot create username create user with email and password and inside this we need to give the email and the password so user email comma user password dot will we are also going to add a non complete listener so add uncomplete listener and inside this we need to do the parameter add on complete listener so android sugar will autocomplete it for you and click on enter so we have this huge line of code I mean it's easier with under sugar because it autocompletes it for you so I repeat so firebase auth dot create user with email and password just type create and it's going to complete click on enter then type in user email and user password and enter a dot and then type just type add and it's gonna attack implead giving a different options to add on complete listener and inside the curly brackets just type new and oncome just type on c om and is going to autocomplete it for you again and click on enter and all these lines should be custom generated for you and if you see here you have an error this because this is a single line so it needs to end with a semicolon so just put a semicolon and inside on complete so you need to you know tell the user that the task was successful or if there was some error so for that sake you can you know display a toast dot make text give the context and just type in registration successful length tossed dot length chart dot show all right so this will basically display the toast and this will show another because since this is inside an internal loop the context is not recognized so you need to do just type in register registration accurately dot this ok so it should work so why are we doing this extra line is because we need to you know intimate the user on if it was successful or not so that's why we are using the add-on complete listener or else only so much is more than fine I mean you could end the line here as well so all the data would be sent to the database but you wouldn't know if it was successful or not so add-on complete basically tells you if it is successful then display this message alright and since this is the task of on complete we need to put this inside that loop so if task dot is successful so that's when we need to display this message so cut this and paste it inside this if condition loop and if the task wasn't successful then we will display this display our toast in the same way but we need to just change the message so display our toast again and we'll say registration fail all right if the registration was successful so you can direct the user to the login page so start activity new intent and we direct him from registration accurately dot this to main activity which is the login activity dot class okay so on successful login you will be doing this as you display the message saying registration kit so so we have successfully completed a registration activity so go ahead to our main activity and we need to give the option for our user to come back come to the registration activity right so for that we need to private X pew registration [Music] we'll call this user registration and we'll assign the IDS for it so user registration is equal to so if you are wondering what I am doing so if you remember the first thing that we did in when we started the video was in the main activity we added this textview so we need to give the option for the user to go to the registration activity so this is the link that we have to the next activity so assigning that so in our main activity so we have created the variable for that we have assigned the ID for that and now we are just gonna set an onclicklistener on this so user registration dot set on click listener new on click listener and we're gonna direct the user from this this activity to a new activity so I'm gonna direct the user from login from this main activity to registration activity so main activity dot this which is a source and the destination is the registration activity so that will be the dot class so this will are sending the user from we're directing the user from one activity to another using just one line so now that we have completed everything I guess we can just go ahead and run the app and check for any errors so as you can see on the website here I do not have any users so I'm gonna go into the app so this is the app activity that we have here so I'm gonna click on new users slash signup so I'm just gonna enter the details so firstly we have our name here and then we have email and it's gonna enter my email id so dear it's comma 22 at gmail.com and I'm gonna enter the password as 1 2 3 4 5 6 all right so when I click on register so it should update the values in the database and as you can see here it showed that the registration was successful so as you can see here we have the user details registered so dear H comma 22 at gmail.com was the email ID data entered and the password is saved even though you can't view it here but it said and it can be accessed in the login page so I'll be showing that in the next video but for now so we have registered our user and you can do so and add as many users as you want and another thing about the app as I told you is if you enter into the registration activity by mistake you could go back to the login activity just by clicking already signed it and as you can see you get directed to the main page so this is the registration activity also another important thing to notice is that when I try to register with all the fields blank so as as you know we had created the logic that when each of this is empty it should display the tour saying that please enter all the details so when I click on register the app is crashing so I found out that we had a logical error in our code so just we have to make some minor changes so so in Android studio go out to the registration activity and we have a logical error here so here and basically inside this if condition I am checking if all of these are empty but I had put an and condition but it should be an or condition so basically after check if this is empty or if this is empty and it should not register if either of them is empty and not if all are empty right so we need to change this logical error so rectify this and just put an or operator here so once you have that once you have corrected that we can again run the app and it should work perfectly fine so here we have our app after the changes were made so I'm gonna keep all the blanks empty and I'm going to click on register so as you can see it tells us to enter all the details so our app is working perfectly fine let's just you know create another user let's just call it Rohan and I am just going to give the email ID as Rohan at gmail.com Rohan and gmail.com and I'm gonna give the password as one two three four five six so I'm gonna click on register so once the data has been posted to firebase so it should be displayed here so so in my database so I'm gonna refresh the page and so as you can see rohan at gmail.com was created so our app is working perfectly fine so catch you guys in the next video so this is the registration activity so hope you liked the video if you liked this video make sure you give it a big thumbs up also if you have any queries make sure you comment below and I will respond to you as quickly as possible so thank you guys for watching make sure you like and subscribe so that you do not miss out on any of my future videos thank you guys for watching happy learning
Info
Channel: Professor DK
Views: 164,784
Rating: undefined out of 5
Keywords: Professor, DK, Simple Login App, Simple Login App using Android Studio 2.3.3, Simple Login App using Android Studio 3, Simple Login app using database, Simple login app using Firebase, Simple login app tutorial, Simple login app using database tutorial, Simple login app using database registration part 2, How to get started with firebase, Firebase Simple tutorial, Simple Firebase Tutorial, Firebase, Android Studio 2.3.3
Id: zKBGjGoeid0
Channel Id: undefined
Length: 21min 32sec (1292 seconds)
Published: Sun Dec 03 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.