How to Build Web Application Signup with Laravel 5.2

How to Build Web Application Login with Laravel 5.2

Introduction

Here you iarn about How to Build Web Application Login with Laravel 5.2

In this tutorial, we’ll be creating simple web application authentication/login in mesosfer using laravel 5.2. Mesosfer authentication use oAuth2.0 so you will get a token for authorization when operating data. This is a second section from web application tutorial series with laravel. If you wanna follow from the begining, you can read the first section here.

Prerequisites

To follow this tutorial, you will need to prepare item below :

  • Sign up for an account in mesosfer cloud platform then create application to get applicationId
  • Install composer.
  • Download source previous section here.

Let’s Write The Code!

Based on previous tutorial, you have UserController.php in folder app/Http/Controller. Then you just create serveral method to handle login process. First add method login for handling navigation to login page.

Then add login page –> login.blade.php in resources/views/pages.

For handling routing, you have to add routing path in file app/Http/routes.php

Run php artisan server then access from browser, It will be like picture below.

how-to-build-web-application-login-with-laravel-5-2-1

We should add sign in method in app/Http/Controllers/UserController.php for handling action post from login page.

Then we will get result json below :

Working with Session

In the next section (CRUD) you will need  access token for every single API execution. After login success you will get access token, to keep that you need store at session variable. Firstly, you should add library Session like script below.

Add script for storing data to session variable inside method signin, after execution no error.

Create controller AnimalController.php to handle redirect after login. In the next section we will also use this controller for managing data (CRUD).

Then create animal view for show page after login success. Add link for logout.

Add method signout for destroy all session user.

We should also add checking session when try to access login page.

Update routing for handling signout and animal controller.

If you access from browser, It will look like the picture below.

how-to-build-web-application-login-with-laravel-5-2-2

Let’s try and share to your community. Download complete code here.

Conclusion

With Mesosfer you don’t need to setup authentication library, just create apps and call RestAPI that provided. So easy and simple for implementation. With authorization token your data will keep secure and safe. Always follow tutorial for upgrade information and knowledge from Mesosfer.

Mesosfer helps you connect your project to the cloud. Cut off the development process so you can straight into the delivery process instead stumble on the complicated infrastructure.

Hi There!

Leave a Reply