예제 #1
0
def register():
    """renders the registration page"""
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        """whenever the form is submitted, enter the credentials into the database and hash the password"""
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(first_name=clean_string(form.first_name.data),
                    last_name=clean_string(form.last_name.data),
                    email=clean_string(form.email.data),
                    password=hashed_password,
                    school_class=clean_string(form.school_class.data),
                    user_type="NOT_APPROVED")

        db.session.add(user)
        db.session.commit()
        """send an email to the admins about the new user"""
        msg = newUserMessage(user)
        mail.send(msg)

        flash(
            'המשתמש נוצר בהצלחה. המתן לאישורו, לאחר האישור יהיה ניתן להתחבר עם המשתמש לאתר.',
            'success')

        return redirect(url_for('login'))

    return render_template('register.html',
                           title='Register',
                           message='דף הירשמות',
                           form=form)
예제 #2
0
def createArticle():
    """renders the create article page (must be logged in in order to access)"""
    form = SubmitArticle()
    if form.validate_on_submit():
        article = Article(
            heading=clean_string(form.heading.data),
            body=clean_string(form.body.data),
            post_date=datetime.now().strftime("%m/%d/%Y, %H:%M:%S"),
            accept_date=None,
            is_accepted=False,
            # is_english=form.is_engish.data,
            author_id=current_user.get_id(),
            caption=clean_string(form.caption.data),
            thumbnail=clean_string(form.thumbnail.data)
            if clean_string(form.thumbnail.data) else
            "https://lh5.googleusercontent.com/p/AF1QipMF1XVDYrw7O7mg3E_fLqgAceacWExqaP4rbptz=s435-k-no"
        )

        db.session.add(article)
        db.session.commit()

        msg = newArticleMessage(article)
        mail.send(msg)

        flash('הכתבה נוצרה בהצלחה וממתינה לאישור מנהל.', 'success')

        return redirect(url_for('articles', index=article.article_id))

    return render_template('submitArticle.html',
                           title="צור כתבה חדשה",
                           form=form)
예제 #3
0
def acceptUser(index):
    """accept user endpoint for accepting new users (must be logged in AND be an admin in order to access)"""
    user = User.query.get(index)

    if user:
        user.accept_user()
        msg = acceptUserMessage(user)
        mail.send(msg)

    next_page = request.args.get('next')
    return redirect(url_for('controlPanel'))
예제 #4
0
def acceptArticle(index):
    """accept article endpoint for accepting new articles (must be logged in AND be an admin in order to access)"""
    article = Article.query.get(index)

    if article:
        article.accept_article()
        msg = acceptArticleMessage(article)
        mail.send(msg)

    next_page = request.args.get('next')
    return redirect(next_page) if next_page else redirect(
        url_for('articlesview'))