简体   繁体   English

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

[英]$http Authentication for an Ionic App with a Sails.js backend

I have a mobile application: 我有一个移动应用程序:

Front end - Ionic framework 前端-离子框架

Back-end - Sails.js API 后端-Sails.js API

I need help to setup the Ionic application, and create a registration and login flow for: 我需要帮助来设置Ionic应用程序,并为以下内容创建注册和登录流程:

  1. Username / Password registration & login 用户名/密码注册和登录

  2. Setup the Sails.js backend with the User controller 使用用户控制器设置Sails.js后端

  3. Tie them together so that users can create accounts and login. 将它们绑在一起,以便用户可以创建帐户并登录。

Could anyone point me in the right direction. 谁能指出我正确的方向。 Any help is highly appreciated. 非常感谢您的帮助。 Thanks 谢谢

This is my sign-in template 这是我的登录模板

<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>

On ng-click call i have the following function to call 在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"
    });
  }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM