2 回答
TA贡献1883条经验 获得超3个赞
正如我在评论中所说,您拥有所需的一切(大部分情况下),您只需要添加“角色”......
你可以用很多方法来做到这一点(通常我会查看我正在使用的选项并决定特定项目的最佳方法 - 我通常最终使用 CLASS 而不是 ID - 个人偏好并取决于所有参与了)。在你的情况下,我遵循了你的代码风格(这很好,虽然有更短的方法来做事...... - 你会随着时间的推移学习!)
因此,仅重用 D-skinner.html 的主体(其余代码不影响这一点),您将得到类似的东西:
<body>
<div id="Folder1" style="visibility:hidden;">
<p>stuff for Folder 1</p>
</div>
<div id="Folder2" style="visibility:hidden;">
<p>stuff for Folder 2</p>
</div>
<div id="Folder3" style="visibility:hidden;">
<p>stuff for Folder 3</p>
</div>
<div id="AdminConsole" style="visibility:hidden;">
<p>stuff for Admin Console</p>
</div>
<div id="Logged_Out">
<h1>Please Login to D-Skinner Portal</h1>
<p>We understand that you want access to Portal, but we need your username and password, otherwise we can't let you in, sorry!</p>
<p>An alert has been sent to the D-Skinner team to alert them of this incident (just in case this was an accident), we will continue to monitor this IP Address and MAC Address for 1 hour to make sure that this isn't an attack.</p>
</div>
<div id="Logged_In">
<h1>D-Skinner - Portal</h1>
<p>We appreciate your beta testing, your login has been successful, please check with your beta co-ordinator to complete your beta.</p>
</div>
<script>
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// you already know this, but here is a great way to test this
console.log("user is now ", user);
// now in your console (differs by browser - internet search to see how to open yours) you will see the user info in an object.
// If user is logged in
var displayName = user.displayName;
var email = user.email;
var emailVerified = user.emailVerified;
// here you can verify everything if you like.....
console.log("displayName is ", displayName);
// I'll only include this one -you can do others as needed
document.getElementById("Logged_In").style.visibility = "show"
// HERE YOU TEST AND DO 'ROLE' THINGS (same as you did 'user'...)
// you did not include any way you are determining which role so I have to guess from the data you did provide.....
if(displayName === 'Person A'){
console.log("displayName ", displayName, " MATCHED here");
// you can do all the 'what they can see' here
// (there are easier and better ways, but this is simple and follows your style of coding)
document.getElementById("Folder1").style.visibility = "show";
document.getElementById("Folder2").style.visibility = "show";
document.getElementById("AdminConsole").style.visibility = "show";
}
if(displayName === 'Person B'){
console.log("displayName ", displayName, " MATCHED here");
// you can do all the 'what they can see' here
document.getElementById("Folder3").style.visibility = "show";
// etc
}
} else {
console.log(" NO USER - showing Logged_Out div"); document.getElementById("Logged_Out").style.visibility = "show"
}
});
</script>
</body>
同样,您有基本概念 - 您只需要通过角色来完成它(并且由于您从未包括如何分配用户和角色,您将需要修改上面的示例以适应您正在做的事情)。
TA贡献2011条经验 获得超2个赞
我假设您知道每个人都可以访问您的隐藏信息。
如果这不是什么秘密,那么您最好进行客户端实施。但是,如果它是某种敏感数据,您将在服务器端实现所有安全和过滤。
所以我会在服务器上放置授权和用户验证。前端只会呈现来自服务器的信息。
添加回答
举报