Giter VIP home page Giter VIP logo

building-a-blog-using-flask-and-angularjs's People

Contributors

johnnncodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

building-a-blog-using-flask-and-angularjs's Issues

restangular request has problem

Blog.service('AuthService', function($q, $http, localStorageService, Session, Restangular) {

    this.login = function(credentials) {
        var me = this;
        deferred = $q.defer()
        Session.create(credentials, true).then(function(user) {
            me.setToken(credentials);
            return deferred.resolve(user);
        }, function(response) {
            if (response.status == 401) {
                return deferred.reject(false);
            }
            throw new Error('No handler for status code ' + response.status);
        });
        return deferred.promise
    };

    this.login1 = function(data){
        var me = this;
        deferred = $q.defer();
        $http({method: 'POST', url: 'sessions', data: data}).
        success(function(data, status, headers, config){
        deferred.resolve(data);
        }).
        error(function() {
            deferred.reject('1')
        });
        return deferred.promise;
    };

});

When controller use AuthService.login,then it will send two request.

For example:
This is no problem

POST /sessions HTTP/1.1
Host: 192.168.101.56:5000
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: application/json, text/plain, /
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json;charset=utf-8
Referer: http://192.168.101.166:8888/
Content-Length: 28
Origin: http://192.168.101.166:8888
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

This is problem

OPTIONS /sessions HTTP/1.1
Host: 192.168.101.56:5000
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Origin: http://192.168.101.166:8888
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

But, controller use AuthService.login1,then it will send one request,It's no problem.

Maybe,This problem because my view and controller is wrong,

This is my login view.

<form ng-submit="submit(username,password)"id="form-signin" class="form-signin" method="post">

    <section>
            <div class="input-group">
              <input type="text" class="form-control" ng-model='username' name="username" placeholder="Username">
              <div class="input-group-addon"><i class="fa fa-user"></i></div>
            </div>
            <div class="input-group">
              <input type="password" class="form-control" ng-model='password' name="password" placeholder="Password">
              <div class="input-group-addon"><i class="fa fa-key"></i></div>
            </div>
          </section>
          <section class="controls">
            <div class="checkbox check-transparent">
              <input type="checkbox" value="1" id="remember" name="remember" checked>
              <label for="remember">remember password</label>
            </div>
            <a href="#">forget password?</a>
          </section>
          <section class="log-in">
            <button type="submit" class="btn btn-greensea">login</button>
            <span>or</span>
            <a href="/registry" class="btn btn-slategray">register</a>
          </section>

</form>

This is my SessionCreateCtrl

Blog.controller('SessionCreateCtrl', function($scope, $location, Session, AuthService) {
    $scope.submit = function(user, passwd) {

        credentials={"email":user,"password":passwd}

        AuthService.login(credentials).then(function(user) {
            $location.path('/posts/create')
        }, function(response) {
            $scope.failedLoginAttempt = true;
        });
    }
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.