简体   繁体   English

Parse.com未登录用户

[英]Parse.com Not logging In User

I made a login system using Parse.com as a back end and for the life of me I can't figure out why this will not work with the code I have. 我使用Parse.com作为后端创建了一个登录系统,对于我一生来说,我无法弄清楚为什么这不适用于我拥有的代码。 When the user enters their UserID and password it is supposed to check the parse database and, if found, log them in based upon which role they have. 当用户输入其用户ID和密码时,应该检查解析数据库,如果找到该数据库,则根据其角色登录。 (Send them to menu1, menu2, or menu3 basically). (将它们基本上发送到menu1,menu2或menu3)。 If it can't find them it is supposed to create an alert saying "Username of Password Incorrect" and clear the form. 如果找不到它们,则应该创建一个警告,提示“密码错误的用户名”并清除表格。

If you click on the 'Sign In' button as of now it doesn't do anything 如果您现在点击“登录”按钮,它什么都不会做

The create_account.html successully registers a User in the Parse database with a username and password so I know it connects....I just can't log them in. create_account.html已使用用户名和密码成功在Parse数据库中注册了一个用户,因此我知道它已连接....我只是无法登录。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!--Bootstrap-->
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <!--Parse-->
        <script type="text/javascript" src="http://www.parsecdn.com/js/parse-latest.js"></script>
        <script src="//www.parsecdn.com/js/parse-1.6.7.min.js"></script>
        <!--Javascript-->
        <!--Stylesheet-->
        <link rel="stylesheet" type="text/css" href="css/login.css">
        <title>index.html</title>
    </head>

    <body>
        <div class="container">             
            <div class="row">
                <div class="col-xs-12">
                    <h1>Study App</h1>
                    <h2>Please Sign In</h2>
                    <form class="form-signin">
                        <div class="form-group">
                            <input type="text" class="form-control" id="userID" placeholder="User ID">
                        </div> <!--end User ID-->       
                        <div class="form-group">
                            <input type="password" class="form-control" id="password" placeholder="Password">
                        </div> <!--end Password-->
                            <a href="urltt">Forgot Password?</a> <!--Not implemented yet-->
                        <button type="button" class="btn btn-lg btn-block btn-primary">Sign In</button>
                    </form> <!--end SIGN IN FORM-->
                </div> <!--END COLUMN-->
            </div> <!--END ROW-->


            <div class="row">
                <div class="col-xs-12">
                    <div id="add_User">
                        <img src="img/add_user.png" alt="Add User Icon" height="42" width="42">
                        <p><a href="create_account.html">Create Account</a></p>
                    </div>
                </div> <!--END COLUMN-->
            </div> <!--END ROW-->       

        </div> <!--end container-->
        <script src="js/login.js"></script>
    </body>
</html>

login.js login.js

    $(function() 
{
   Parse.$ = jQuery;
   Parse.initialize("x", "y"); <!--Removed for security-->
});


$('.form-signin').on('submit', function(e) 
{ 
    e.preventDefault();
    var data = $(this).serializeArray(),userID = data[0].value,password = data[1].value;        

    Parse.User.logIn(username, password, {
        success: function (user) {
            var queryRole = new Parse.Query(Parse.Role);
            if(queryRole.equalTo('name', 'Student')) {
                window.location = "menu1.html"
            }
            else if (queryRole.equalTo('name', 'Tutor')) {
                window.location = "menu2.html"
            }
            else {
                window.location = "professor/professor-menu3.html"
            }
        },
        // If there is an error
        error: function (user, error) {
            console.log(error);
            alert("Username or Password incorrect");
            $(".form-signin")[0].reset();
        }
    });

});

You set userID and password : 您设置userIDpassword

var data = $(this).serializeArray(),userID = data[0].value,password = data[1].value;

then you use username and password : 然后您使用usernamepassword

Parse.User.logIn(username, password, {

Also, the way you get the userID and password seems a bit dangerous to me, if you ever add other fields in your form before those it'll break. 另外,如果您曾经在表单中添加其他字段,那么获取userIDpassword的方式对我来说似乎有点危险。

I would recommend you to switch to: 我建议您切换到:

var username = $('#userID').val();
var password = $('#password').val();

instead. 代替。

Also, you don't have a submit button in your form. 另外,您的表单中没有提交按钮。 Change: 更改:

<button type="button" class="btn btn-lg btn-block btn-primary">Sign In</button>

to: 至:

<button type="submit" class="btn btn-lg btn-block btn-primary">Sign In</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM