Example #1
0
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    username, email = oauth.callback()
    if email is None:
        # I need a valid email address for my user identification
        flash('Authentication failed.')
        return redirect(url_for('index'))
    # Look if the user already exists
    user = User.query.filter_by(email=email).first()
    if not user:
        # Create the user. Try and use their name returned by Google,
        # but if it is not set, split the email address at the @.
        nickname = username
        if nickname is None or nickname == "":
            nickname = email.split('@')[0]

        # We can do more work here to ensure a unique nickname, if you
        # require that.
        user = User(nickname=nickname, email=email)
        db.session.add(user)
        db.session.commit()
    # Log in the user, by default remembering them for their next visit
    # unless they log out.
    login_user(user, remember=True)
    return redirect(url_for('index'))
Example #2
0
def create_deck():
    data = request.form
    deck_name = data["deckName"]
    if not current_user.add_deck(deck_name):
        return redirect('/')
    flash("Deck " + deck_name+" created!","info")
    return redirect('/')
Example #3
0
def topics(operation=None, topic_id=-1):
    form = NewTopicForm(request.form)

    if request.method == 'POST' and form.validate_on_submit():
        topic = Topic(name=form.topic.data)
        db.session.add(topic)
        db.session.commit()
        flash('New topic is created')
        return redirect(url_for('topics'))
    if operation == 'delete':
        try:
            topic = Topic().query.get(topic_id)
            db.session.delete(topic)
            db.session.commit()
        except:
            flash("Failed to delete topic {}.".format(topic_id))
        return redirect(url_for('topics'))
    if operation == 'update':
        try:
            topic = Topic().query.get(topic_id)
            topic.name = request.values.get("value")
            db.session.add(topic)
            db.session.commit()
        except:
            return 'Error renaming topic.', 400
        else:
            return 'Topic updted successfuly.', 200

    topics = Topic().query.all()
    return render_template('topics.html',
                           title='Topics',
                           form=form,
                           topics=topics)
Example #4
0
    def request_detail_view(self, id):
        unapproved_user = User.query.filter(User.approved == False,
                                            User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        msg_body = render_template('email/request_detail.txt',
                                   user=unapproved_user)
        html_msg = render_template('email/request_detail.html',
                                   user=unapproved_user)

        msg_subject = u"Ufak bir rica!"
        msg = MailMessage(body=msg_body,
                          html=html_msg,
                          subject=msg_subject,
                          sender=(u"Eşya Kütüphanesi",
                                  "*****@*****.**"),
                          recipients=[unapproved_user.email])

        mail.send(msg)
        flash(
            u"Kullanıcıya e-posta gönderilerek daha fazla bilgi vermesi talep edildi!"
        )
        return redirect(url_for('.index_view'))
Example #5
0
def remove_card_from_deck(user_name,deck_name,card_id):
    if current_user.get_id() != user_name:
        abort(500)
    c = card.get_by_id(card_id)
    c.remove_from_deck(deck_name)
    c.remove_from_sidedeck(deck_name)
    return redirect('/'+user_name+'/deck/'+deck_name)
Example #6
0
def edit_question(question_id=-1):
    form = NewQuestionForm(request.form)
    #answerzip = zip(form.answers, form.validities)
    answers = []
    if request.method == 'POST' and form.validate_on_submit():
        for answer in form.answers:
            answers.append(
                Answer(text=answer.answer.data,
                       is_correct=answer.is_correct.data))

        question = Question.query.get(question_id)
        question.text = form.question.data
        Answer.query.filter(Answer.question_id == question.id).delete()
        question.answers = answers
        db.session.add(question)
        db.session.commit()

        return redirect(url_for('topic_questions', topic_id=question.topic.id))

    question = Question.query.get(question_id)
    for i in range(2):
        form.answers.pop_entry()

    form.question.data = question.text
    for answer in question.answers:
        answer_form = AnswerForm()
        answer_form.answer = answer.text
        answer_form.is_correct = answer.is_correct
        form.answers.append_entry(answer_form)

    return render_template('question.html', title='New Question', form=form)
Example #7
0
def edit_resume(resume_id):
    resume = Resume.query.filter_by(id=resume_id, user=current_user).first()
    if not resume:
        abort(404)

    for field, value in request.form.iteritems():
        print field, value
        print type(field), type(value)
        if field == 'default':
            if value == 'True':
                resume.default = True
                resumes = Resume.query.filter_by(user=current_user).all()
                for r in resumes:
                    if r.id != resume_id:
                        r.default = False
                        db.session.add(r)
            else:
                resume.default = False

        if field == 'title':
            # TODO: error checking!!! What if title is blank or all whitespace?
            resume.title = value

    db.session.add(resume)
    db.session.commit()

    if request.args.get('api'):
        return jsonify(response='OK')
    else:
        return redirect(url_for("resumes"))
Example #8
0
def index():
    if login.current_user.is_authenticated():
        return login.redirect('/dashboard')

    # Create the forms
    sign_up_form = forms.SignUpForm()
    sign_in_form = forms.SignInForm()

    if flask.request.method == 'POST' and sign_up_form.validate_on_submit():
        new_user = models.User(
           first_name=sign_up_form.first_name.data,
           last_name=sign_up_form.last_name.data,
           email=sign_up_form.email.data,
           password=bcrypt.generate_password_hash(sign_up_form.password.data),
        )

        db.session.add(new_user)
        db.session.commit()

        return flask.redirect(flask.url_for('dashboard'))

    if flask.request.method == 'POST' and sign_in_form.validate_on_submit():
        user = models.User.query.filter(
            models.User.email == sign_in_form.user_email.data).first()
        login.login_user(user)
        if (bcrypt.check_password_hash(user.password,
                sign_in_form.user_password.data)):
            return flask.redirect(flask.url_for('dashboard'))

    return flask.render_template('home.epy', sign_up_form=sign_up_form,
        sign_in_form=sign_in_form, user=login.current_user)
Example #9
0
def delete_question(question_id=-1):
    question = Question.query.get(question_id)
    topic_id = question.topic.id

    db.session.delete(question)
    db.session.commit()

    return redirect(url_for('topic_questions', topic_id=topic_id))
Example #10
0
def login():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user)
            redirect_url = request.args.get('next') or url_for('main.login')
            return redirect(redirect_url)
    return render_template('login.html', form=form)
