<?php

/**
 *      【橙创家校通v4.0】 (C)2010-2012 Tuntron Inc.
 *      
 *    	 http://www.tuntron.com   QQ：1121251729
 *
 *      &重设密码模块&
 */
 
if (!defined('IS_RUN')) die('Forbidden');
$Modname = '重设密码';

switch($c){
	
	case "":
	
		$email = trim($_GET['mail']);
		$resetpwd = trim($_GET['code']);
		
		$userNum = G_class('user')->find(array(
			'email'=>$email,
			'resetpwd'=>$resetpwd,
		));
		if($email=='' || $resetpwd==''){
			Note("重置密码所需条件不够！");
		}elseif($userNum[0] == 0){
			Note("该链接已经失效，请重新发送重置请求！",'>>找回密码<<',SITEURL.'?mod=login&do=forgetpwd');
		}else{
			$user = G_class('user')->read_by_email($email);
		
		}
		
		
		break;
	
	//执行
	case "do":
		
		$uid 	= trim($_POST['uid']);
		$email 	= trim($_POST['email']);
		$mobile 	= trim($_POST['mobile']);
		$pwd 	= trim($_POST['password']);
		$repwd	= trim($_POST['password2']);
		
		$resetpwd = trim($_POST['resetpwd']);
		
		if($email=='' && $mobile==''){
			Note("所有输入项都不能为空！");
		}
		if($email){
			$userNum = G_class('user')->find(array(
				'email'=>$email,
				'resetpwd'=>$resetpwd,
			));
		}else{
			$userNum = G_class('user')->find(array(
			'phonenum'=>$mobile,
			'resetpwd'=>$resetpwd,
			));
			
		}
		if($pwd=='' || $repwd=='' || $resetpwd==''){
			Note("所有输入项都不能为空！");
		}elseif($userNum[0] == 0){
			Note("该链接已经失效，请重新发送重置请求！",'>>找回密码<<',SITEURL.'?mod=login&do=forgetpwd');
		}else{
			
		$post = G_class('user')->get_post($_POST);
		G_class('user')-> change_password($post['oldpasswd'],$post['password'],$post['password2'],$post['uid'],1);
		G_class('user')->update_resetpwd($email?$email:$mobile,'',$email?'email':'phonenum');
		Note('新密码已经生效！','>>请使用新密码登录<<',SITEURL.'?mod=login&do=login&c=out');
		
		}
		
		break;
	
	
}

require_once Template('resetpwd');

?>