As users perform actions within the application, we need to verify the user's identity. We'll store the user's identity in the browser session and use the session to validate requests.
- [Instructor] Hi and welcome.…In the previous video, we learned how to authenticate users…by hashing passwords and storing them in the database.…In this video, we'll enforce authentication on our site…by building a custom middleware…to ensure the user is authenticated.…To get started, we'll set the user in a session…on a valid login or successful registration.…Next, we'll add a new middleware handler…to check for a valid user in a session object.…Finally, we'll add a small amount of UI…to allow the user to log out of the application.…
First, let's open up our main.go file.…Whenever we do a successful register or login,…and then log in or out,…we should set a new session value.…We'll use sessions.GetSession with our request, r,…to get the session.…Then we'll use the set method with the key user…and then value of the user object's Username property.…We need to be sure to do this during successful login…or register before we redirect to the main page.…Next, we want to verify that the user session value…is always set before we allow a user to enter the main page.…
Go is on the rise. This open-source programming language (created by Google!) comes with a strong and accessible standard library, and provides a growing ecosystem of tools, libraries, and frameworks that can help you build web applications fast. Go for Web Development gets you started with the language, opening with the classic "Hello world" exercise and culminating in a web application with a strongly designed database back end, useful middleware, UI with an intelligent search function, multi-user authentication, and more.
First, learn how to build a web server with Go's extensive standard library. Explore the concepts behind a single-page web application and learn how to create a dynamic user interface, manipulate a database, and use powerful encryption algorithms to implement an authentication system. Next, you'll incorporate more functionality by calling out to external libraries from the database. Finally, it all comes together into an optimized package you can deploy into the wild with Heroku.
- Creating a route in Go
- Using templates
- Building database connections
- Collecting data
- Using web middleware
- Using the Ace template engine
- Integrating HTTP routers like gorilla/mux
- Authenticating users
- Optimizing a Go codebase