Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Login operation of blog project in laravel and example analysis of creating background home page

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "login operation of the blog project in laravel and the example analysis of creating the home page of the background", the content is simple and clear, and I hope it can help you solve your doubts. Here, let the editor lead you to study and learn about "the login operation of the blog project in laravel and the example analysis of creating the home page of the background".

Background login verification code Crypt encryption and decryption

1) assign a route first (test)

2) create a crypt method

Use Crypt::encrypted (); encrypt the password

$str = '123456 investors investors JpdiI6IkRKNlZsU2k3OWhtTkxTUTFObWdpaVE9PSIsZhbHVlIjoiUUVhRTFqd0YwQk1TeDVMU3RuenBodz09IiwibWFjIjoiOTZZlMTJjZmY1NTQwYA4ZTBiYzODVhjk0NDAxNzI4ZNlNjM4OWZhkM4OWZhkMYZZNzODMjk0NDAxNzI4ZNlNjM4OWZhkMDxYWE4OWFkMyJ9 echo Crypt::encrypt ($str); / encryption' echo Crypt::decrypt; (str_p); /

3) determine whether the username and password is correct

$user = BlogUserModel::first (); if ($user- > user_name! = $input ['user_name'] | | Crypt::decrypt ($user- > pass_word)! = $input [' pass_word']) {return back ()-> with ('incorrect msg',' username or password!') ;}

4) if the user name and password are correct, save the information in session

Session (['user'= > $user]); / / store data in session dd (session (' user'))

Second, the layout of the background home page, welcome page, and sub-views

1) put the same content into the common of the layouts folder

Put the glass content in the sub-view, in the glass content section @ yield ('content')

2) reference the template file in the child view

@ extends (home.layouts.common) @ section ('content')

This is the glass content of the subview.

@ endsection

3) transfer to the backend home page after logging in successfully

Return redirect () / / indicates reversing each page

4) reference transfer page address

{{URL::asset ('/ home/index')}}

5) the introduction of css and js

{{URL::asset ('/ css/style.css')}}

Setting up and logging out of the background administrator login middleware

1) Log in to this route (do not put it in the group that determines whether or not to log in)

Route::group (); route::group ([], function () {}); route::group (['middleware'= > [' web','admin.login']], function () {})

2) in kernel.php

'admin.login' = >\ App\ Http\ Middleware\ AdminLogin::class registers a middleware

3) create middleware with PHP artisan

Php artisan make:middleware AdminLogin

4) after logging in successfully, put the information in the session. This is where we take the value in the middleware to see if there is a value.

If (session ('user') = = null) {return redirect (' home/login');}

5) Log out of middleware

Assign a reason

Public function quit () {session (['user'= > null]); return redirect (' home/login');}

6) look at this route with not only prefixes, but also prefixes and namespaces.

Route::group (['middleware'= > [' web','admin.login']], function () {Route::any ('home/quit','Home\ LoginController@quit'); Route::any (' home/index','Home\ IndexController@index'); Route::any ('home/article','Home\ IndexController@article');})

The following are the optimizations made above

Route::group (['middleware'= > [' web','admin.login']], 'prefix'= >' admin', 'namespace' = >' Admin',function () {Route::any ('quit','LoginController@quit'); Route::any (' index','IndexController@index'); Route::any ('article','IndexController@article');}) The above is all the contents of the article "login operation of blog project in laravel and sample analysis of creating background home page". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report