登录思路:   前台发送一个请求,然后通过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的更多相关文章

  1. WordPress 使用 Pie-Register 添加前台注册、登录、找回密码和编辑个人资料功能

    转自:http://www.wpdaxue.com/front-end-publishing.html Pie-Register 是一个功能比较完善的 WordPress 才能,使用它可以很方便添加和 ...

  2. dedecms织梦后台password忘记了怎么办?dedecms织梦后台password忘记怎样找回password?

    方法一:自己用解密的方式 用phpmyadmin登陆后台数据库,查看 找到password:去除前三位和后一位,然后拷贝到http://www.cmd5.com/在线解密工具里面解密 watermar ...

  3. 新西兰天维网登录发送明文password

    新西兰比較有人气的华人社区站点是天维网(新西兰天维网),是这边华人用中文吐槽常常上的论坛,也是华人之间各种交易(比方买卖二手车)的集散地.上次非诚勿扰新西兰专场就是天维网承办的宣传和报名.来新西兰定居 ...

  4. aix用户登录次数受限问题(3004-300 输入了无效的登录名或password)

    当登录AIX系统.username或password不对以至于多次登录,超过系统设定的次数,怎样解锁: 1.用root用户登录系统 2.chuser unsuccessful_login_count= ...

  5. 下次自己主动登录(记住password)功能

    1:进入cookie插件 <script src="jquery.cookie.js" type="text/javascript"></sc ...

  6. SSH证书登录方式(无password验证登录)

    经常在工作中须要在各个Linux机间进行跳转,每次password的输入成了麻烦,并且也不安全.在实际使用中,在windows下常使用secureCRT工具或teraterm工具进行SSH登录.以及实 ...

  7. redmine忘记username和password

    环境: Ubuntu 13.10 bitnami-redmine-2.5.1-1-linux-x64-installer.run 用bitnami安装完redmine以后,有是否忘记了username ...

  8. 诡异的 &quot;password取回&quot; 邮件问题

    大部分系统中都有"找回password"的功能,我们的平台也做了此功能,用户可通过 短信,邮件 找回password. 当中对于邮件找回password的方式遇到奇特的问题.记录下 ...

  9. laravel5.3的多用户登录,经过验证laravel5.4可用【转帖】

    简介 在底层代码中,Laravel 的认证组件由 guards 和 providers组成,Guard 定义了用户在每个请求中如何实现认证,例如,Laravel 通过 session guard来维护 ...

随机推荐

  1. PHP无限级分类实现(递归+非递归)

    <?php /** * Created by PhpStorm. * User: qishou * Date: 15-8-2 * Time: 上午12:00 */ //准备数组,代替从数据库中检 ...

  2. android黑科技系列——微信定位聊天记录中照片的位置信息插件开发详解

    一.前言 最近关于微信中,朋友之间发送原图就可能暴露你的位置信息,其实这个问题不在于微信,微信是为了更好的体验效果,才有发送原图功能,而对于拍照,发送普通图片微信后台都会过滤图片的exif信息,这样就 ...

  3. java与安卓中的回调callback学习笔记

    1.回调的简单设计如下: package com.listercai.top; public class A { private CallBack callBack; private AnotherC ...

  4. springboot + sharding-jdbc 学习

    官网地址:http://shardingsphere.io/document/current/cn/overview/ sharding-jdbc事务:https://blog.csdn.net/ya ...

  5. 从XMLHttpRequest中获取请求的URL

    在编写Ajax通用错误处理程序时,经常需要记录发生错误的XMLHttpRequest的请求URL.但查询文档,并未找到从XMLHttpRequest中获取请求URL的方法. 在javascript - ...

  6. SLAM: 图像角点检测的Fast算法(时间阈值实验)

    作为角点检测的一种快速方法,FastCornerDetect算法比Harris方法.SIft方法都要快一些,应用于实时性要求较高的场合,可以直接应用于SLAM的随机匹配过程.算法来源于2006年的Ed ...

  7. (转)OpenLayers3基础教程——OL3之Popup

    http://blog.csdn.net/gisshixisheng/article/details/46794813 概述: 本节重点讲述OpenLayers3中Popup的调用时实现,OL3改用O ...

  8. 支持移动触摸的jQuery图片Lightbox插件

    简介 这是一款支持移动触摸设备的简洁jQuery图片Lightbox插件.该LightBox插件可以在移动手机和桌面设备中运行,它具有响应式,预加载图片,键盘支持等特点,非常实用.它的特点还有: 响应 ...

  9. 01010_Eclipse中项目的jar包导入与导出

    1.jar包 jar包是一个可以包含许多.class文件的压缩文件.我们可以将一个jar包加入到项目的依赖中,从而该项目可以使用该jar下的所有类:也可以把项目中所有的类打包到指定的jar包,提供给其 ...

  10. UVALive 6177 The King's Ups and Downs

    The King's Ups and Downs Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UV ...