Git Product home page Git Product logo

user-profiles's Introduction

User Profiles

Step 1: Basic setup


Step 2: Controllers, endpoints, and data

We'll start in userCtrl.js.

  • Create a method on our exports object named login, this method should loop through the users array, find the user that matches req.body.name and confirm that the req.body.password matches the user's password.
  • If we find a match we need to set req.session.currentUser equal to to the correct user object and res.send({ userFound: true });.
  • If we don't find the user, we will need to res.send({ userFound: false });. -->

On to profileCtrl.js

Here we will need a simple method on our exports object that pushes every profile that is in the req.session.currentUser's friends array. Then res.send's an object back containing our new array and the current user. The response object should be structured something like this:

{
  currentUser: req.session.currentUser,
  friends: yourArrayOfFriendObjects
}

This function will need an accompanying endpoint in your server.js, so add an app.get endpoint with a path of `'/api/profiles'.

## Step 3: Serving static files

<!-- Now you may have noticed that there was some front-end code included with the project, but at the beginning of the project it was mentioned that we would no
longer need to use `http-server` or `live-server`. We are going to send all of our static front-end files from our server.

This functionality is built into express with the `express.static()` method. All we need to do to begin sending our static files is add this
line to our `server.js`. -->

```javascript
app.use(express.static(__dirname + '/public'));

Step 4: Hooking up to the front end.

Take a few minutes to browse through the current .js files in your public folder, you'll notice there are several areas containing FIX ME's. Let's move through and set up our front end so it is actually functional!

To start, you'll notice that our mainCtrl.js is calling a function inside of our friendService.js that contains a FIX ME. This function should post to your login endpoint, sending the user object we recieved from our controller.

Next we will need to fix the resolve inside of our app.js. This resolve should return the result of our friendService.getFriends method sending a 'GET' request to our /api/profiles endpoint.

Lastly you will need to inject that resolve into your profileCtrl.js and assign the correct values to $scope.currentUser and $scope.friends.


Well done! Try logging in as several different users and seeing the different friend lists, all with very minimal front-end code. This was all done simply by tracking our user's session on the back-end.

Step 5 (Black Diamond): Make it a bit more interactive

  • Allow users to add or remove friends.
  • Add a settings view specific to the current user, where they can change their name or password.

Copyright

© DevMountain LLC, 2015. Unauthorized use and/or duplication of this material without express and written permission from DevMountain, LLC is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to DevMountain with appropriate and specific direction to the original content.

user-profiles's People

Contributors

r-walsh avatar sjwestbrook avatar zacanger avatar jrobber avatar mchapman101 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.