Beispiel #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'))
Beispiel #2
0
def register_get():
    if current_user.is_authenticated:
        Flasher.flash("You are already logged in", "success")
        return redirect(
            url_for('app_notes.notes', username=current_user.username))

    return render_template("register.html.j2",
                           form=RegisterForm(),
                           title="Librenotes | Register",
                           description="Make your notes free, register now!")
Beispiel #3
0
def login_get():
    if current_user.is_authenticated:
        Flasher.flash("You are already logged in", "success")
        return redirect(
            url_for('app_notes.notes', username=current_user.username))
    else:
        return render_template(
            "login.html.j2",
            form=LoginForm(),
            title="Librenotes | Login",
            description="Login to your account to see your private notes")
Beispiel #4
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))
Beispiel #5
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'))
Beispiel #6
0
def confirm():
    confirmed = mailer.confirm_token(request.args['token'])
    if confirmed:
        user_ = User.query.filter(User.email == confirmed).first()
        if user_.is_confirmed:
            Flasher.flash("This mail address has been already verified!",
                          "warning")
        else:
            user_.is_confirmed = True
            db.session.commit()
            Flasher.flash(
                "Email verification is successful, now you can login!",
                "success")
        return redirect(url_for('app_login.login_get'))
    else:
        return "Expired or you are fake"
Beispiel #7
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))
Beispiel #8
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"))
Beispiel #9
0
def logout():
    session.pop('rand_key')
    logout_user()
    Flasher.flash("You are successfully logged out!", "success")
    return redirect(url_for(".index"))