gpt4 book ai didi

javascript - 具有 Sails.js 后端的 Ionic 应用程序的 $http 身份验证

转载 作者:行者123 更新时间:2023-11-28 00:05:37 25 4
gpt4 key购买 nike

我有一个移动应用程序:

前端 - Ionic 框架

后端 - Sails.js API

我需要帮助来设置 Ionic 应用程序,并为以下内容创建注册和登录流程:

  1. 用户名/密码注册及登录

  2. 使用用户 Controller 设置 Sails.js 后端

  3. 将它们捆绑在一起,以便用户可以创建帐户并登录。

有人能给我指出正确的方向吗?非常感谢任何帮助。谢谢

最佳答案

这是我的登录模板

<script id="templates/sign-in.html" type="text/ng-template">
< ion - view > < div class = "bar bar-header bar-positive" > < h1 class = "title" > Sign - In < /h1>
</div > < ion - content style = "margin-top:40px !important" > < div class = "list list-inset" > < label id = "acc"
class = "item item-input" > < input type = "text"
ng - model = "user.account"
placeholder = "Account" > < /label>
<label id="user" class="item item-input">
<input type="text" ng-model="user.user" placeholder="Username">
</label >

< label id = "pass"
class = "item item-input" > < input type = "password"
ng - model = "user.password"
placeholder = "Password" > < /label>
</div > < div class = "padding" > < button class = "button button-block button-positive"
ng - click = "signIn(user)" >
Sign - In < /button>
</div > < div id = "error"
style = "color:#a94442;"
class = "item item-divider" >

< /div>
</ion - content > < /ion-view>
</script>

在 ng-click 调用中,我有以下函数可以调用

$scope.signIn = function signIn(user) {
if (user) {
var ath = user.account + ',' + user.user + ',' + user.password;
var url = "http://youradress.com/you";
var config = {
headers: {
'Credentials': ath
}
};
$http.get(url, config).success(function (data, status, headers, config) {
if (data.indexOf("Permission") > -1) {
$state.go('devices-list')
} else {
error = document.getElementById("error");
error.innerHTML = "Unable to logged in! Check Credentials";
}
}).error(function (data, status, headers, config) {
error = document.getElementById("error");
error.innerHTML = "Unable to logged in! Check Internet"
});
}
}

关于javascript - 具有 Sails.js 后端的 Ionic 应用程序的 $http 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31365627/

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