好看的web用户管理模块(登录注册)

简洁的登录注册前台

登录界面
在这里插入图片描述
导入bootstrap和jquery路径

<link rel="stylesheet" href="statics/bootstrap/css/bootstrap.min.css" />
<script type="text/javascript" src="statics/js/jquery-3.4.1.js"></script>

html

<body>
	<div class="container">
		
		<div class="row">
			<div class="col-md-offset-3 col-md-6">
				<form class ="form-horizontal" action="user" method="post" id="admin">
					<input type="hidden" name="actionName" value="login">
					<span class="heading"><font color="#4F4F4F">用户登录</font> </span>
					<div class="form-group">
						<input type="email" name="userName" class="form-control" id="inputEmail" placeholder="用户名或电子邮件">
						<i class="fa fa-user"></i>
					</div>
					<div class="form-group help">
						<input type="password" name="password" class="form-control" id="pwd" placeholder="密码">
						<i class="fa fa-lock"></i>
						<a href="#" class="fa fa-question-circle"></a>		
					</div>
					<div class="form-group">
						<div class="main-checkbox">
							<input type="checkbox" name="check" id="checkbox1" value="null">
							<label for="checkbox1"></label>
						</div>
						<span class="text">记住我</span>
						<button type="button" class="btn btn-default" id="asubmit">登录</button>
					</div>
				</form>
				
			</div>
			
		</div>
	</div>
</body>

js模块

	var userName = $("#inputEmail");
	var password = $("#pwd");

	$("#asubmit").click(function(){	
		if (userName.val() == "") {
			userName.attr("placeholder","请输入用户名或邮箱地址");
		}
		else if(password.val() == ""){
			password.attr("placeholder","请输入密码");
		}else {
			var pwdsha1 = hex_sha1(password.val());		//密码加密
			password.val(pwdsha1);
			$("form").submit();
			console.log(userName.val());
		}
	});

css

.form-bg{
    background: #00b4ef;
}
.form-horizontal{
    background: #fff;
    padding-bottom: 40px;
    border-radius: 15px;
    text-align: center;
    background: rgba(255,255,255,0.4);width:500px;height: 400px;margin:120px auto;
    box-shadow: 0px 0px 30px #ccc;
}
.form-horizontal .heading{
    display: block;
    font-size: 35px;
    font-weight: 700;
    padding: 35px 0;
    border-bottom: 1px solid #F0F0F0;
    margin-bottom: 30px;
    /*background-image: linear-gradient(to bottom,#6fcdd533, #11a3fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;*/
}
.form-horizontal .form-group{
    padding: 0 40px;
    margin: 0 0 25px 0;
    position: relative;
}
.form-horizontal .form-control{
    background: #f0f0f0;
    border: none;
    border-radius: 20px;
    box-shadow: none;
    padding: 0 20px 0 45px;
    height: 40px;
    transition: all 0.3s ease 0s;
}
.form-horizontal .form-control:focus{
    background: #e0e0e0;
    box-shadow: none;
    outline: 0 none;
}
.form-horizontal .form-group i{
    position: absolute;
    top: 12px;
    left: 60px;
    font-size: 17px;
    color: #c8c8c8;
    transition : all 0.5s ease 0s;
}
.form-horizontal .form-control:focus + i{
    color: #00b4ef;
}
.form-horizontal .fa-question-circle{
    display: inline-block;
    position: absolute;
    top: 12px;
    right: 60px;
    font-size: 20px;
    color: #808080;
    transition: all 0.5s ease 0s;
}
.form-horizontal .fa-question-circle:hover{
    color: #000;
}
.form-horizontal .main-checkbox{
    float: left;
    width: 20px;
    height: 20px;
    background: #11a3fc;
    border-radius: 50%;
    position: relative;
    margin: 5px 0 0 5px;
    border: 1px solid #11a3fc;
}
.form-horizontal .main-checkbox label{
    width: 20px;
    height: 20px;
    position: absolute;
    top: 0;
    left: 0;
    cursor: pointer;
}
.form-horizontal .main-checkbox label:after{
    content: "";
    width: 10px;
    height: 5px;
    position: absolute;
    top: 5px;
    left: 4px;
    border: 3px solid #fff;
    border-top: none;
    border-right: none;
    background: transparent;
    opacity: 0;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
}
.form-horizontal .main-checkbox input[type=checkbox]{
    visibility: hidden;
}
.form-horizontal .main-checkbox input[type=checkbox]:checked + label:after{
    opacity: 1;
}
.form-horizontal .text{
    float: left;
    margin-left: 7px;
    line-height: 20px;
    padding-top: 5px;
    text-transform: capitalize;
}
.form-horizontal .btn{
    float: right;
    font-size: 14px;
    color: #fff;
    background: #00b4ef;
    border-radius: 30px;
    padding: 10px 25px;
    border: none;
    text-transform: capitalize;
    transition: all 0.5s ease 0s;
}
@media only screen and (max-width: 479px){
    .form-horizontal .form-group{
        padding: 0 25px;
    }
    .form-horizontal .form-group i{
        left: 45px;
    }
    .form-horizontal .btn{
        padding: 10px 20px;
    }
}
body{
    background: url(../img/4.jpg);
    background-repeat: no-repeat;
    background-size: 100% auto;
      animation-name:myfirst;
    animation-duration:30s;
    /*变换时间*/
    animation-delay:2s;
    /*动画开始时间*/
    animation-iteration-count:infinite;
    /*下一周期循环播放*/
    animation-play-state:running;
    /*动画开始运行*/
}
@keyframes myfirst
{
    0%   {background:url("../img/1.jpg");}
    34%  {background:url("../img/2.jpg");}
    67%  {background:url("../img/3.jpg");}
    100% {background:url("../img/4.jpg");}
}

在这里插入图片描述
注册html

<div class="container">
		
		<div class="row">
			<div class="col-md-offset-3 col-md-6">
				<form class ="form-horizontal" action="user" method="post" id="admin">
					<input type="hidden" name="actionName" value="register">
					<span class="heading"><font color="#4F4F4F">用户注册</font> </span>
					<div class="form-group">
						<input type="email" name="ruserName" class="form-control" id="ruserName" placeholder="用户名或电子邮件" oninput="veName()">
						<i class="fa fa-user"></i>
					</div>
					<div class="form-group help">
						<input type="password" name="rpassword" class="form-control" id="pwd" placeholder="密码">
						<i class="fa fa-lock"></i>
						<a href="#" class="fa fa-question-circle"></a>		
					</div>
					<div class="form-group help">
						<input type="password" name="vpassword" class="form-control" id="vpwd" placeholder="验证密码">
						<i class="fa fa-lock"></i>
						<a href="#" class="fa fa-question-circle"></a>		
					</div>
					<div class="form-group help">
						<input type="text" name="age" class="form-control" id="age" placeholder="年龄">
						<i class="fa fa-lock"></i>
						<a href="#" class="fa fa-question-circle"></a>		
					</div>
					<div class="form-group help">
						<div class="main-checkbox">
							<input type="radio" name="userSix" id="man" value="man ">
							<label for="man"></label>
						</div><span class="text">男</span>
						<div class="main-checkbox">
							<input type="radio" name="userSix" id="woman" value="women ">
							<label for="woman"></label>
						</div><span class="text">女</span><span class="text" id="msg" style="font-size:12px;color:pink"></span>
					</div>
					<div class="form-group help">
						<div class="main-checkbox">
							<input type="checkbox" name="check" id="checkbox1" value="null">
							<label for="checkbox1"></label>
						</div>
						<span class="text">同意用户协议</span><span class="text" id="msg1" style="font-size:12px;color:pink"></span>
						<button type="button" class="btn btn-default" id="bu1">注册</button>
					</div>
				</form>
				
			</div>
			
		</div>
	</div>
</body>

js代码

var userName = $("#ruserName");
var password = $("#pwd");
var vpassword = $("#vpwd");
var userAge = $("#age");
var userSix = $("radio");
var flag = false;


$("#bu1").click(function(){	
	
	if (userName.val() == "") {
		userName.attr("placeholder","请输入用户名或邮箱地址");
		return;
	}
	if(password.val() == ""){
		password.attr("placeholder","请输入密码");
		return;
	}
	if (password.val().length <= 6) {
		password.attr("placeholder","密码必须等于或等于6个字符");
	}
	if(vpassword.val() == ""){
		vpassword.attr("placeholder","请输入密码");
		return;
	}
	if(userAge.val() == ""){
		userAge.attr("placeholder","请输入年龄");
		return;
	}
	 if($(":radio:checked").length < 1){
	 	$("#msg").html("请选择性别");
		return;
	} 
		
	if(password.val() != vpassword.val()){
		console.log(password.val());
		console.log("--------------");
		console.log(vpassword.val());
		password.val("");
		vpassword.val("");
		password.attr("placeholder","请验证密码是否正确");
		vpassword.attr("placeholder","请验证密码是否正确");
		return;
	}
	if($("#checkbox1").prop("checked")){
		var pwdsha1 = hex_sha1(password.val());
		password.val(pwdsha1);
		$("form").submit();
		console.log(userName.val());
		return;
	}else{
		$("#msg1").html("请同意用户协议");
	}	
});

