【Basic computer】-----User Activation



User Activation 



      Most of website we use while we want to make it, they may want you to register . of course, this is real good not just for them but for you, you can have your own space and more convenient to use it .as a soft engineer, there is a one thing I want to share with you, after you register, you want to make sure you are succeed or not, their website may have the function will send you a message to help you to confirm it which we call it “User Activation”.
  

【Here is the business logic】

    Search the User from the activation number :


     (1)Check the user exist or not,if it exist then ;

             Alert the user state as 1;


     (2)If it is not exist:
            Activation number has change.


【Following is the code】

         



【UserDao.java】  

//根据激活码查询用户
	public User findByCode(String code){
		String hql="from User where conde=?";
		List<User>list =this.getHibernateTemplate().find(hql,code);
		if(list !=null && list.size()>0){
			 return list.get(0);
		}
		return null;
	}
	
	//修改用户状态方法
	public void update (User existUser){
		this.getHibernateTemplate().update(existUser);
	}


【UserAction.java】

      
         /**
	 * 用户激活的方法
	 * Daniel.He
	 */
   public void active(){
	   //根据激活码查询用户
	   User existUser = userService.findByCode(user.getCode());
	   //判断
	   if(existUser==null){
		   //激活错误的
		   this.addActionMessage("激活失败:激活码错误!");
	   }else{
		   //激活成功
		   //修改用户状态
		   existUser.setState(1);
		   existUser.setCode(null);
		   userService.update(existUser);
		   this.addActionMessage("激活成功:请去登录!");
	   }
   }



【UserService.java】

   
   //业务根据激活码查询用户
		public User findByCode(String code) {
			// TODO Auto-generated method stub
			return userDao.findByCode(code);
		}


       //修改用户状态的方法
		public void update(User existUser) {		
			// TODO Auto-generated method stub
		     userDao.update(existUser);
		}


        As you can see the code above, you will got a “bingo”! here is the what we call it “code library”, this kind of code can use in another function or system is real useful.Have you got the desire to want to have a try, ready go.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值