带有Sails.js后端的Ionic App的$ http身份验证

时间:2015-07-12 07:49:16

标签: javascript ionic-framework sails.js ionic

我有一个移动应用程序:

前端 - 离子框架

后端 - Sails.js API

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

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

  2. 使用用户控制器

  3. 设置Sails.js后端
  4. 将它们绑在一起,以便用户可以创建帐户并登录。

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

1 个答案:

答案 0 :(得分:1)

这是我的登录模板

<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"
    });
  }
 }