function veName(){
	var uanme = userName.val();
	$.ajax({
		typr:"post",
		url:"register",
		data:{
			userName : uanme,
			actionName:"veName"
		},
		success:function(result) {
			if(result == "Suuccess"){
				flag = true;
			}else{
				flag = false;
				
			}
		}
	});
}


ccs(和登录模块大部分一致,需要自己进行封装)

.form-bg{
    background: #00b4ef;
}
.form-horizontal{
    background: #fff;
    padding-bottom: 35px;
    border-radius: 15px;
    text-align: center;
    background: rgba(255,255,255,0.45);
    width:450px;
    height: 520px;
    margin:90px auto;
    box-shadow: 5px 5px 20px #ccc;
}
.form-horizontal .heading{
    display: block;
    font-size: 35px;
    font-weight: 700;
    padding: 25px 0;
    border-bottom: 1px solid #dddddd82;
    margin-bottom: 30px;
    background-image: linear-gradient(to bottom,#6db6ae36, #0690e3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.form-horizontal .form-group{
    padding: 0 40px;
    margin: 0 0 25px 0;
    position: relative;
}
.form-horizontal .form-control{
    background: #f0f0f0;
    border: none;
    border-radius: 20px;
    box-shadow: none;
    padding: 0 20px 0 45px;
    height: 40px;
    transition: all 0.3s ease 0s;
}
.form-horizontal .form-control:focus{
    background: #e0e0e0;
    box-shadow: none;
    outline: 0 none;
}
.form-horizontal .form-group i{
    position: absolute;
    top: 12px;
    left: 60px;
    font-size: 17px;
    color: #c8c8c8;
    transition : all 0.5s ease 0s;
}
.form-horizontal .form-control:focus + i{
    color: #00b4ef;
}
.form-horizontal .fa-question-circle{
    display: inline-block;
    position: absolute;
    top: 12px;
    right: 60px;
    font-size: 20px;
    color: #808080;
    transition: all 0.5s ease 0s;
}
.form-horizontal .fa-question-circle:hover{
    color: #000;
}
.form-horizontal .main-checkbox{
    float: left;
    width: 20px;
    height: 20px;
    background: #11a3fc;
    border-radius: 50%;
    position: relative;
    margin: 5px 0 0 5px;
    border: 1px solid #11a3fc;
}
.form-horizontal .main-checkbox label{
    width: 20px;
    height: 20px;
    position: absolute;
    top: 0;
    left: 0;
    cursor: pointer;
}
.form-horizontal .main-checkbox label:after{
    content: "";
    width: 10px;
    height: 6px;
    position: absolute;
    top: 4.5px;
    left: 4px;
    border: 3px solid #eee;
    border-top: none;
    border-right: none;
    background: transparent;
    opacity: 0;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
}
.form-horizontal .main-checkbox input[type=radio]{
    visibility: hidden;
}
.form-horizontal .main-checkbox input[type=radio]:checked + label:after{
    opacity: 1;
}
.form-horizontal .main-checkbox input[type=checkbox]{
    visibility: hidden;
}
.form-horizontal .main-checkbox input[type=checkbox]:checked + label:after{
    opacity: 1;
}
.form-horizontal .text{
    float: left;
    margin-left: 7px;
    line-height: 20px;
    padding-top: 5px;
    text-transform: capitalize;
}
.form-horizontal .btn{
    float: right;
    font-size: 14px;
    color: #fff;
    background: #00b4ef;
    border-radius: 30px;
    padding: 10px 25px;
    border: none;
    text-transform: capitalize;
    transition: all 0.5s ease 0s;
}
@media only screen and (max-width: 479px){
    .form-horizontal .form-group{
        padding: 0 25px;
    }
    .form-horizontal .form-group i{
        left: 45px;
    }
    .form-horizontal .btn{
        padding: 10px 20px;
    }
}
body{
  background:#eee
}


登录注册的后端功能模块

DBUtil建立数据库连接

import java.sql.Connection;
import java.sql.DriverManager;

public class DBUtil {
	private String dbUrl = "jdbc:mysql://localhost:3306/logon";

	private String dbUserName = "root";
	private String dbUserPassword = "work";
	private String jdbcName = "com.mysql.jdbc.Driver";
	/**
	 * 获取数据库数据
	 * @return [description]
	 * @throws Exception     [description]
	 */
	public Connection getCon() throws Exception {
		Class.forName(jdbcName);
		Connection con = DriverManager.getConnection(dbUrl,dbUserName,dbUserPassword);
		return con;
	}
	/**
	 * 关闭数据库
	 * @param  con       [description]
	 * @throws Exception [description]
	 */
	public static void closeCon(Connection con) throws Exception {
		if(con != null) {
			con.close();
			System.out.println("数据库连接失败");
		}	
	}
	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args){
		DBUtil dbUtil = new DBUtil();
		
		try {
			dbUtil.getCon();
			System.out.println("数据库连接成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

BaseDao模块(实现登录注册功能)

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.susur.user.User;

public class Dao {
	/**
	 * 登录验证
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public User login(Connection con,User user) throws Exception{
		User resultUser = null;
		String sql = "select * from logon where userName=? and password=?";
		PreparedStatement pstmt = con.prepareStatement(sql);
		
		pstmt.setString(1, user.getUserName());
		pstmt.setString(2, user.getPassword());
		ResultSet rs = pstmt.executeQuery();
		
		System.out.println(rs);
		if(rs.next()) {
			resultUser = new User();
			resultUser.setUserName(rs.getString("userName"));
			resultUser.setPassword(rs.getString("password"));	
		}
		
		return resultUser;
	}
	/**
	 * 用户注册
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public boolean register(Connection con,User user) throws Exception {
		boolean flag = false;
		PreparedStatement pstmt = null;
		String sql = "insert into logon(userName,password,userAge,userSix)value(?,?,?,?)";
		pstmt = con.prepareStatement(sql);
		pstmt.setString(1, user.getUserName());
		pstmt.setString(2, user.getPassword());
		pstmt.setInt(3, user.getUserAge());
		pstmt.setString(4, user.getUserSix());
		
		if(pstmt.executeUpdate() > 0) {
			flag = true;
		}
		
		return flag;
	}
	/**
	 * 验证用户名是否存在
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public boolean vename(Connection con,User user) throws Exception{
		
		String sql = "select * from logon where userName=?";
		PreparedStatement pstmt = con.prepareStatement(sql);
		
		pstmt.setString(1, user.getUserName());
		ResultSet rs = pstmt.executeQuery();
		
		System.out.println(rs);
		return rs.next();
		
	}

}

这里需要个User类记录用户信息

	private String userName;
	private String password;
	private int userAge;
	private String userSix;

servlet建立与前台的连接完成请求转发功能

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.susur.DBU.DBUtil;
import com.susur.dao.Dao;
import com.susur.user.User;

/**
 * 用户管理模块
 */
public class UserProj extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public UserProj() {
        super();
    }

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String actionName = request.getParameter("actionName");
		switch(actionName) {
		case "login":
			loginSubmit(request,response);
			break;
		case "register":
			registerSubmit(request,response);
			break;
		case "veName":
			veNameSubmit(request,response);
			break;
		case "chfn":
			chfnSubmit(request,response);
			break;
		case "changePWD":
			changePWD(request,response);
			break;
		case "logout":
			logoutSubmit(request,response);
			break;
		}
	}
	/**
	 * 用户登录
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	private void logoutSubmit(HttpServletRequest request, HttpServletResponse response) throws IOException {
			
	}

	private void changePWD(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}

	private void chfnSubmit(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}

	private void veNameSubmit(HttpServletRequest request, HttpServletResponse response) throws IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		String userName = request.getParameter("userName");
		
		DBUtil db = new DBUtil();
		User user = new User();
		user.setUserName(userName);
		Dao dao = new Dao();
		
		try {
			Connection con = db.getCon();
			if(dao.vename(con, user)) {
				out.write("1");
				out.close();
				return;
			}else {
				out.write("0");
				out.close();
				return;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	/**
	 * 用户注册
	 * @param request
	 * @param response
	 * @throws UnsupportedEncodingException
	 */
	private void registerSubmit(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		
		String userName = request.getParameter("ruserName");
		String password = request.getParameter("rpassword");
		String age = request.getParameter("age");
		int userAge = Integer.valueOf(age).intValue();
		String userSix = request.getParameter("userSix");
		
		DBUtil db = new DBUtil();
		User user = new User(userName, password, userAge, userSix);
		Dao dao = new Dao();
		
		try {
			Connection con = db.getCon();
			if(dao.register(con, user)) {
				response.sendRedirect("login.html");
			}else {
				response.sendRedirect("register.jsp");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private void loginSubmit(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		DBUtil db = new DBUtil();
		User user = new User(userName, password);
		Dao dao = new Dao();
		
		try {
			Connection con = db.getCon();
			if(dao.login(con, user) != null) {
				response.sendRedirect("index.html");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
	}

}

  • 6
    点赞
  • 70
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值