{include file='common/header'/}
<div class="row">
    <div class="col-md-3">
        {include file='auth/left'/}
    </div>
    <div class="col-md-9">
        <div class="panel panel-default">
            <div class="panel-body">
                <h1>
                    <div class="btn-group pull-right">
                        <a href="{:url('user/auth/login')}" class="btn btn-primary">用户登录</a>
                        <a href="{:url('user/auth/reg')}" class="btn btn-primary">会员注册</a>
                        <a href="{:url('user/auth/password')}" class="btn btn-primary">找回密码</a>
                    </div>
                    找回密码
                </h1>
                <hr>
                <form class="form-horizontal well" id="password_form" onsubmit="return M.password();" method="post" action="{:url('user/auth/password')}">
                    <div class="form-group">
                        <label for="email" class="col-sm-2 control-label">邮箱</label>
                        <div class="col-sm-10">
                            <input name="email" type="text" class="form-control" id="email">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">邮箱认证码</label>
                        <div class="col-sm-10">
                            <div class="input-group">
                                <input type="text" name="password_code" class="form-control" placeholder="">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button" onclick="M.sendCode()">发送认证码</button>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="password" class="col-sm-2 control-label">新密码</label>
                        <div class="col-sm-10">
                            <input name="password" type="text" class="form-control" id="password">
                            <p class="help-block">任意6-12位字符</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="password2" class="col-sm-2 control-label">重复密码</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="password2" placeholder="再次确认密码">
                        </div>
                    </div>
                    {if condition="false !== eb_config('user.password.captcha')"}
                        {include file='common/captcha' /}
                    {/if}
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-primary" >提交</button>
                        </div>
                    </div>
                </form>
                <script>
                    var M={};
                    $(function(){
                        M.password = function(){
                            if ($('#password').val() != $('#password2').val()) {
                                alert('两次密码不一致！');
                                return false;
                            }
                            $.ajax({
                                url: '{:url('user/auth/password')}',
                                type: 'POST',
                                dataType: 'json',
                                data: $('#password_form').serialize(),
                                success:function(data){
                                    alert(data.msg);
                                    if (data.code) {
                                        self.location=data.url;
                                    }else{
                                        change_captcha('#captcha_img');
                                    }
                                }
                            });
                            return false;
                        };
                        M.sendCode = function(){
                            var email = $('#email').val();
                            $.ajax({
                                url: '{:url('user/auth/passwordcode')}',
                                type: 'POST',
                                dataType: 'json',
                                data: {
                                    email:email,
                                },
                                success:function(data){
                                    alert(data.msg);
                                }
                            });
                            return false;
                        }
                    });
                </script>
            </div>
        </div>
    </div>
</div>
{include file='common/footer'/}