Exemplo n.º 1
0
def register():
    f_name = request.json['f_name']
    l_name = request.json['l_name']
    email = request.json['email']
    phone = request.json['phone']
    password = request.json['password']
    hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')

    new_user = models.User(f_name, l_name, hashed_password, email, phone)

    db.session.add(new_user)
    db.session.commit()

    return schemas.user_Schema.jsonify(new_user)
Exemplo n.º 2
0
 def add_user(self, username, password, admin=False):
     new_user = User(
         name=username,
         password=bcrypt.generate_password_hash(
             password,
             DevelopmentConfig().BCRYPT_LOG_ROUNDS
         ).decode('utf-8'),
         admin=admin
     )
     try:
         db.session.add(new_user)
         db.session.commit()
     except Exception as db_exceptions:
         print(db_exceptions)
Exemplo n.º 3
0
def registration():
    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('Account created!Please login', "success")
        return redirect(url_for("login"))

    return render_template("registration.html", title="Register", form=form)
Exemplo n.º 4
0
def update_user(id):
    user = models.User.query.get(id)
    f_name = request.json['f_name']
    l_name = request.json['l_name']
    email = request.json['email']
    phone = request.json['phone']
    if 'password' in request.json and request.json['password'] != '':
        user.password = hashed_password = bcrypt.generate_password_hash(
            request.json['password']).decode('utf-8')

    user.f_name = f_name
    user.l_name = l_name
    user.email = email
    user.phone = phone

    db.session.commit()

    return schemas.user_Schema.jsonify(user)