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

标签 javascript sails.js ionic-framework

我有一个移动应用程序:

前端 - 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/

相关文章:

javascript - 将多个路径点添加到 Leaflet 时出错

javascript - 通过一个 javascript 文件引导 AngularJS javascript 文件

node.js - 具有版本化数据和差异端点的 REST API : optimizing bandwidth and performance

sails.js - 如何在pm2的生产环境中运行Sails(sails lift --prod)

ionic-framework - 在 Ionic 中显示预先格式化的 HTML 内容

ios - <输入类型 ="file"选择文件后重新启动 Ionic 应用程序

javascript - 如何在 v 4.3.1 中使用 FullCalendar resourcesTimeGridDay?

javascript - 使用 javascript 添加 <use> 标签

javascript - D3.js 在两条路径之间添加截取点和区域

node.js - Node JS 异步.并行