Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将登录用户重定向到node.js中的不同页面_Javascript_Angularjs_Node.js_Express_Passport.js - Fatal编程技术网

Javascript 将登录用户重定向到node.js中的不同页面

Javascript 将登录用户重定向到node.js中的不同页面,javascript,angularjs,node.js,express,passport.js,Javascript,Angularjs,Node.js,Express,Passport.js,我有一个应用程序,我可以使用我的注册用户登录。我想根据登录用户的角色(此处为EntityTypes)将其重定向到不同的主页。以下是应用程序的登录控制器,以及node.js代码和登录html。我希望有人能帮助我 login.html- <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Login User</title> </hea

我有一个应用程序,我可以使用我的注册用户登录。我想根据登录用户的角色(此处为EntityTypes)将其重定向到不同的主页。以下是应用程序的登录控制器,以及node.js代码和登录html。我希望有人能帮助我

login.html-

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Login User</title>
</head>

<body>
<div ng-controller="loginCtrl">
    <h1>Login</h1>

<div class="row">
    <div class="col-md-8">
    <section>
        <form role = "form" data-ng-submit = "SendLoginData()" 
class="loginpage">
            <h4>Use a local account to log in</h4>
            {{ PostDataResponse }}
            <br />
            <div class="form-horizontal">
            <div class="form-group">
            <label class="col-md-2 control-label">Email</label>
                <div class="col-md-10">
                    <input type="email" ng-model="email"/>
                </div>
            </div>
            <div class="form-group">
            <label class="col-md-2 control-label">Password</label>
                <div class="col-md-10">
                    <input type="password" ng-model="password" />
                </div>
            </div>
            <div class="form-group">
            <label class="col-md-2 control-label">Remember me?</label>
                <div class="col-md-10">
                    <input type="checkbox" ng-model="checkboxModel.value1"
                        ng-true-value="'YES'" ng-false-value="'NO'">
             <!-- </form> -->
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <button type="submit" class="btn btn-default">Log in</button>
                </div>
            </div>
            <div>

            <p>
                <a href="#/register">Register as a new user?</a>
            </p>
            <p>
                <a href="ForgotPassword">Forgot your password?</a>
            </p>
            </div>
        </form>
    </section>
</div>
<div class="col-md-4">
    <section>
        <h4>Use another service to log in.</h4>

                    <p>
                        Test content here!
                    </p>
                </form>
    </section>
</div>
</div>
</div>
</body>
</html>
index.js-

var PORT = 4569;
var body_parser = require('body-parser');
var express = require('express')
var app = express();
var bigInt = require('big-integer');
var async = require('async');
var bcrypt = require('bcryptjs');
var location = require('location');
var path = require('path');
var http = require('http');
var sql = require('mssql');

app.use(body_parser.urlencoded({extended: true}));
app.use(express.static('public'));
app.use(body_parser.json());
app.set('views', 'app/views');
app.set('view engine', 'ejs');

    var config = {
服务器:'localhost', 数据库:“chico”, 用户:“Soumya”, 密码:“secret”, 港口:1433 };

app.post('/login', function(req, res) {
    console.log(req.body.LoginEmail);
    console.log(req.body.LoginPassword);

    var dbConn = new sql.ConnectionPool(config);
    dbConn.connect().then(function () {
        console.log("I am the error 4");
        var transaction = new sql.Transaction(dbConn);
        console.log("I am the error 5");
        transaction.begin().then(function () {

            var request = new sql.Request(transaction);
            console.log("I am the error 6");

        request.query("select Email,EntityType from dbo.Userregister1 where Email = '"+req.body.LoginEmail+"' and PasswordHash = '"+req.body.LoginPassword+"'", function (err, row) {

            if(err) {
                console.log('Error1');
            } 
            else if (row.rowsAffected[0] == 1) {
                console.log('Error2');
                res.sendStatus(201);
            } else if (row.rowsAffected[0] != 1) {                                              
                console.log('Error3');
                res.sendStatus(399)
            };
        })
    })
});
});   

app.listen(PORT, function () {
  console.log('Server Started. You can access the editor from http://localhost:' + PORT)
})

在服务器上,如果您有办法检测登录的用户类型(在错误检测块之后的代码中),您可以执行以下操作:

if(row.data['userType'] === "admin") {
    res.redirect("/adminPanel");
}
else if(row.data['userType'] === "editor") {
    res.redirect("/editorPanel");
}
对于你可能在应用程序中扮演的任何角色,你都会这样做。我不能100%确定关于row.data的语法,因为我不使用MSSQL,但它似乎应该与之相近

if(row.data['userType'] === "admin") {
    res.redirect("/adminPanel");
}
else if(row.data['userType'] === "editor") {
    res.redirect("/editorPanel");
}