示例#1
0
def register_post():
    form = RegisterForm(request.form)
    if form.validate():
        if not AuthHelper.check_user_exist(form.email.data,
                                           form.username.data):
            # Create new user
            user = User()
            user.username = form.username.data
            user.password = generate_password_hash(form.password.data)
            user.email = form.email.data
            user.generate_encryption_keys(form.password.data)
            # Add to db
            db.session.add(user)
            db.session.commit()
            mailer.send_confirmation_mail(form.username.data, form.email.data)
            Flasher.flash(
                "Register Successful, please check your mail address for confirmation",
                "success")
            return redirect(url_for('app_login.login_get'))
        else:
            Flasher.flash("This username or email address is already in use",
                          "warning")
    else:
        Flasher.flash_errors(form, "danger")
    return redirect(url_for('app_register.register_get'))
示例#2
0
def change_description_post():
    form = ChangeDescription(request.form)
    if form.validate():
        if AuthHelper.check_session_validation(current_user):
            current_user.description = form.description.data
            db.session.commit()
            Flasher.flash("Your description is successfully changed", "success")
        else:
            Flasher.flash("Are you fake?",
                          category='warning')
    else:
        Flasher.flash_errors(form, "danger")
    return redirect(url_for("app_notes.notes", username=current_user.username))
示例#3
0
def contact():
    form = ContactForm(request.form)
    if form.validate():
        c = ContactMessage()
        c.sender_name = form.name.data
        c.sender_mail = form.email.data
        c.message = form.message.data
        db.session.add(c)
        db.session.commit()
        Flasher.flash("Your message is sent to the developers", 'success')
    else:
        Flasher.flash_errors(form, "danger")
    return redirect(url_for('app_index.index'))
示例#4
0
def change_pass_post():
    form = ChangePasswordForm(request.form)
    if form.validate():
        if AuthHelper.check_password(current_user, form.password.data) and AuthHelper.check_session_validation(
                current_user):
            current_user.password = generate_password_hash(form.new_password.data)
            current_user.encrypt_rand_key(form.new_password.data, AuthHelper.get_random_key())
            db.session.commit()
            Flasher.flash("Your password is successfully changed", "success")
            return redirect(url_for("app_notes.notes", username=current_user.username))
        else:
            Flasher.flash("Your current password doesn't match with entered password or you are fake!",
                          category='warning')
            return redirect(url_for("app_notes.notes", username=current_user.username))
    else:
        Flasher.flash_errors(form, "danger")
        return redirect(url_for("app_notes.notes", username=current_user.username))
示例#5
0
def login_post():
    form = LoginForm(request.form)
    if form.validate():
        user_ = User.query.filter_by(username=form.username.data).first()
        if user_ and AuthHelper.check_password(user_, form.password.data):
            if not user_.is_confirmed:
                Flasher.flash("Did you confirm your email adress?", "danger")
                return redirect(url_for("app_login.login_get"))
            else:
                login_user(user_)
                AuthHelper.set_random_key(
                    user_.get_random_key(form.password.data))
                Flasher.flash("Login Successful! Welcome back, {}".format(
                    user_.username),
                              category="success")
            return redirect(
                url_for('app_notes.notes', username=form.username.data))
        else:
            Flasher.flash("Password or Username does not match", "danger")
            return redirect(url_for("app_login.login_get"))
    else:
        Flasher.flash_errors(form, "danger")
        return redirect(url_for("app_login.login_get"))