Signing Users In

Start course
Overview
Difficulty
Intermediate
Duration
3h 18m
Students
11
Description

In this course, we're going to build a Foursquare Clone using Parse. Parse provides you with a great tool to work in cloud servers and you will learn the advantages and disadvantages that come with it.

Intended Audience

This course is designed for anyone who wants to:

  • Learn about iOS development and coding
  • Move into a career as an iOS developer
  • Master Swift skills

Prerequisites

To get the most out of this course, you should have some basic knowledge of iOS.

Transcript

Hi. Within this lecture, we're going to see how to log users in. So far, we have created our user, right? So now, we have the James user. Now, let's go into the signInClicked and try to log that user in. So, of course we're going to use PFUser class one more time here. So, I'm going to check to see if userNameText.text is not empty string, and passwordText.text is not even an empty string one more time. Because if that's the case, I don't want to send any request to the server, I just want to give an empty string message to the user, okay? So, I'm going to do what I have been doing so far. I'm going to use makeAlert as a username and password. But if they are not empty strings, then I will just begin to log the user in by using PFUser class.

So again, if you say PFUser. you will see a lot of options like signing in, signing out, but we need something called the logIn. So, there is the logOut function, we're going to use that later on but right now I need something with logging in. Of course, we're going to log in in background with username and password.

So, as you can see we have this logIn that throws an error and this is working synchronously. We want something with a background like this, okay? LogInUsername inBackground with username and password and this gives out a block. So, that's exactly what I want. I want to logInWithUsername and the password and see the results in a block.

So for username, I'm going to go for userNameText.text and I'm going to force unwrap this. And for password, of course, I'm going to go for passwordText.text and force unwrap this as well. And for a block, if you hit 'Enter' it will give you either a user or an error, okay?

So, this time we don't get any boolean like we did before. Right now, we get a user. So, let me call this user and let me call this error. So, inside this closure, let me just close this so we can see it better, okay? Let me close this one as well. I'm going to check to see if error is not nil. And of course, if error is not nil, I'm going to say self.makeAlert and for title, I'm going to go for error and for message, error.localizedDescription with a default value of error.

So, if that's the case I'm going to display this but if it's not, if I don't have any error messages, it means that my user has signed in. So generally, I want to do a Segue in here and we're going to do that once we create our other View Controllers. So, I'm going to take a note saying Segue for right now I'm just going to show you what this user has. If you say user. you can just get the user email, you can just get the user password, user.username. And if you want to do something with that user variable, you're more than welcome to do over here, right?

So right now, all I want to do is just print out something like welcome, okay? Maybe we can do something like user?.username and before that we can just print out welcome message. Of course, we don't do that in real app, I'm just doing that as an example to see if we managed to log the users in.

So, let me run this on our simulator and let's go for James, but for password, let's leave this blank. As you can see we got the error. So, it's working fine. Let me give a wrong password, and as you can see we get the invalid username or password from the parse server. So, this is our error message. And if I give the right credentials, as you can see, it logs me in.

So, we have created signing in and signing up functions but we cannot actually use them since we don't have any further View Controllers at this moment. I believe this is the time that we stop here  and create the places View Controller in which we display the existing places in the server so that users can choose one of them and display the details. But we're going to do that in the next lecture.

 

About the Author
Students
938
Courses
55
Learning Paths
3

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics