<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="Doxbin is a document sharing and publishing website for text-based information such as dox, code-snippets and other stuff.">
    <title>Reset Password - Doxbin</title>
    @include('_scripts')
    <link rel="stylesheet" href="/legacy/index.css">
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
	<style>
    .login-div{
        margin: 0 auto;
        max-width: 500px;
        min-width: 100px;
        width: 100%;
        text-align: left;
    }
    .login-div label{
        padding: 10px 0px 1px 3px;
        margin: 0;
    }
	input{
		line-height: 1.2;
		color: white;
		background: #282828;
		border: 0;
		border-radius: 2px;
		display: inline-block;
		-webkit-font-smoothing: antialiased;
		outline: none;
		padding: 7px 5px;
        width: 100%;
	}
	input::placeholder{
		color: rgb(167, 167, 167);
	}
	input[type=submit]{
		line-height: 1.2;
		color: white;
		background: #282828;
		border: 0;
		border-radius: 2px;
		display: block;
		-webkit-font-smoothing: antialiased;
		outline: none;
		padding: 7px 5px;
        width: 90%;
        margin: 15px auto 50px auto;
	}
	input{
		font-size: 100%;
	}
	
	input[type=submit]:hover{
		color: white;
		background: #3d3d3d;
		text-decoration: none;
	}
	</style>
</head>

<body>
{!! csrf_field() !!}
    @include('_nav')
    <div class="col-md-12" style="margin-top: 10px;">
        <div class="col-md-12" style="margin-top: 80px;">
    @if ($reset == null)
        <p class="text-center">That token does not exist.</p>
    @elseif($reset->expired == 1 || $reset->expires <= time())
        <p class="text-center">That token has expired.</p>
	@elseif($myUser != null)
        <p class="text-center">Log out before resetting password.</p>
    @else
        <div align="center">
            <h5 style="font-size: 25px;">Reset Password</h5>
            <p>Reset password to user <a href="/user/{{ $user->username }}">{{ $user->username }}</a>.</p>
            <noscript><p style="color: red; padding: 0px 0px 10px 0px; text-align: center; margin: 0;">Doxbin requires JavaScript to function correctly.</p></noscript>
            <div id="error-msg" style="color: red; padding: 0px 0px 10px 0px; text-align: center; margin: 0;"></div>
            </div>
        </div>
        <div class="col-md-6 col-md-offset-3 text-center">
            <div class="login-div">
                <form action="" method="POST" id="login-form">
                <label for="pass">New Password</label><br>
                <input name="pass" id="pass" type="password" placeholder="Password" autofocus><br>
                <label for="confpass">Confirm Password</label><br>
                <input name="confpass" id="confpass" type="password" placeholder="Confirm"><br>
                {!! csrf_field() !!}
                <input type="submit" value="Reset Password">
                </form>
            </div>
    @endif
        </div>
    </div>
    <script src="{{ asset('/legacy/jquery.min.js') }}"></script>
    <script src="{{ asset('/legacy/jquery-ui-1.10.3.custom.min.js') }}"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="{{ asset('/legacy/logout.js') }}"></script>
    <script>
	$(document).ready(function(){
		$('#login-form').on('submit', function(e){
            if($('#pass').val() != $('#confpass').val()){
                $('#error-msg').text('Passwords do not match.');
            }else{
                $.post('/password-reset/{{ ($reset == null ? 'null' : $reset->link)}}', {
                    _token: $('input[name=_token]').val(),
                    pass: $('#pass').val(),
                    confpass: $('#confpass').val(),
                }, function(resp){
                    if(resp.status == "err"){
                        $('#error-msg').text(resp.msg);
                    }else{
                        window.location = '/login?success=1';
                    }
                });
            }
			e.preventDefault();
		});
	});
	</script>
</body>
</html>