コード例 #1
0
ファイル: views.py プロジェクト: jerkos/kepavi
def twitter_authorized():
    next_url = request.args.get('next') or url_for('softwares.index')
    resp = twitter.authorized_response()
    if resp is None:
        flash('Twitter login failed !', 'danger')
        return redirect(url_for('softwares.index'))

    user = User.query.filter(User.username == resp['screen_name']).first()
    if user is None:
        user = User.create_from_twitter_oauth(resp)

    login_user(user, True)
    flash("Twitter login succeeded.", "success")
    return redirect(next_url)
コード例 #2
0
ファイル: manage.py プロジェクト: jerkos/kepavi
def initdb():
    """Creates the database."""
    db.create_all()

    logging.info('Getting kegg organism list...')
    kegg_list = Kegg.get_org_list()

    # use only get memory error otherwise
    # print BiomodelMongo.objects.only('organism', 'name').all()
    mongo_list = dict(
        (b.organism, b.name)
        for b in BiomodelMongo.objects.only('organism', 'name').all()
        )

    mongo_orgs = set(mongo_list.keys())

    # to prevent insertion porting the same name
    kegg_names = set()

    logging.info('Insertion begins...')
    d = csv.DictReader(kegg_list.split('\n'), delimiter='\t', fieldnames=('code', 'org', 'tax'))
    for row in d:
        code, org, tax = row['code'], row['org'], row['tax']
        if org in mongo_orgs:
            if tax not in kegg_names:
                o = Organism(row['code'], row['org'], row['tax'])
                o.save()
                b = Biomodel(name=tax, kegg_org=org)
                b.save()
                # finally tax to the set
                kegg_names.add(tax)

    # insert user
    u = User(username='******', email='*****@*****.**', password='******')
    u.save()

    logging.info('Done !')
コード例 #3
0
ファイル: views.py プロジェクト: jerkos/kepavi
def authorized(oauth_token):
    next_url = request.args.get('next') or url_for('softwares.index')
    if oauth_token is None:
        flash("Authorization failed.", "danger")
        return redirect(url_for('auth.login'))

    user = User.query.filter_by(github_access_token=oauth_token).first()
    if user is None:
        user = User.create_github_account(oauth_token)

    # session.pop('nb_views', None)
    # force remembering
    login_user(user, True)
    flash("Github login succeeded.", "success")

    return redirect(next_url)
コード例 #4
0
ファイル: views.py プロジェクト: jerkos/kepavi
def login():
    """
    Logs the user in
    """

    if current_user is not None and current_user.is_authenticated():
        return redirect(url_for("user.profile", username=current_user.username))

    form = LoginForm(request.form)
    if form.validate_on_submit():
        user, authenticated = User.authenticate(form.login.data,
                                                form.password.data)
        if user and authenticated:
            # remove this key when a user is authenticated
            # session.pop('nb_views', None)
            login_user(user, remember=form.remember_me.data)
            flash("Welcome onboard {} !".format(user.username), "success")
            return redirect(request.args.get("next") or url_for("user.profile", username=user.username))

        flash("Wrong username or password", "danger")
    return render_template("auth/login.html", form=form)