如何创建ionic-v1登录

时间:2017-12-28 09:15:37

标签: javascript mysql node.js mobile ionic-v1

我是离子骨架的新手。我试图使用mysql数据库创建登录,但不知道该怎么做。

控制器:



app.controller('loginuserCtrl', function($scope, UserService, $state) {
    $scope.user = {};
 
    $scope.login = function() {
        UserService.getLogin($scope.user.username,$scope.user.password).success(function(response) {
            $state.go('profile');
        
            var data = response.data;

            switch (data.code) {
                case '00':
                    $scope.$broadcast('scroll.refreshComplete');
                    break;
                case '99':
                    break;
            }
        }) 
    };
});

<ion-view view-title="Login" name="loginUser">
  <ion-content class="padding">
     
      <div class="list list-inset">
          <label class="item item-input">
              <input type="text" placeholder="Username" ng-model="user.username">
          </label>
          <label class="item item-input">
              <input type="password" placeholder="Password" ng-model="user.password">
          </label>
      </div>
      <button class="button button-block button-calm" ng-click="login()">Login</button>
      
  </ion-content>
</ion-view>
&#13;
&#13;
&#13;

service.js:

&#13;
&#13;
var app = angular.module('services', []);

app.service('UserService', function ($http, config) {
    return {
        getLogin: function (saveObj) {
            return $http.get(config.serverIp + 'Login',saveObj);
        }
      };
});
&#13;
&#13;
&#13;

server.js

&#13;
&#13;
//select user login
app.get('/Login', function (req, res) {
    var query = req.query;

var sql = "SELECT * FROM sys_user WHERE usr_id = '" + query.usr_id + "'and usr_identno = '" + query.usr_identno + "'";

    connection.query(sql, function (err, rows, field) {
        if (!err) {
            res.json({code: '00', content: rows});
        } else {
            throw err;
        }
    });
});
&#13;
&#13;
&#13;

0 个答案:

没有答案