Ejemplo n.º 1
0
def after_login(**user_fields):
    import re

    if request.method == "POST":
        user_fields = {k: v for k, v in request.form.items() if v is not None}
    else:
        user_fields = {k: v for k, v in user_fields.items() if v is not None}

    print(request.host)

    if "google_id" in user_fields:
        user = User.query.filter_by(google_id=user_fields["google_id"]).first()
    elif "twitter_id" in user_fields:
        user = User.query.filter_by(
            twitter_id=user_fields["twitter_id"]).first()
    elif "facebook_id" in user_fields:
        user = User.query.filter_by(
            facebook_id=user_fields["facebook_id"]).first()
    elif None is not re.match(r'^(localhost|127.0.0.1)', request.host):
        user = User(id=1)

    if user is None:

        nickname = user_fields[
            "nickname"] if "nickname" in user_fields else None
        if nickname is None or nickname == "":
            nickname = user_fields["email"].split('@')[0]
        nickname = User.make_unique_nickname(nickname)
        user_fields["nickname"] = nickname
        user_fields["agree_mailer"] = 1
        user = User(**user_fields)
        db.session.add(user)
        db.session.commit()

    remember_me = False
    if 'remember_me' in session:
        remember_me = session['remember_me']
        session.pop('remember_me', None)
    login_user(user, remember=remember_me)

    return render_template('account/complete_login.html')
Ejemplo n.º 2
0
def after_login(**user_fields):
    
    if request.method == "POST":
        user_fields = {k:v for k,v in request.form.items() if v is not None}
    else:
        user_fields = {k:v for k,v in user_fields.items() if v is not None}
    
    if "google_id" in user_fields:
        user = User.query.filter_by(google_id = user_fields["google_id"]).first()
    elif "twitter_id" in user_fields:
        user = User.query.filter_by(twitter_id = user_fields["twitter_id"]).first()
    elif "facebook_id" in user_fields:
        user = User.query.filter_by(facebook_id = user_fields["facebook_id"]).first()
        
    if user is None:
            
        # if request.remote_addr != SITE_MIRROR.split(":")[1][2:]:
        #     form_json = user_fields
        #     try:
        #         opener = urllib2.urlopen("{0}account/complete_login/".format(SITE_MIRROR),urllib.urlencode(form_json),5)
        #     except:
        #         flash(gettext("The server is not responding. Please try again later."))
        #         return render_template('account/complete_login.html')
        
        nickname = user_fields["nickname"] if "nickname" in user_fields else None
        if nickname is None or nickname == "":
            nickname = user_fields["email"].split('@')[0]
        nickname = User.make_unique_nickname(nickname)
        user_fields["nickname"] = nickname
        user = User(**user_fields)
        db.session.add(user)
        db.session.commit()
        
    # if request.remote_addr == SITE_MIRROR.split(":")[1][2:]:
    #     return jsonify({"success": 1})
    # else:
    remember_me = False
    if 'remember_me' in session:
        remember_me = session['remember_me']
        session.pop('remember_me', None)
    login_user(user, remember = remember_me)

    return render_template('account/complete_login.html')
Ejemplo n.º 3
0
def after_login(**user_fields):
    import re

    if request.method == "POST":
        user_fields = {k: v for k, v in request.form.items() if v is not None}
    else:
        user_fields = {k: v for k, v in user_fields.items() if v is not None}

    print(request.host)

    if "google_id" in user_fields:
        user = User.query.filter_by(google_id=user_fields["google_id"]).first()
    elif "twitter_id" in user_fields:
        user = User.query.filter_by(
            twitter_id=user_fields["twitter_id"]).first()
    elif "facebook_id" in user_fields:
        user = User.query.filter_by(
            facebook_id=user_fields["facebook_id"]).first()
    elif None is not re.match(r'^(localhost|127.0.0.1)', request.host):
        user = User(id=1)

    if user is None:

        nickname = user_fields[
            "nickname"] if "nickname" in user_fields else None
        if nickname is None or nickname == "":
            nickname = user_fields["email"].split('@')[0]
        nickname = User.make_unique_nickname(nickname)
        user_fields["nickname"] = nickname
        user_fields["agree_mailer"] = 1
        user = User(**user_fields)
        db.session.add(user)
        db.session.commit()

    remember_me = False
    if 'remember_me' in session:
        remember_me = session['remember_me']
        session.pop('remember_me', None)
    login_user(user, remember=remember_me)

    return render_template('account/complete_login.html')