<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-lg-6 mx-auto">
		<div class="card">
			<div class="card-header">
				<?php echo lang('user_resetpw');?>
			</div>
			<div class="card-body">
				<form action="<?php echo url('user-resetpw');?>" method="post" id="form">
				
					<!--{hook user_resetpw_email_before.htm}-->
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon icon-envelope icon-fw"></i></span>
						</div>
						<input type="text" class="form-control" placeholder="<?php echo lang('email');?>" name="email" id="email">
						<div class="invalid-feedback"></div>
					</div>
					<!--{hook user_resetpw_email_after.htm}-->
					
					<!--{hook user_resetpw_verify_code_before.htm}-->
					<div class="media">
						<div class="media-body">
							<div class="form-group input-group">
								<div class="input-group-prepend">
									<span class="input-group-text"><i class="icon icon-key icon-fw"></i></span>
								</div>
								<input type="text" class="form-control" placeholder="<?php echo lang('verify_code');?>" name="code" id="code">
							</div>
						</div>
						<div class="ml-1 mt-1">
							<button type="submit" class="btn btn-primary btn-sm ml-3" id="send" data-loading-text="<?php echo lang('sending');?>..." action="<?php echo url('user-send_code-user_resetpw');?>"><?php echo lang('send_verify_code');?></button>
						</div>
					</div>
					<!--{hook user_resetpw_verify_code_after.htm}-->
					
					<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..." <?php if($conf['user_create_email_on']) { ?>disabled<?php } ?>><?php echo lang('next_step');?></button>
				</form>
			</div>
		</div>
	</div>
</div>

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>

<script>
var jform = $('#form');
var jsubmit = $('#submit');
var jsend = $('#send');
jsend.on('click', function() {
	jform.reset();
	jsend.button('loading');
	var postdata = jform.serialize();
	$.xpost(jsend.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			$('#code').focus();
			var t = 60; // 倒计时
			jsend.button('<?php echo lang('user_send_sucessfully');?> 60 ');
			jsubmit.button('reset');
			// 倒计时，重新发送
			var handler = setInterval(function() {
				jsend.button('<?php echo lang('user_send_sucessfully');?> '+(--t)+' ');
				if(t == 0) {
					clearInterval(handler);
					jsend.button('reset');
				}
			}, 1000);
		} else if(code < 0) {
			$.alert(message);
			jsend.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsend.button('reset');
		}
	});
	return false;
});

jform.on('submit', function() {
	jform.reset();
	jsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.button(message).delay(1000).location(xn.url('user-resetpw_complete'));
		} else if(xn.is_number(code)) {
			alert(message);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});

</script>