示例#1
0
def authorized(auth):
    resp = {}
    success = 0
    if auth == 'github':
        resp = github.authorized_response()
        if resp is None:
            flash('You denied the request to sign in.')
            return redirect(request.args.get('next') or url_for('main.index'))
        session['github_token'] = (resp['access_token'], '')
        success = 1
    if success == 1:
        me = github.get('user')
        user = User.query.filter_by(email=me.data['email']).first()
        if user is None:
            user = User(email=me.data['email'],
                        username=me.data['login'],
                        password=resp['access_token'],
                        confirmed=True)
            db.session.add(user)
            db.session.commit()
            default_notebook = Notebook(title='Default', author_id=user.id)
            db.session.add(default_notebook)
            db.session.commit()
        elif user is not None:
            user.confirmed = True
            db.session.commit()
            login_user(user)
        return redirect(request.args.get('next') or url_for('main.index'))
示例#2
0
def authorized(auth):
    resp={}
    success=0
    if auth == 'github':
        resp = github.authorized_response()
        if resp is None: 
            flash('You denied the request to sign in.')
            return redirect(request.args.get('next') or url_for('main.index'))
        session['github_token'] = (resp['access_token'], '')
        success=1
    if success == 1:
        me = github.get('user')
        user = User.query.filter_by(email=me.data['email']).first()
        if user is None:
            user = User(
                email=me.data['email'],
                username=me.data['login'],
                password=resp['access_token'],
                confirmed=True)
            db.session.add(user)
            db.session.commit()
            default_notebook = Notebook(
                title='Default', author_id=user.id)
            db.session.add(default_notebook)
            db.session.commit()
        elif user is not None:
            user.confirmed=True
            db.session.commit()
            login_user(user)
        return redirect(request.args.get('next') or url_for('main.index'))
示例#3
0
def authorized(auth):
    resp = {}
    success = 0
    if auth == 'github':
        resp = github.authorized_response()
        if resp is None:
            flash('You denied the request to sign in.')
            return redirect(request.args.get('next') or url_for('main.index'))
        session['github_token'] = (resp['access_token'], '')
        success = 1
    if success == 1:
        me = github.get('user')
        user = Query(User).equal_to('email', me.data['email']).find()
        if not user:
            user = User.register(me.data['email'], me.data['login'],
                                 resp['access_token'])
            Notebook.create_default_notebook(user.id)
        else:
            user = user[0]
        login_user(user)
        return redirect(request.args.get('next') or url_for('main.index'))
示例#4
0
 def authorized_response(self):
     return github.authorized_response()