Exemplo n.º 1
0
    def authorized(self, resp):
        next_url = request.args.get('next') or url_for('general.index')
        if resp is None:
            flash(u'You denied the request to sign in.')
            return False, next_url

        session['oauth_method'] = self.method

        username = self.get_user_info(resp)

        u = User.objects(userid=username, method=self.method).first()
        if u == None:
            User(token=session['oauth_token'], userid=username, method=self.method).save()
        else:
            u.token = session['oauth_token'][0]
            u.save()
        login_user(u)

        session['oauth_id'] = username
        identity_changed.send(current_app._get_current_object(), identity=Identity(username))

        return redirect(next_url)
Exemplo n.º 2
0
def load_user(userid):
    from SwaRoute.swa_route.database import User
    return User.objects(userid=userid).first()