<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Aisky-CowdungCart</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">

    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>

    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>

    <script src="../static/js/registration.js"></script>

    <link rel="stylesheet" href="../static/css/registration.css">

    <script>
            function Registration(){
                var firstname = $("input[name='firstname']").val();
                var lastname = $("input[name='lastname']").val();
                var email = $("input[name='email']").val();
                var phone = $("input[name='phone']").val();
                var username = $("input[name='username']").val();
                var password = $("input[name='password']").val();
                var confirmpwd = $("input[name='confirmpwd']").val();
                var data = {"firstname":firstname, "lastname":lastname, "email":email, "phone":phone, "username":username, "password":password};

                $.ajax({
                    url: "/login",
                    type: "post",
                    data: data,
                    dataType: "json",
                    success: function(res){
                        if(res.access_token){
                            console.log("test");
                            localStorage.setItem('Hello', res.access_token);
                            window.location.href='/';
                        };
                    },
                });
            };
        </script>


</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-2"></div>
            <div class="col">
                <img src="../static/img/logo_new.png" class="img-fluid">
                <h1 class="text-center">Registration</h1>
                <!--<form method="post" action="/register">-->
                    <div class="form">
                        <div class="wrong-info"><span id="firstname-span"></span></div>
                        <div class="form-inline">
                            <label for="first">First Name</label>
                            <input type="text" class="form-control" id="first" name="firstname">
                        </div>
                        <div class="wrong-info"><span id="lastname-span"></span></div>
                        <div class="form-inline">
                            <label for="last">Last Name</label>
                            <input type="text" class="form-control" id="last" name="lastname">
                        </div>
                        <div class="wrong-info"><span id="email-span"></span></div>
                        <div class="form-inline">
                            <label for="email">Email</label>
                            <input type="email" class="form-control" id="email" name="email">
                        </div>
                        <div class="wrong-info"><span id="phone-span"></span></div>
                        <div class="form-inline">
                            <label for="phone">Phone</label>
                            <input type="number" class="form-control" id="phone" name="phone">
                        </div>
                        <div class="wrong-info"><span id="username-span"></span></div>
                        <div class="form-inline">
                            <label for="usr">User Name</label>
                            <input type="text" class="form-control" id="usr" name="username">
                        </div>
                        <div class="wrong-info"><span id="password-span"></span></div>
                        <div class="form-inline">
                            <label for="pwd">Password</label>
                            <input type="password" class="form-control" id="pwd" name="password">
                        </div>
                        <div class="wrong-info"><span></span></div>
                        <div class="form-inline">
                            <label for="cpwd">Confirm Password</label>
                            <input type="password" class="form-control" id="cpwd" name="confirmpwd">
                        </div>
                    </div>
                    <div class="text-center">
                        <input type="submit" class="btn btn-info" value="Register" onclick="Registration()" style="margin-right:70px;">
                        <input type="button"  class="btn btn-info" value="Cancel" onclick="Login()">
                    </div>
                <!--</form>-->
            </div>
            <div class="col-2"></div>
        </div>
    </div>
</body>
</html>