Beispiel #1
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'))
Beispiel #2
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'))
Beispiel #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)
def post_list_cars():
    mfg = request.form.get("mfg")
    if mfg == 'not specified':
        return redirect (url_for('get_list_cars'))

    cars = g.user.cars.filter(models.Car.mfg == mfg).all()
    return render_template("list_cars.html", cars = cars, user=g.user)
Beispiel #5
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)
Beispiel #6
0
def post_list_cars():
    mfg = request.form.get("mfg")
    if mfg == 'not specified':
        return redirect(url_for('get_list_cars'))

    cars = g.user.cars.filter(models.Car.mfg == mfg).all()
    return render_template("list_cars.html", cars=cars, user=g.user)
def delete_car(id):
    car = models.Car.query.get(id)
    if car and car.owner == g.user:
        db.session.delete(car)
        db.session.commit()
        return redirect(url_for("get_list_cars"))
    else:
        abort(404)
Beispiel #8
0
def delete_car(id):
    car = models.Car.query.get(id)
    if car and car.owner == g.user:
        db.session.delete(car)
        db.session.commit()
        return redirect(url_for("get_list_cars"))
    else:
        abort(404)
Beispiel #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))
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #15
0
def post_add_car():
    mfg = request.form.get("mfg")
    model = request.form.get("model")
    year = request.form.get("year")
    year = year if year else 0
    color = request.form.get("color")

    c = models.Car(mfg=mfg, model=model, year=year, color=color)
    g.user.cars.append(c)
    db.session.commit()
    return redirect(url_for("get_list_cars"))
Beispiel #16
0
def post_add_car():
    mfg = request.form.get("mfg")
    model = request.form.get("model")
    year = request.form.get("year")
    year = year if year else 0
    color = request.form.get("color")

    c = models.Car(mfg=mfg, model=model, year=year, color=color)
    g.user.cars.append(c)
    db.session.commit()
    return redirect(url_for("get_list_cars"))
Beispiel #17
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)
Beispiel #18
0
def post_edit_car(id):
    car = models.Car.query.get(id)
    if car and car.owner == g.user:
        car.make = request.form.get("make")
        car.model = request.form.get("model")
        car.year = request.form.get("year")
        car.color = request.form.get("color")
        db.session.commit();

        return redirect(url_for("get_list_cars"))
    else:
        abort(404)
Beispiel #19
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'))
Beispiel #20
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'))
Beispiel #21
0
def post_edit_car(id):
    car = models.Car.query.get(id)
    if car and car.owner == g.user:
        car.make = request.form.get("make")
        car.model = request.form.get("model")
        car.year = request.form.get("year")
        car.color = request.form.get("color")
        db.session.commit()

        return redirect(url_for("get_list_cars"))
    else:
        abort(404)
Beispiel #22
0
def after_login(resp):
    if not resp.email:
        abort(404)

    user = models.User.query.filter(models.User.email == resp.email).first()
    
    if not user:
        user = models.User(resp.email)
        db.session.add(user)
        db.session.commit()

    login_user(user)
    
    return redirect(url_for('get_list_cars'))
Beispiel #23
0
def after_login(resp):
    if not resp.email:
        abort(404)

    user = models.User.query.filter(models.User.email == resp.email).first()

    if not user:
        user = models.User(resp.email)
        db.session.add(user)
        db.session.commit()

    login_user(user)

    return redirect(url_for('get_list_cars'))
Beispiel #24
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'))
Beispiel #25
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'))
Beispiel #26
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)
Beispiel #27
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)
Beispiel #28
0
def logout():
    logout_user()
    return redirect(url_for('home'))      
Beispiel #29
0
def index():
    return redirect(url_for('login'))
Beispiel #30
0
def logout():
    logout_user()
    return redirect(url_for('index'))
Beispiel #31
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()
Beispiel #32
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')
Beispiel #33
0
def logout():
    # session.pop('google_token', None)
    logout_user()
    flash(u'Você foi desconectado.')
    return redirect(url_for('main.index'))
Beispiel #34
0
 def approval_view(self, id):
     flash('%s is approved' % str(id))
     return redirect(url_for('.index_view'))
Beispiel #35
0
def redirect_url(default='index'):
    return request.args.get('next') or \
           request.referrer or \
           url_for(default)
Beispiel #36
0
def logout():
    logout_user()
    flash('You have been logged out')
    return redirect(url_for('displayIndex'))
Beispiel #37
0
def logout():
    logout_user()
    return redirect(url_for('index'))
Beispiel #38
0
def logout():
    logout_user()
    flash('logged out now')
    return redirect(url_for('blog.index'))
Beispiel #39
0
def index():
    return redirect(url_for('login'))
Beispiel #40
0
 def approval_view(self, id):
     flash('%s is approved' % str(id))
     return redirect(url_for('.index_view'))
Beispiel #41
0
def logout():
    logout_user()
    flash('logged out now')
    return redirect(url_for('blog.index'))
Beispiel #42
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()