Exemplo n.º 1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        username = form.username.data
        user = User(username, password, email)
        otp = send_verification_email(user)
        token = user.get_verification_token(otp=otp)
        return redirect(
            url_for('user_accounts.otp_verification',
                    token=token,
                    remember_me=form.remember_me.data))

    return render_template('user_accounts/register.html', form=form)
Exemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('/home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account was created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash("註冊完成! 可以開始登入", "success")
        return redirect(url_for("users.login"))
    return render_template("register.html", form = form, title = "Register")
Exemplo n.º 4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    form = RegistrationForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            hashed_pass = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
            user = User(username=form.username.data.title(), email=form.email.data, password=hashed_pass)
            db.session.add(user)
            db.session.commit()
            flash(f"Account created successfully! Now you can login", 'success')
            return redirect(url_for("users.login"))
    return render_template("register.html", title='Register', form=form)
Exemplo n.º 5
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_token(token)
    if user is None:
        flash('The token was invalid or experied.')
        return redirect(url_for('user_accounts.login'))
    form = ResetPassword()
    if form.validate_on_submit():
        user.password = generate_password_hash(form.password.data)
        db.session.commit()
        flash('Password reset successful! You could login now.', 'info')
        return redirect(url_for('user_accounts.login'))
    return render_template('user_accounts/reset_password.html', form=form)
Exemplo n.º 6
0
def register():
    register_form = RegisterForm()
    if register_form.re_submit.data and register_form.validate_on_submit():
        user = User(username=register_form.username.data,
                    password_hash=register_form.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('content.login', login_required=2))
    return render_template('login.html',
                           register_form=register_form,
                           para=g.para,
                           hots=g.hot_list,
                           links=g.links,
                           target='register')
Exemplo n.º 7
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('密碼更新完成. 可以開始登入', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html', form = form, title = 'Reset Password')
Exemplo n.º 8
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    user = User.verify_reset_password_token(token)
    if not user:
        flash("Token is expired or invalid", "warning")
        return redirect(url_for('users.request_reset_password'))
    form = ResetPasswordForm()
    if request.method == "POST":
        if form.validate_on_submit():
            hashed_new_pass = bcrypt.generate_password_hash(form.new_password.data).decode('utf-8')
            user.password = hashed_new_pass
            db.session.commit()
            flash(f"Password updated successfully", 'success')
            return redirect(url_for("main.login"))
    return render_template("reset_password.html", title="Create New Password", form=form)
Exemplo n.º 9
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form=RegistrationForm()
    print(form.email.errors)

    if form.validate_on_submit():
        user=User(username=form.username.data,email=form.email.data,
                    password=bcrypt.generate_password_hash(form.password.data).decode('utf-8'))
        db.session.add(user)
        db.session.commit()
        flash('Account has created for {}'.format(form.username.data),'success')
        return redirect(url_for('home'))


    return render_template("register.html",title="register",form=form)
Exemplo n.º 10
0
def adduser():
    name = raw_input("Name: ")
    email = raw_input("Email: ")
    if session.query(User).filter_by(email=email).first():
        print "User with that email address already exists"
        return

    password = raw_input("Password ")
    password_2 = raw_input("Password ")
    while not (password and password_2) or password != password_2:
        password = getpass("Password: "******"Re-enter password: ")
    user = User(name=name,
                email=email,
                password=generate_password_hash(password))
    session.add(user)
    session.commit()
Exemplo n.º 11
0
def register_admin():
    form = AdminRegistrationForm()
    if request.method == "POST":
        if form.validate_on_submit():
            email = form.email.data
            username = form.username.data
            # generate a random password
            possible_characters = "@#_abcdefghijklmnopqrstuvwxyz1234567890"
            random_password = "".join([random.choice(possible_characters) for _ in range(6)])
            # hash the passowrd
            hashed_pass = bcrypt.generate_password_hash(random_password).decode('utf-8')
            user = User(username=username.title(), email=email, password=hashed_pass, admin=1)
            db.session.add(user)
            db.session.commit()
            new_admin_email(user)
            flash("New admin was added successfully and an email was sent to him.", "success")
            return redirect(url_for("admin.register_admin"))
    return render_template("admin/add_admin.html", form=form)
Exemplo n.º 12
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)

    if user is None:
        flash('Invalid token or expired token', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_pass = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_pass
        db.session.commit()
        flash('Password has been updated! You are now able to log in',
              'success')

        return redirect(url_for('login'))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form)
Exemplo n.º 13
0
def otp_verification(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    # Token Processing
    user, otp = User.verify_verification_token(token)
    remember_me = request.args.get('remember_me')
    remember_me = True if remember_me == 'True' else False
    if user is None or otp is None:
        flash('Invalid or expired token')
        return redirect(url_for('user_accounts.login'))

    # Validate OTP
    form = OTPForm()
    if form.validate_on_submit():
        if not form.otp.data == str(otp):
            flash('Invalid OTP')
            return redirect(
                url_for('user_accounts.otp_verification', token=token))
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=remember_me)
        return redirect(url_for('home'))
    return render_template('user_accounts/otp_verification.html', form=form)
Exemplo n.º 14
0
def insert(name, email):
    result = User.add(name, email)
    return f'{result}\n'