三期_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来维护 ...
随机推荐
- CVTE面经
神一般的面试经历.也算面了不少公司,没见过这种面试. 一面:三个同学对应一个面试官,同一个问题依次作答. 1.为什么投递这个岗位? 答:blablabla... 2.最难忘的成功项目? 答:blabl ...
- office 2010 破解
使用Rearm命令激活延迟重置Office 20101.安装Offcie 2010 安装Offcie 2010,默认30天的试用期,这里要注意,上文提供的Office 2010是零售版,所以没有序列号 ...
- Laravel5.1学习笔记7 视图
视图 (View) 基本用法 传递数据到视图 在多个视图中分享数据 视图组件 #基本用法 视图里面包含了你应用程序所提供的 HTML 代码,并且提供一个简单的方式来分离控制器和网页呈现上的逻辑.视 ...
- reduce多种方法计算数组中某个值的出现次数
先来了解下reduce用法 arr.reduce(callback[, initialValue]) callback执行数组中每个值的函数,包含四个参数: accumulator 累计器累计回调的返 ...
- MSP430之section(1)
1 Intro The smallest unit of an object file is a section. A section is a block of code or data that ...
- 实验8 标准模板库STL
一.实验目的与要求: 了解标准模板库STL中的容器.迭代器.函数对象和算法等基本概念. 掌握STL,并能应用STL解决实际问题. 二.实验过程: 完成实验8标准模板库STL中练习题,见:http:// ...
- printf 打印较长字符
- h5调用app中写好的的方法
做h5页面的时候,总会遇到些不能解决的问题于是就要与app做一些交互, app那边编辑好的方法后我们怎么用js语法去调用app编写好的方法 if(this.$winInfo.shebei == 1){ ...
- 整理Webview加载缓慢的解决方案
1.https://www.cnblogs.com/xinye/p/3144139.html 2.https://www.jianshu.com/p/95d4d73be3d1
- BZOJ 4698: Sdoi2008 Sandy的卡片 后缀数组 + RMQ + 查分
题目描述 Sandy和Sue的热衷于收集干脆面中的卡片. 然而,Sue收集卡片是因为卡片上漂亮的人物形象,而Sandy则是为了积攒卡片兑换超炫的人物模型. 每一张卡片都由一些数字进行标记,第i张卡片的 ...