gpt4 book ai didi

javascript - 如何使用 Mean.io 堆栈通过 Node 进行登录

转载 作者:行者123 更新时间:2023-12-02 14:38:42 27 4
gpt4 key购买 nike

我正在使用 stack MEAN.io 开发一个 web 应用程序,现在我已经得到了包含 HTML、CSS 和 AngularJS 的前端部分,其中包含一些逻辑。但现在我想在服务器端登录,我不知道从哪里开始,因为例如 AngularJS 它有一个定义路由的文件,它将使用什么模板以及哪个 Controller ,但是 Express/呢? Node 部分?

我如何实现这个新的登录?我有点迷失了。

Server folders

我想对注册用户进行一些“管理”,以便他们可以添加最喜欢的个人资料。就像在屏幕右侧添加一个书签一样。但我想在服务器端执行此操作。

问题是我找不到在哪里编写服务器端代码,并且这与前端的同一文件相关。

例如,当我在索引页面时,我想显示我之前添加的收藏夹配置文件。当然也存储到 MongoDB 中。

最佳答案

您有两种选择,使用常规表单来发布数据或使用 $http Angular ajax 发布。

regular form kind of posting data to server

<form action="/" method="post">
<input type"email" name="email" />
<input type"password" name="password" />
<input type="submit" value="login" />
</form>

posting data using ajax angular $http method

<form >
<input type"email" ng-model="user.email" />
<input type"password" ng-model="user.password" />
<button ng-click="login">login</button>
</form>

$scope.user = {};
$scope.login= function () {
$http({
url: 'http://localhost:3000/',
method: 'POST',
data: {
email: user.email,
password:user.password
}
});
});

server side

router.post('/', function (req, res, next) {
console.log(req.body);
//custom authentication or use passport.js
});

关于javascript - 如何使用 Mean.io 堆栈通过 Node 进行登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37216050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com