Example #1
0
def authorized(access_token):
    session['token'] = access_token
    if access_token:
        user_data = github.get('user')
        user = User.query.filter_by(username=user_data['login']).first()

        # retreive key from github account
        try:
            key = requests.get('https://github.com/%s.keys'
                               % user_data['login'])
            key.raise_for_status()
            pubkey_ = str((key.text))
        except requests.exceptions.HTTPError:
            logging.exception('Failed to retrieve key from Github')

        if user is None:
            user = User()
            db.session.add(user)
            user.username = user_data['login']
            user.token = access_token
            user.email = user_data['email']
            user.name = user_data['name']
            user.pubkey = pubkey_
            db.session.commit()
        else:
            user.token = access_token
            user.pubkey = pubkey_
            db.session.commit()
        return redirect('/dashboard')
Example #2
0
 def wrap(*args, **kwargs):
     orgs = github.get('user/orgs')
     for org_ in orgs:
         if org_['login'] == org:
             return func(*args, **kwargs)
         return jsonify({"response": "You must be the member of gluster \
                    organization on Github to serve yourself machines for testing"}), 401
Example #3
0
 def wrap(*args, **kwargs):
     if g.user is None:
         return redirect(url_for('login', next=request.url))
     orgs = github.get('user/orgs')
     for org_ in orgs:
         if org_['login'] == org:
             return func(*args, **kwargs)
     return jsonify({
         "response": "You must be the member of gluster"
                     " organization on Github to serve"
                     " yourself machines"
                     " for testing"}), 401
Example #4
0
def authorized(access_token):
    session['token'] = access_token
    if access_token:
        user_data = github.get('user')
        user = User.query.filter_by(username=user_data['login']).first()

        if user is None:
            user = User()
            db.session.add(user)
            user.username = user_data['login']
            user.token = access_token
            user.email = user_data['email']
            user.name = user_data['name']
            db.session.commit()
        else:
            user.token = access_token
            db.session.commit()
        return redirect('/dashboard')