三期_day06_登录和找回password
登录思路: 前台发送一个请求,然后通过spring的自己主动注參注入username和password,将password加密后与数据库中查找的做比較。返回是否通过。
这里还使用了EasyUI的校验控件。不得不说,使用框架真快。不须要写那么多繁杂的脚本代码。
1.页面代码
<form id="ff" method="post" action="UserInfo_login">
<div><label for="name">邮箱:</label> <input id="name" name="email" type="text" /></div>
<div><label for="email">密码:</label> <input id="pwd" name="passwords" type="password"/></div>
</form>
2.脚本代码
<script>
$(function() {
$('#login').dialog({
title : 'CRM后台登录',
modal : true,
closable : false,
draggable:false,
buttons : [ {
text : '登录',
iconCls : 'icon-ok',
handler : function() {
var isValid = $('#ff').form('validate');
if (!isValid){
return false;
}else{
$('#ff').submit();
}
}
} ],
});
start();
}); function start() {
$('#name').validatebox({
required : true,
validType : 'email',
missingMessage : "邮箱为空 ",
invalidMessage : "请输入正确的邮箱"
});
$('#pwd').validatebox({
required : true,
missingMessage : "password为空 "
});
}
</script>
3.Action层代码
注解:
@Controller("userInfoAction")
public class UserInfoAction implements ModelDriven<UserInfo>, SessionAware {
@Autowired
private UserInfoService userInfoService;
private UserInfo userInfo;
private String result;
private Map<String, Object> session;
private Object jsondata;
解释一下:
UserInfoService: 通过spring的自己主动注參能够取到业务类对象。
UserInfo: 通过模型驱动,实现getModel方法。就可以获取页面上的输入控件的值,仅仅要name为userInfo中的属性就可以。
result: 是为了转发的,比如登录失败。多种情况时。
session: session的取得是通过实现SessionAware接口,还要实现一个setSession方法。
当然也有ActionContext和ServletActionContext,这样的原理是基于IOC(控制反转)为Action注入參数。其原理就是反射。
jsondata: 这个是为了转发json数据而存在的。
简单来说,这里面的东西就是一个大容器。到处都是spring的自己主动注參。特别是service层,action层,数据持久层,连structs转发也有它的身影。
mybatis+spring+structs2
public String login() {
String password = userInfo.getPasswords(); // 原密码
userInfo.setPasswords(Encrypt.md5(userInfo.getPasswords()));
userInfo = userInfoService.login(userInfo);
if (userInfo != null) {
userInfo.setPasswords(password); // 在页面上显示的是未加密的密码,便于改动
session.put(CrmConstants.USERINFO, userInfo); //存入session中
result = "";
if (userInfo.getPl() == 2) { // 老板
result += "boss/frame"; // ${result}.jsp -> workers/frame.jsp
} else if (userInfo.getPl() == 1) { // 员工
result += "workers/frame";
} else if (userInfo.getPl() == 0) { // 客户
result += "customers/frame";
} else if (userInfo.getPl() == 3) { // 超级管理员
result += "workers/frame";
}
return "login_success";
} else {
return "fail";
}
}
4.Service业务层代码
@Service("userInfoService")
public class UserInfoServiceImpl implements UserInfoService{
<span style="white-space:pre"> </span>@Autowired
<span style="white-space:pre"> </span>private UserInfoMapper userInfoMapper;
方法
public UserInfo login(UserInfo userInfo) {
return userInfoMapper.findUser(userInfo);
}
5.数据持久层
public interface UserInfoMapper {
UserInfo getUserInfoById(int id);
int insertUserInfo(UserInfo userInfo);
UserInfo findUser(UserInfo userInfo);
int updateUserInfoDate(UserInfo userInfo);
int vailEmail(String email);
int modify(UserInfo userInfo);
int deleteUserByUid(int uid);
}
UserInfoMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yc.crm.mapper.UserInfoMapper"> <resultMap id="BaseResultMap" type="com.yc.crm.entity.UserInfo">
<id column="CRM_ID" property="uid" />
<result column="EMAIL" property="email" />
<result column="PASSWORDS" property="passwords" />
<result column="CNAME" property="cname" />
<result column="PHONE" property="phone" />
<result column="SEX" property="sex" />
<result column="AGE" property="age" />
<result column="ADDRESS" property="address" />
<result column="USERLEVEL" property="level" />
<result column="PL" property="pl" />
<result column="CREATEDATE" property="createdate" />
<association property="bussiness"
resultMap="com.yc.crm.mapper.BusinessMapper.BaseResultMap" />
</resultMap>
<select id="findUser" parameterType="UserInfo" resultMap="BaseResultMap">
select * from crm_user_info u join crm_business b on
u.bussiness_id=b.business_id where u.email=#{email} and
u.passwords=#{passwords}
</select>
</mapper>
说明的是: 1. 数据库不同。编写的语句也不同。比如mysql的获取自增主键ID和oracle不同,这个问题至少困扰了几天。
2. 查询的时候。由于实体类和数据库中的字段不同,比如字段为企业ID,而实体类中属性为企业实体类,这个时候查询须要使用join将business表联合起来,否则获取的business实体对象除了ID。其余属性皆为空。
3.假设在这里使用了keyword,不必惊慌。能够加上"UID"来解决。加了"UID"必须大写。
4.mybatis中的标签要合理使用,比如update时候使用if-set标签。if标签的整形推断条件,以下来几个坑过我的样例。
eg 1.0
<update id="modify" parameterType="UserInfo">
update crm_user_info
<set>
<if test="passwords!=null and passwords!=''">
passwords=#{passwords},
</if>
phone=#{phone},sex=#{sex},"AGE"=#{age},userlevel=#{level},address=#{address} where email=#{email}
</set>
</update>
eg 1.1
<select id="find" parameterType="OrderDetail" resultMap="BaseResultMap">
select * from crm_order_detail det
join crm_order de on det.o_id=de.o_id
join crm_user_info cu on cu.crm_id=de.c_id
join crm_gods gods on gods.g_id=det.g_id
where de.e_id=#{order.worker.uid}
<if test="state!=null and state>=0">
and det.state=#{state}
</if>
<if test="god!=null and god.name!=null and god.name!='' ">
and gods.g_name like '%'||#{god.name}||'%'
</if>
<!--<if test="odate!=null and udate!=null"> <![CDATA[ >= ]]>
and odate between to_date(#{odate},'yyyy-mm-dd') and to_date(#{udate},'yyyy-mm-dd')
</if> -->
<if test="order!=null and order.customer!=null and order.customer.cname!=null and order.customer.cname!=''">
and cu.cname like '%'||#{order.customer.cname}||'%'
</if>
</select>
1.须要说明的是,上面的日期我还没解决。从前台控件取的日期,到action层为java.util.Date,而数据库的是java.sql.Date,这倆者须要在oracle比較。
2.上面的推断条件不是一步到位,而是一步一步的推断是否为空。
order!=null and order.customer!=null and order.customer.cname!=null and order.customer.cname!=''
3.like查询使用了字符拼接。使用自带函数我没有成功过。
至于找回password,发送请求,后台发送一封邮件至客户邮箱,这个技术不是非常难。
我是菜鸟,我在路上。
三期_day06_登录和找回password的更多相关文章
- WordPress 使用 Pie-Register 添加前台注册、登录、找回密码和编辑个人资料功能
转自:http://www.wpdaxue.com/front-end-publishing.html Pie-Register 是一个功能比较完善的 WordPress 才能,使用它可以很方便添加和 ...
- dedecms织梦后台password忘记了怎么办?dedecms织梦后台password忘记怎样找回password?
方法一:自己用解密的方式 用phpmyadmin登陆后台数据库,查看 找到password:去除前三位和后一位,然后拷贝到http://www.cmd5.com/在线解密工具里面解密 watermar ...
- 新西兰天维网登录发送明文password
新西兰比較有人气的华人社区站点是天维网(新西兰天维网),是这边华人用中文吐槽常常上的论坛,也是华人之间各种交易(比方买卖二手车)的集散地.上次非诚勿扰新西兰专场就是天维网承办的宣传和报名.来新西兰定居 ...
- aix用户登录次数受限问题(3004-300 输入了无效的登录名或password)
当登录AIX系统.username或password不对以至于多次登录,超过系统设定的次数,怎样解锁: 1.用root用户登录系统 2.chuser unsuccessful_login_count= ...
- 下次自己主动登录(记住password)功能
1:进入cookie插件 <script src="jquery.cookie.js" type="text/javascript"></sc ...
- SSH证书登录方式(无password验证登录)
经常在工作中须要在各个Linux机间进行跳转,每次password的输入成了麻烦,并且也不安全.在实际使用中,在windows下常使用secureCRT工具或teraterm工具进行SSH登录.以及实 ...
- redmine忘记username和password
环境: Ubuntu 13.10 bitnami-redmine-2.5.1-1-linux-x64-installer.run 用bitnami安装完redmine以后,有是否忘记了username ...
- 诡异的 "password取回" 邮件问题
大部分系统中都有"找回password"的功能,我们的平台也做了此功能,用户可通过 短信,邮件 找回password. 当中对于邮件找回password的方式遇到奇特的问题.记录下 ...
- laravel5.3的多用户登录,经过验证laravel5.4可用【转帖】
简介 在底层代码中,Laravel 的认证组件由 guards 和 providers组成,Guard 定义了用户在每个请求中如何实现认证,例如,Laravel 通过 session guard来维护 ...
随机推荐
- java常见面试题03-String,StringBuffer,StringBuilder的区别
面试题 A:String,StringBuffer,StringBuilder的区别 1:String 内容不可变,StringBuffer.StringBudiler可变 2:StringBu ...
- C99C新增内容
继上一篇复合文字之后,今天我们继续谈一谈C99C的新特性. C99标准是继C89标准之后的第二个C语言官方标准,于1999年12月1日正式发布,其中对数据类型(增加了对_Bool),关键字(增加了in ...
- B - Double Cola
Problem description Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double C ...
- 树莓派-基于raspistill实现定时拍照
raspistill 经过上一篇<<树莓派-安装摄像头模块>>之后 raspistill 是树莓派基于摄像头拍照命令 比如我要截取一张宽1024px,高768px,旋转180度 ...
- 关于sizeof()、size()的有些问题
#include<iostream>using namespace std; int main() { char a[] = "abcdefg"; string s = ...
- java Queue中 remove/poll, add/offer, element/peek区别
offer,add区别: 一些队列有大小限制,因此如果想在一个满的队列中加入一个新项,多出的项就会被拒绝. 这时新的 offer 方法就可以起作用了.它不是对调用 add() 方法抛出一个 unche ...
- ES6 Template String 模板字符串
模板字符串(Template String)是增强版的字符串,用反引号(`)标识,它可以当作普通字符串使用,也可以用来定义多行字符串,或者在字符串中嵌入变量. 大家可以先看下面一段代码: $(&quo ...
- R 连接mysql数据库
一.配置RODBC 1.R下载RODBC包,安装好.2.在http://dev.mysql.com/downloads/connector/odbc下载mySQL ODBC,安装好.3.windows ...
- dubbo之集群容错
在集群调用失败时,Dubbo 提供了多种容错方案,缺省为 failover 重试. 集群容错模式 1. Failover Cluster 失败自动切换,当出现失败,重试其它服务器 .通常用于读操作,但 ...
- mongodb 下载与安装文档
MongoDB数据库安装及配置环境(windows10系统) windows10系统下MongoDB的安装及环境配置: MongoDB的安装 下载地址: https://www.mongodb.c ...