Пример #1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if request.method == 'GET':
        return render_template("register.html", title='Register', form=form)

    if form.validate_on_submit():
        form = RegistrationForm()
        username = form.username.data
        email = form.email.data
        password = form.password.data
        hashed_pw = bcrypt.generate_password_hash(password).decode('utf-8')
        user = User(username=username, email=email, password=hashed_pw)
        db.session.add(user)
        db.session.commit()
        msg = f'Dear, {username} new account is successfully created for you!'
        form = LoginForm()
        return render_template("login.html", title="Login", form=form, msg=msg)

    msg = 'Form is not valid'
    return render_template('register.html',
                           title='Register',
                           form=form,
                           msg=msg)
Пример #2
0
def index():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    login_form = LoginForm()
    register_form = RegistrationForm()

    if login_form.validate_on_submit():
        user = User.query.filter_by(email=login_form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, login_form.password.data):
            login_user(user, remember=login_form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check email and password', 'danger')

    if register_form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(register_form.password.data).decode('utf-8')
        user = User(username=register_form.username.data, email=register_form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('index'))

    return render_template('index.html', title='Please login or register!', register_form=register_form, login_form=login_form)
Пример #3
0
def register():
    form = register_form()
    if form.validate_on_submit():
        print("tak")
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, password=hashed_password)
        print(user.username)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    print("gowno kaka")
    return render_template('register.html', form=form)
Пример #4
0
def register():
    # if current_user.is_authenticated():
    #     return redirect(url_for('dashboard'))
    if session.get('username', None):
        return redirect(url_for('dashboard'))

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = Users(username=form.username.data, password=hashed, firstName=form.firstName.data, lastName=form.lastName.data, email=form.email.data)
        db.session.add(user)
        db.session.commit()
        flash('Account created!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register", form=form, register=True)
Пример #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RegistrationForm()
    if request.method == "POST":
        username = request.form.get("username")
        email = request.form.get("email")
        password = request.form.get("password")
        confirm = request.form.get("confirm")
        hashed_password = bcrypt.generate_password_hash(password)
        user = User(username=username, email=email, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        # print('account created')
        return redirect(url_for("login"))
    return render_template("register.html", form=form)
Пример #6
0
def register():
    if 'loggedin' in session:
        return "Already logged in"
    form = RegistrationForm()
    if form.validate_on_submit():
        account = User.query.filter_by(name=form.username.data).first()
        # print(f"account name {account}")
        if account:
            flash("This account is alredy exists", "danger")
        else:
            hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
            user = User(name=form.username.data, password=hashed_password, email=form.email.data)
            db.session.add(user)
            db.session.commit() 
            flash(f"Account created for {form.username.data}", "success")
            return redirect(url_for('users.login')) 
        
    return render_template("register.html", form=form)
Пример #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        try:
            if username and password:
                encrypted_password = bcrypt.generate_password_hash(
                    password).decode('utf-8')
                user = User(username=username, password=encrypted_password)
                db.session.add(user)
                db.session.commit()
                return redirect(url_for('login'))
            else:
                flash('fill both fields')
        except:
            flash('username already taken', 'fail')
    return render_template('register.html')
Пример #8
0
 def __init__(self, username=None, password=None):
     self.username = username
     self.password = bcrypt.generate_password_hash(password)
Пример #9
0
 def pwd(self, plain_text_password):
     self.password = bcrypt.generate_password_hash(
         plain_text_password).decode('utf-8')