login

mail@pastecode.io avatar
unknown
plain_text
a month ago
20 kB
2
Indexable
Never
<%-- 
    Document   : login
    Created on : Oct 2, 2023, 10:32:52 PM
    Author     : MSI GTX
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
        <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
        <style>
            body {
                background-color: brown;
                background: -webkit-linear-gradient(to left, #8E0E00, #581414);
                background: linear-gradient(to left, #8E0E00, #581414);
                background-size: cover;
                background-position-y: -80px;
                font-size: 20px;
                /* display: flex; */
                flex-direction: column;
                align-items: center;
                justify-content: center;
                height: 100vh;
                margin: 0;
            }

            #wrapper {
                min-height: 100vh;
                /*chiều cao tối thiểu như này là 100%*/
                display: flex;
                justify-content: center;
                align-items: center;
            }


            #form-login {
                max-width: 400px;
                background: rgba(0, 0, 0, 0.45);
                flex-grow: 1;
                padding: 30px 30px 60px;
                box-shadow: 0px 0px 17px 2px rgba(82, 46, 46, 0.8);
            }
            #form-forgot {
                max-width: 400px;
                background: rgba(0, 0, 0, 0.45);
                flex-grow: 1;
                padding: 30px 30px 60px;
                box-shadow: 0px 0px 17px 2px rgba(82, 46, 46, 0.8);
            }

            #form-signup {
                max-width: 400px;
                background: rgba(0, 0, 0, 0.45);
                flex-grow: 1;
                padding: 30px 30px 60px;
                box-shadow: 0px 0px 17px 2px rgba(82, 46, 46, 0.8);
            }

            .form-heading {
                font-size: 50px;
                color: #ffffff;
                text-align: center;
                margin-bottom: 30px;
            }

            .form-group {
                border-bottom: 1px solid #fcfdff;
                margin-top: 15px;
                margin-bottom: 20px;
                display: flex;
            }

            .form-group i {
                color: #fff;
                font-size: 16px;
                padding-top: 5px;
                padding-right: 10px;
            }

            .form-input {
                /*hiển thị ảnh nền tron suốt*/
                background: transparent;
                width: 100%;
                padding: 10px;
                border: 0;
                outline: 0;
                color: #ffffff;
                flex-grow: 1;
                /*mở rộng phần tử bằng khoảng trắng*/
            }

            .form-input::placeholder {
                color: #ffffff;
            }

            #eye i {
                padding-right: 0;
                cursor: pointer;
            }
            .material-symbols-rounded{
                color: white;
            }

            .form-submit {
                background: transparent;
                border: 1px solid #ffffff;
                color: #fff;
                width: 100%;
                text-transform: uppercase;
                padding: 6px 10px;
                transition: 0.25s ease-in-out;
                margin-top: 30px;
            }

            .form-submit:hover {
                border: 1px solid #54a0ff;
            }

            .form-button {
                background: transparent;
                text-align: center;
                border: 1px solid #ffffff;
                color: #fff;
                width: 95%;
                text-transform: uppercase;
                padding: 6px 10px;
                transition: 0.25s ease-in-out; /*giup chuyển đổi hiệu ứng mượt mà hơn*/
                margin-top: 30px;
                text-decoration: none; /* Loại bỏ gạch chân mặc định của thẻ a */
                display: inline-block; /* Để thẻ a có kích thước và padding như một nút */
            }

            .form-button:hover {
                border: 1px solid #54a0ff;
            }

            .error {
                color: #fff;
                font-size: 16px;
                display: block;
                margin-top: 5px;
            }

        </style>
    </head>
    <body>
        <!--form đăng nhập có login forgot email register-->

        <div id="wrapper">

            <form action="AccountController" id="form-login" method="post">
                <h1 class="form-heading">LOGIN</h1>
                <div class="form-group">
                    <span class="material-symbols-rounded">mail</span>
                    <input type="text" class="form-input" name="email" id="email" placeholder="Email">
                </div>
                <span class="error" id="email-error"></span>
                <div class="form-group">
                    <span class="material-symbols-rounded">lock</span>
                    <input type="password" class="form-input" name="password" id="password" placeholder="Password">
                </div>
                <span class="error" id="password-error"></span>
                <input type="submit" name="btnlogin" id="btnlogin" value="Login" class="form-submit">
                <button id="forgot-button" class="form-submit">Forgot</button>
                <button id="signup-button" class="form-submit">Register</button>
                <a class="form-button" href="/AccountController/index">Back</a>
            </form>


            <!--form quên mật khẩu khi bấm vào forgot thì cho nhập email và kiêm tra-->
            <form action="AccountController" id="form-forgot" method="post" style="display: none;">
                <h1 class="form-heading">FORGOT PASSWORD</h1>
                <div class="form-group">
                    <span class="material-symbols-rounded">mail</span>
                    <input type="text" class="form-input" name="emailse" id="emailse" placeholder="Email">
                </div>
                <span class="error" id="email-error-forgot"></span>
                <input type="submit" name="btnforgot" value="Check Email" class="form-submit">
                <button id="back-to-forgot" class="form-submit">Back</button>
            </form>


            <!--form tạo tài khoản mới-->
            <form action="AccountController" method="post" id="form-signup" style="display: none;">

                <h1 class="form-heading">SIGN UP</h1>
                <div class="form-group">
                    <span class="material-symbols-rounded">account_circle</span>
                    <input type="text" class="form-input" name="fullname" id="fullname" placeholder="Username">
                </div>
                <span class="error" id="name-error"></span>
                <div class="form-group">
                    <span class="material-symbols-rounded">home</span>
                    <input type="text" class="form-input" name="address" id="address" placeholder="Address">
                </div>
                <span class="error" id="address-error"></span>
                <div class="form-group">
                    <span class="material-symbols-rounded">phone_in_talk</span>
                    <input type="text" class="form-input" name="phone" id="phone" placeholder="Phone">
                </div>
                <span class="error" id="phone-error"></span>
                <div class="form-group">
                    <span class="material-symbols-rounded">mail</span>
                    <input type="text" class="form-input" name="emails" id="emails" placeholder="Email">
                </div>
                <span class="error" id="emails-error"></span>
                <div class="form-group">
                    <span class="material-symbols-rounded">lock</span>
                    <input type="password" class="form-input" name="passwords" id="passwords" placeholder="Password">
                </div>
                <span class="error" id="passwords-error"></span>
                <input type="submit" name="btnsignup" id="btnsignup" value="SignUp" class="form-submit">
                <button id="back-to-login" class="form-submit">Back</button>
            </form>


        </div>


        <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
        <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
        <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script>
            const loginForm = document.getElementById("form-login");
            const signupForm = document.getElementById("form-signup");
            const forgotForm = document.getElementById("form-forgot");
            const backToLoginButton = document.getElementById("back-to-login");
            const backToForgotButton = document.getElementById("back-to-forgot");

            //nút quay về của form signup
            document.getElementById("back-to-login").addEventListener("click", function (event) {
                event.preventDefault();                //ngăn chặn việc gửi form
                signupForm.style.display = "none";
                forgotForm.style.display = "none";
                loginForm.style.display = "block";
            });
            //nút quay về của form forgot
            document.getElementById("back-to-forgot").addEventListener("click", function (event) {
                event.preventDefault();
                signupForm.style.display = "none";
                forgotForm.style.display = "none";
                loginForm.style.display = "block";
            });

            // chức năng form login
            $(document).ready(function () {
                $("#btnlogin").click(function (event) {
                    event.preventDefault(); // Prevent form submission
                    performAjaxRequest();
                });
                // hiển thị trang forgot
                $("#forgot-button").click(function (event) {
                    loginForm.style.display = "none";
                    signupForm.style.display = "none";
                    forgotForm.style.display = "block";
                    $("#login-error").text(""); // Reset the login error message
                    event.preventDefault(); // Prevent form submission
                });
                // hiển thị form signup
                $("#signup-button").click(function (event) {
                    loginForm.style.display = "none";
                    signupForm.style.display = "block";
                    forgotForm.style.display = "none";
                    $("#login-error").text(""); // Reset the login error message
                    event.preventDefault(); // Prevent form submission
                });
            });
            // hiển thị form thông báo thành công hay thất bại
            function performAjaxRequest() {
                var email = $("#email").val().trim();
                var password = $("#password").val().trim();
                var hasError = false;
                // Check if email is empty or missing '@'
                if (email === "" || email.indexOf('@') === -1) {
                    $("#email-error").text("Please enter a valid email address ex: abc@gmail.com.").css("color", "red");
                    hasError = true;
                } else {
                    $("#email-error").text("");
                }

                // Check if password is empty
                if (password === "") {
                    $("#password-error").text("Please enter password.").css("color", "red");
                    hasError = true;
                } else {
                    $("#password-error").text("");
                }

                // If there is an error, stop further processing
                if (hasError) {
                    return;
                }

                $.ajax({
                    type: "POST",
                    url: "AccountController",
                    data: {btnlogin: "Login", email: email, password: password},
                    success: function (response) {
                        if (response === "SUCCESS") {
                            // Redirect to another page after successful login
                            Swal.fire({
                                title: 'Login Success',
                                text: 'Click OK to switch to the home page ',
                                icon: 'success',
                                confirmButtonText: 'OK'
                            }).then(() => {
                                // Redirect to another page after clicking OK
                                window.location.href = '/AccountController/index'; // Change this to the desired URL
                            });
                        } else {
                            // Display SweetAlert for failure
                            Swal.fire({
                                title: 'Login Failed',
                                text: 'Please check your email and password.',
                                icon: 'error',
                                confirmButtonText: 'OK'
                            });
                        }
                    },
                    error: function () {
                        // Display SweetAlert for error
                        Swal.fire({
                            title: 'System Error',
                            text: 'The system is failing',
                            icon: 'error',
                            confirmButtonText: 'OK'
                        });
                    }
                });
            }








            $(document).ready(function () {
                $("#btnsignup").click(function (event) {
                    event.preventDefault(); // Prevent form submission
                    performAjaxRequestRegister();
                });
            });
            // hiện form thông báo của signup
            function performAjaxRequestRegister() {
                var fullname = $("#fullname").val().trim();
                var address = $("#address").val().trim();
                var phone = $("#phone").val().trim();
                var emails = $("#emails").val().trim();
                var passwords = $("#passwords").val().trim();
                var hasErrors = false;
                if (fullname === "") {
                    $("#name-error").text("Please enter a valid name").css("color", "red");
                    hasErrors = true;
                } else {
                    $("#name-error").text("");
                }
                if (address === "") {
                    $("#address-error").text("Please enter a valid address").css("color", "red");
                    hasErrors = true;
                } else {
                    $("#address-error").text("");
                }
                if (phone === "") {
                    $("#phone-error").text("Please enter a valid phone").css("color", "red");
                    hasErrors = true;
                } else {
                    var phoneNumberPattern = /^0[0-9]{9}$/;
                    if (!phoneNumberPattern.test(phone)) {
                        $("#phone-error").text("Phone number start with 0 and have a length 10").css("color", "red");
                        hasErrors = true;
                    }
                }
                if (emails === "" || emails.indexOf('@') === -1) {
                    $("#emails-error").text("Please enter a valid email address ex: abc@gmail.com.").css("color", "red");
                    hasErrors = true;
                } else {
                    $("#emails-error").text("");
                }

                // Check if password is empty
                if (passwords === "") {
                    $("#passwords-error").text("Please enter password.").css("color", "red");
                    hasErrors = true;
                } else {
                    $("#passwords-error").text("");
                }
                if (hasErrors) {
                    return;
                }

                $.ajax({
                    type: "POST",
                    url: "AccountController",
                    data: {btnsignup: "SignUp", fullname: fullname, address: address, phone: phone, emails: emails, passwords: passwords},
                    success: function (response) {
                        if (response === "REGISTER") {
                            // Redirect to another page after successful login
                            Swal.fire({
                                title: 'Register Success',
                                text: 'Click OK to authenticate the account ',
                                icon: 'success',
                                confirmButtonText: 'OK'
                            }).then(() => {
                                // Redirect to another page after clicking OK
                                window.location.href = '/AccountController/pin'; // Change this to the desired URL
                            });
                        } else if (response === "EXITEMAIL") {
                            // Redirect to another page after successful login
                            Swal.fire({
                                title: 'Email Exist',
                                text: 'Email already exists, please enter another email ',
                                icon: 'error',
                                confirmButtonText: 'OK'
                            });
                        } else if (response === "ERROR") {
                            // Display SweetAlert for failure
                            Swal.fire({
                                title: 'Login Failed',
                                text: 'Your account was not created successfully.Please check the information again',
                                icon: 'error',
                                confirmButtonText: 'OK'
                            });
                        }
                    },
                    error: function () {
                        // Display SweetAlert for error
                        Swal.fire({
                            title: 'System Error',
                            text: 'The system is failing.',
                            icon: 'error',
                            confirmButtonText: 'OK'
                        });
                    }
                });
            }

        </script>
    </body>
</html>
Leave a Comment