Home Web Front-end Layui Tutorial Layui login interface beautification effect display

Layui login interface beautification effect display

Jan 22, 2021 am 11:37 AM
layui login interface

Layui login interface beautification effect display

The complete code is shown below:

(Learning video sharing: Introduction to Programming)

1. Front-end html

login.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
    content="width=device-width, initial-scale=1, maximum-scale=1">
<title>登录</title>
<link rel="stylesheet" href="/static/css/layui.css">
<link rel="stylesheet" href="/static/css/login.css">
</head>
<body>
    <p class="clear box layui-main login">
  
        <form class="layui-form layui-form-pane1" action="ulogin" method="post">
            <p class="layui-form-item">
                <label class="layui-form-label">用户名:</label>
                <p class="layui-input-block">
                    <input type="text" name="user.name" lay-verify="uname" required
                        placeholder="请输入用户名" autocomplete="off" class="layui-input">${UnameErrMsg?if_exists}
                </p>
            </p>
            <p class="layui-form-item">
                <label class="layui-form-label">密码:</label>
                <p class="layui-input-block">
                    <input type="password" name="user.pwd" lay-verify="" required
                        placeholder="请输入密码" autocomplete="off" class="layui-input">${PwdErrMsg?if_exists}
                </p>
            </p>
            <p class="layui-form-item">
                <label class="layui-form-label">验证码:</label>
                <p class="layui-input-block">
                    <input type="text" name="yzm" lay-verify="" required
                        placeholder="请输入验证码" autocomplete="off" class="layui-input">${yzmErrMsg?if_exists}<br>
                <a href="/login.html"><img src="/static/imghw/default1.png"  data-src="/yzm"  class="lazy"  alt="验证码" ></a>
                </p>
            </p>
            <p class="layui-form-item">
            <label class="layui-form-label"></label>
                <button class="layui-btn layui-btn-normal btn-center" type="submit">登录</button>
            </p>
        </form>
    </p>
  
    <script src="/static/js/layui.js"></script>
</body>
</html>
Copy after login

Login interface style

@CHARSET "UTF-8";
body{
    background-image:url(/static/images/login-bg.png);
}
.login {
    padding-top: 15%;
    width: 26%;
}
  
.btn-center{
    text-center:center;
    margin:0 auto;
}
Copy after login

2. Write controller

The login method and ulogin method

under the controller package IndexController class

package cn.pangpython.controller;
  
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.kit.SessionIdKit;
  
import cn.pangpython.model.User;
import cn.pangpython.utils.DateUtils;
import cn.pangpython.utils.MD5;
import cn.pangpython.validate.RegistValidator;
import cn.pangpython.validate.UserLoginValidator;
  
/**
 * @author pangPython
 * 主页控制器
 */
public class IndexController extends Controller {
    public void index(){
        renderText("index");
    }
  
    //渲染注册页面
    public void regpage(){
        render("regist.html");
    }
  
    //处理注册
    @Before(RegistValidator.class)
    public void regist(){
        String pwd = getPara("user.pwd");
        String confirm = getPara("reg.confirm");
  
        //验证码验证
        boolean result = validateCaptcha("reg.yzm");
        if(!result){
            setAttr("yzmErrMsg", "验证码错误!");
            render("regist.html");
            return;
        }
        //确认密码验证
        if(!pwd.equals(confirm)){
            setAttr("confirmErrMsg", "请正确填写确认密码!");
            render("regist.html");
            return;
        }
  
        String uname = getPara("user.name");
        User user = getModel(User.class);
        String reg_time = DateUtils.dateToUnixTimestamp(DateUtils.getNowTime())+"";
        //使用用户注册日期作为md5密码加密的盐值,可节省一个salt数据库字段
        pwd = MD5.GetMD5Code(pwd+reg_time);
  
        //给user实体类填充数据
        user.setName(uname);
        user.setPwd(pwd);
        user.setRegTime(reg_time);
  
        //使用jfinal的保存操作
        user.save();
  
        renderText("注册成功!");
    }
  
    public void login(){
        render("login.html");
    }
  
    @Before(UserLoginValidator.class)
    public void ulogin(){
        // 验证码结果
        boolean result = validateCaptcha("yzm");
        if (!result) {
            setAttr("yzmErrMsg", "验证码错误!");
            render("login.html");
            return;
        }
  
        String uname = getPara("user.name");
        String sql = "select * from user where name = ? limit 1";
  
        User user = User.dao.findFirst(sql, uname);
        if (user != null) {
            String pwd = MD5.GetMD5Code(getPara("user.pwd") + user.getRegTime());
  
            if (user.getPwd().equals(pwd)) {
  
                // 生成唯一标识
                String sessionId = SessionIdKit.me().generate(getRequest());
                // 设置服务器端session
                setSessionAttr(sessionId, user);
                // 设置用户端cookie
                setCookie("cuser", sessionId, 60000);
                //redirect("/user");
                renderText("登录成功!");
  
            } else {
                // 密码不正确
                setAttr("UnameErrMsg", "用户名或密码不正确!");
                render("login.html");
            }
  
        } else {
            // 用户名不存在
            setAttr("UnameErrMsg", "用户名不存在!");
            render("login.html");
        }
  
    }
  
}
Copy after login

