一、前言
实际开发中,一些应用通常要考虑到安全性问题。例如:对于一些重要的操作,有些请求需要用户验明身份后才能进行相应的操作。现在开始一个个人博客的登录功能,学艺不精请多指点。
二、登录页面
1、背景:登录页面要有背景,覆盖当前所看到的页面
2、输入框:登录页面要有用户名以及用户的密码输入框,用户输入密码为空或者输入用户名为空的时候就点击登录按钮会报错:用户名和密码错误。
3、登录的按钮:输入正确的用户名和密码方可进入个人的博客网站页面(输入错误的用户名和密码会弹出提示语:用户名或密码错误)
4、用户名和密码输入有15个字符的限制,超过十五个字符强制不给输入
1、登录页面效果图
这是登录页面的效果,我电脑屏幕比较小,我没有做适应屏幕的字体,关键代码我用了js。
2、关键代码
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>登录博客后台</title>
<meta http-equiv="Cache-Control" content="no-siteapp"/>
<link rel="shortcut icon" th:href="@{/user/img/bloglogo.jpg}"/>
<script th:src="@{/assets/js/jquery.min.js}"></script>
<script th:src="@{/assets/js/amazeui.min.js}"></script>
<link rel="stylesheet" th:href="@{/assets/css/amazeui.min.css}"/>
<link rel="stylesheet" th:href="@{/assets/css/app.css}"/>
</head>
<body data-vide-bg="/assets/img/ceshi1.mp4">
<div>
<div class="am-g">
<div class="am-u-lg-3 am-u-md-6 am-u-sm-8 am-u-sm-centered log-content">
<h1 class="log-title am-animation-slide-top" style="color: white;" th:text="#{login.welcomeTitle}">欢迎登录博客</h1>
<br>
<div th:if="${param.error}" style="color: red" th:text="#{login.error}">用户名或密码错误!</div>
<form class="am-form" id="loginForm" th:action="@{/login}" method="post">
<div>
<input type="hidden" name="url" th:value="${url}">
</div>
<div class="am-input-group am-radius am-animation-slide-left">
<input type="text" maxlength="15" class="am-radius" th:placeholder="#{login.username}" name="username" />
<span class="am-input-group-label log-icon am-radius">
<i class="am-icon-user am-icon-sm am-icon-fw"></i>
</span>
</div>
<br>
<div class="am-input-group am-animation-slide-left log-animation-delay">
<input type="password" maxlength="15" class="am-form-field am-radius log-input" th:placeholder="#{login.password}" name="password" />
<span class="am-input-group-label log-icon am-radius">
<i class="am-icon-lock am-icon-sm am-icon-fw"></i>
</span>
</div>
<div class="checkbox mb-3" style="color: white">
<label>
<input name="rememberme" type="checkb