Example #11
0
def login():
    form = LogInForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user,form.remember_me)
            return redirect(request.args.get('next') or url_for('blog.index'))
        flash('Invalid username or password')
    return render_template('auth/login.html',form=form)
Example #12
0
def login():
    form = LogInForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me)
            return redirect(request.args.get('next') or url_for('blog.index'))
        flash('Invalid username or password')
    return render_template('auth/login.html', form=form)
Example #13
0
def register():
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        new_user = User(email=form.email.data,
                        username=form.username.data,
                        password=form.password.data)
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('main.login'))
    return render_template('register.html', form=form)
Example #14
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user= User(email = form.email.data,
                   username = form.username.data,
                   password = form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('注册完成')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html',form=form)
Example #15
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('注册完成')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Example #16
0
def register():
    if current_user.is_authenticated():
        return redirect(url_for("resumes"))

    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data
        display_name = form.display_name.data
        password = form.password.data

        u = User(email, display_name, password)
        db.session.add(u)
        db.session.commit()

        # TODO: Capture first and last name? personalized email?
        mail.send_welcome_email(email)

        login_user(u)
        return redirect(url_for("resumes"))

    return render_template('register.html', form=form)
Example #17
0
def oauth_callback(provider):
    if not current_user.is_anonymous():
        return redirect(url_for('main.index'))
    oauth = OAuthSignIn.get_provider(provider)
    id, name, family_name, email, picture, gender, locale = oauth.callback()
    if id is None:
        flash(u'A autenticação falhou.')
        return redirect(url_for('main.index'))
    user = User.query.filter_by(id=id).first()
    if not user:
        user = User(id=id,
                    name=name,
                    family_name=family_name,
                    email=email,
                    picture=picture,
                    gender=gender,
                    locale=locale)
        db.session.add(user)
        db.session.commit()
    login_user(user, True)
    return redirect(url_for('main.index'))
Example #18
0
    def request_detail_view(self, id):
        unapproved_user = User.query.filter(User.approved == False, User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        msg_body = render_template('email/request_detail.txt', user=unapproved_user)
        html_msg = render_template('email/request_detail.html', user=unapproved_user)

        msg_subject = u"Ufak bir rica!"
        msg = MailMessage(
            body=msg_body,
            html=html_msg,
            subject=msg_subject,
            sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
            recipients=[unapproved_user.email]
        )

        mail.send(msg)
        flash(u"Kullanıcıya e-posta gönderilerek daha fazla bilgi vermesi talep edildi!")
        return redirect(url_for('.index_view'))
Example #19
0
def login():
    """Login page"""

    def get_user(email, password):
        """Verify login and return user object if valid"""
        user = User.query.filter_by(email=email).first()
        if user and hashpw(password, user.salt) == user.password:
            return user

    if current_user.is_authenticated():
        return redirect(url_for("resumes"))

    form = LoginForm()
    if form.validate_on_submit():  # shorthand for "if POST and form is valid"
        user = get_user(form.email.data, form.password.data)
        if user:
            login_user(user)
            return redirect(url_for("resumes"))
        else:
            flash('Invalid Login')

    return render_template('login.html', form=form)
Example #20
0
    def approval_view(self, id):
        unapproved_user = User.query.filter(User.approved == False,
                                            User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        unapproved_user.approved = True
        db.session.commit()

        msg_body = render_template('email/welcome.txt', user=unapproved_user)
        html_msg = render_template('email/welcome.html', user=unapproved_user)

        msg_subject = u"Hoşgeldin!"
        msg = MailMessage(body=msg_body,
                          html=html_msg,
                          subject=msg_subject,
                          sender=(u"Eşya Kütüphanesi",
                                  "*****@*****.**"),
                          recipients=[unapproved_user.email])

        mail.send(msg)
        flash(u"Kullanıcı onaylandı ve e-posta gönderildi!")
        return redirect(url_for('.index_view'))
Example #21
0
def edit_profile():
    form=EditProfileForm()
    if form.validate_on_submit():
        current_user.name=form.name.data
        current_user.location=form.location.data
        current_user.wordrange=form.language.data
        current_user.everyrange=form.everyrange.data
        db.session.add(current_user)
        flash(u'更新成功')
        return redirect(url_for('.userInfo',username=current_user.username))
    form.name.data=current_user.username
    form.location.data=current_user.location
    form.language.data=current_user.wordrange
    form.everyrange.data=current_user.everyrange
    return render_template('edit_profile.html',form=form)
Example #22
0
    def approval_view(self, id):
        unapproved_user = User.query.filter(User.approved == False, User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        unapproved_user.approved = True
        db.session.commit()

        msg_body = render_template('email/welcome.txt', user=unapproved_user)
        html_msg = render_template('email/welcome.html', user=unapproved_user)

        msg_subject = u"Hoşgeldin!"
        msg = MailMessage(
            body=msg_body,
            html=html_msg,
            subject=msg_subject,
            sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
            recipients=[unapproved_user.email]
        )

        mail.send(msg)
        flash(u"Kullanıcı onaylandı ve e-posta gönderildi!")
        return redirect(url_for('.index_view'))
Example #23
0
def clone_resume(resume_id):
    resume = Resume.query.filter_by(id=resume_id, user=current_user).first()
    if not resume:
        abort(404)

    cloned_resume = Resume(resume.title + ' [CLONE]', current_user)
    db.session.add(cloned_resume)
    db.session.commit()

    src = app.config['RESUME_FOLDER'] + ('/%d.json' % (resume_id))
    dest = app.config['RESUME_FOLDER'] + ('/%d.json' % (cloned_resume.id))
    if os.path.isfile(src):
        shutil.copy(src, dest)

    if request.args.get('api'):
        return jsonify(response='OK')
    else:
        return redirect(url_for("resumes"))
Example #24
0
def delete_resume(resume_id):
    # Abstract this into decorator
    resume = Resume.query.filter_by(id=resume_id, user=current_user).first()
    if not resume:
        abort(404)

    db.session.delete(resume)
    db.session.commit()

    # abstract abstract abstract
    to_delete = glob.glob(app.config['RESUME_FOLDER'] + '/%d.*' % (resume_id))
    for filename in to_delete:
        os.unlink(filename)

    if request.args.get('api'):
        return jsonify(response='OK')
    else:
        return redirect(url_for("resumes"))
Example #25
0
def new_question(topic_id=-1):
    form = NewQuestionForm(request.form)
    #answerzip = zip(form.answers, form.validities)
    answers = []
    if request.method == 'POST' and form.validate_on_submit():
        for answer in form.answers:
            answers.append(
                Answer(text=answer.answer.data,
                       is_correct=answer.is_correct.data))

        question = Question(text=form.question.data,
                            author=g.user,
                            topic=Topic.query.get(topic_id),
                            answers=answers)
        db.session.add(question)
        db.session.commit()

        return redirect(url_for('topic_questions', topic_id=topic_id))
        #question = Question(texty, author, topic, answers)

    return render_template('question.html', title='New Question', form=form)
Example #26
0
def logout_cat():
    message = "Good Bye " + current_user.name  + ", come again!"
    print message
    logout_user()
    return redirect("http://college.cat")
Example #27
0
def logout():
    """Logs user out!"""
    logout_user()
    return redirect(url_for("login"))
Example #28
0
 def approval_view(self, id):
     flash('%s is approved' % str(id))
     return redirect(url_for('.index_view'))
Example #29
0
def classify_card(card_id):
    data = request.form
    tags = simplejson.loads(data["tags"])
    c = card.get_by_id(card_id)
    c.add_to_decks(tags)
    return redirect('/')
Example #30
0
def add_to_deck(user_name,deck_name,card_id):
    if current_user.get_id() != user_name:
        abort(500)
    c = card.get_by_id(card_id)
    c.add_to_deck(deck_name)
    return redirect('/'+user_name+'/deck/'+deck_name)
Example #31
0
def logout():
    logout_user()
    flash('logged out now')
    return redirect(url_for('blog.index'))
Example #32
0
 def approval_view(self, id):
     flash('%s is approved' % str(id))
     return redirect(url_for('.index_view'))
Example #33
0
def home():
    if login.current_user.is_authenticated():
        return login.redirect('/app')
    else:
        return render_template('login.html')
Example #34
0
def logout():
    # session.pop('google_token', None)
    logout_user()
    flash(u'Você foi desconectado.')
    return redirect(url_for('main.index'))
Example #35
0
def login():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    return render_template('login.html', title='Sign In')
Example #36
0
def login(provider='google'):
    if not current_user.is_anonymous():
        return redirect(url_for('main.index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()
Example #37
0
def logout():
    logout_user()
    flash('logged out now')
    return redirect(url_for('blog.index'))
Example #38
0
def oauth_authorize(provider):
    # Flask-Login function
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()
Example #39
0
def logout():
    logout_user()
    return redirect(url_for('main.index'))