3. Write login validator

UserLoginValidator under the validator package inherits JFinal’s Validator

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
  
public class UserLoginValidator extends Validator {
  
    @Override
    protected void handleError(Controller controller) {
        controller.keepPara();
  
    }
  
    @Override
    protected void validate(Controller arg0) {
        validateRequired("user.name", "UnameErrMsg", "请输入用户名!");
        validateRequired("user.pwd", "PwdErrMsg", "请输入密码!");
        validateRequired("yzm", "yzmErrMsg", "请输入验证码!");
    }
  
}
Copy after login

Effect display:

Layui login interface beautification effect display

Layui login interface beautification effect display

Related recommendations: layui

The above is the detailed content of Layui login interface beautification effect display. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if win10 does not switch users? Win10 login interface does not have the option to switch users. Solution What should I do if win10 does not switch users? Win10 login interface does not have the option to switch users. Solution Jun 25, 2024 pm 05:21 PM

A problem that Windows 10 users may encounter is that they cannot find the switch user option on the login interface. So what should I do if there is no switch user option on the win10 login interface? Let this site give users a detailed explanation of the problem of not switching user options in the win10 login interface. Detailed solution to the problem of switching user options on the Win10 login interface: Check user account settings: First, make sure you have multiple user accounts on your computer and that these accounts are enabled. You can check and enable the account by following these steps: a. Press Win+I keys to open Settings and select "Accounts". b. Select "Family & Others" or &ld in the left navigation bar

Solve the infinite loop problem in win11 login interface Solve the infinite loop problem in win11 login interface Jan 29, 2024 pm 12:57 PM

Many users may encounter an endless loop in the login interface when starting their computer, that is, they cannot successfully enter the system. Recently, some users using win11 system have also encountered this problem. In this issue, the editor will share two solutions. Follow the steps to successfully enter the system and no longer fall into an endless loop. I hope this win11 tutorial can help more people solve this problem. How to solve the infinite loop in the win11 login interface. Method 1: 1. First, we can try to restart the computer using the power button to see if it can be solved by restarting. 2. If the problem cannot be solved, restart the computer more than 3 times in a row to enter the advanced repair options, and then select Troubleshooting. 4. Then select Uninstall updates in the advanced options. 5. Enter netshw

How to set up jump on layui login page How to set up jump on layui login page Apr 04, 2024 am 03:12 AM

Layui login page jump setting steps: Add jump code: Add judgment in the login form submit button click event, and jump to the specified page through window.location.href after successful login. Modify the form configuration: add a hidden input field to the form element of lay-filter="login", with the name "redirect" and the value being the target page address.

How to get form data in layui How to get form data in layui Apr 04, 2024 am 03:39 AM

layui provides a variety of methods for obtaining form data, including directly obtaining all field data of the form, obtaining the value of a single form element, using the formAPI.getVal() method to obtain the specified field value, serializing the form data and using it as an AJAX request parameter, and listening Form submission event gets data.

How layui implements self-adaptation How layui implements self-adaptation Apr 26, 2024 am 03:00 AM

Adaptive layout can be achieved by using the responsive layout function of the layui framework. The steps include: referencing the layui framework. Define an adaptive layout container and set the layui-container class. Use responsive breakpoints (xs/sm/md/lg) to hide elements under specific breakpoints. Specify element width using the grid system (layui-col-). Create spacing via offset (layui-offset-). Use responsive utilities (layui-invisible/show/block/inline) to control the visibility of elements and how they appear.

How to transfer data in layui How to transfer data in layui Apr 26, 2024 am 03:39 AM

The method of using layui to transmit data is as follows: Use Ajax: Create the request object, set the request parameters (URL, method, data), and process the response. Use built-in methods: Simplify data transfer using built-in methods such as $.post, $.get, $.postJSON, or $.getJSON.

What is the difference between layui and vue? What is the difference between layui and vue? Apr 04, 2024 am 03:54 AM

The difference between layui and Vue is mainly reflected in functions and concerns. Layui focuses on rapid development of UI elements and provides prefabricated components to simplify page construction; Vue is a full-stack framework that focuses on data binding, component development and state management, and is more suitable for building complex applications. Layui is easy to learn and suitable for quickly building pages; Vue has a steep learning curve but helps build scalable and easy-to-maintain applications. Depending on the project needs and developer skill level, the appropriate framework can be selected.

win11 stuck at login interface win11 stuck at login interface Jan 07, 2024 am 09:29 AM

After updating win11, some users will encounter some problems. This is a bug of win11 and it is normal. We will also encounter the login interface being stuck or even spinning in circles, unable to enter. In such a situation, How to deal with it. win11 is stuck on the login interface: 1. We can try to solve the problem by restarting, because restarting can generally solve most problems. 2. If restarting cannot solve the problem, we can restart the computer three times in a row and enter the advanced repair options. 3. After entering the advanced repair options, click "Troubleshoot". 4. Then click "Advanced Options". 5. Finally, select “Uninstall Update” to solve the problem. Further reading: Driver loading failed

See all articles