Exemple #1
0
    def post(self):

        form = RegisterForm()

        if form.validate_on_submit():

            photo = upload_file(request.files['photo'])

            obj = Relative(name=form.name.data,
                           cpf=form.cpf.data,
                           phone=form.phone.data,
                           email=form.email.data,
                           password=bcrypt.generate_password_hash(
                               form.password.data).decode('utf-8'),
                           photo=photo,
                           active=True)

            db.session.add(obj)
            db.session.commit()
            """token = relative_token_serializer.dumps(form.email.data, salt='confirm-email')
            
            msg = Message(
                '82Hack - Confirmação de Cadastro',
                sender=app.config['MAIL_USERNAME'],
                recipients=[form.email.data]
            )
            msg.html = "<a href='" + API_URL + "confirm_email/" + \
                token + "'>Clique aqui para confirmar seu cadastro!</a>"
            mail.send(msg)"""

            return {'success': True}

        else:
            print(form.errors)
            return {'success': False, "errors": form.errors}
    def __init__(self, *args, **kwargs):
        super(User, self).__init__(*args, **kwargs)

        self.password = bcrypt.generate_password_hash(
            kwargs.get('password'), app.config.get('BCRYPT_LOG_ROUNDS')
        ).decode()
        self.registered_on = datetime.datetime.now()
Exemple #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('Your account has been created! You are now able to log in', 'success')
        #flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Exemple #4
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('Your password has been updated! You are now able to log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html', title='Reset Password', form=form)
Exemple #5
0
def add_user(username: str, password: str, email: str):
    # 添加用户,返回一个元组 (插入结果(Bool),提示信息)
    # 检测用户是否存在
    if is_existing_user(username):
        return False, "用户已存在"

    # 检测邮箱是否被注册
    if is_existing_email(email):
        return False, "邮箱已注册"

    # 插入用户信息
    pw_hash = bcrypt.generate_password_hash(password)  # hash加密用户密码
    user = User(username=username, password=pw_hash, email=email)
    db.session.add(user)
    db.session.commit()
    return True, "注册成功"
Exemple #6
0
def set_user(uid, origin_password, username=None, new_password=None, email=None):
    user = is_existing_user(uid=uid)
    if user and bcrypt.check_password_hash(user.password, origin_password):
        if username:
            if is_existing_user(username):
                return False, "用户已存在"
            user.username = username
        if new_password:
            user.password = bcrypt.generate_password_hash(new_password)
        if email:
            if is_existing_email(email):
                return False, "邮箱已注册"
            user.email = email
        db.session.commit()
        return True, "更新用户信息成功"
    else:
        return False, "用户不存在或密码错误"
Exemple #7
0
def app_register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))

    _form = RegisterForm()
    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 successfully!", "success")
        return redirect(url_for("login"))

    return render_template('pages/register.html', form=_form)
Exemple #8
0
    def post(self):

        form = RegisterForm()

        if form.validate_on_submit():

            admin = Admin(username=form.username.data,
                          password=bcrypt.generate_password_hash(
                              form.password.data).decode('utf-8'))

            db.session.add(admin)
            db.session.commit()

            return {'success': True}

        else:

            return {'success': False, "errors": form.errors}
Exemple #9
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        if form.new_password.data:
            hashed_password = bcrypt.generate_password_hash(form.new_password.data).decode('utf-8')
            current_user.password = hashed_password
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template('account.html', title='Account', image_file=image_file, form=form)
Exemple #10
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("users.account_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,
                    hidemail=False,
                    msg_per_page=5)

        db.session.add(user)
        db.session.commit()

        flash("Your account has been created. You can nou login.", "success")

    return render_template("register.html", form=form)
Exemple #11
0
def registration():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data.lower(),
                    password=hashed_pw,
                    image_file='default_' + str(random.randrange(1, 4, 1)) +
                    '.jpg')

        db.session.add(user)
        db.session.commit()

        #flash('Your account has been  created you can now login', 'success')
        return redirect(url_for('login'))
    return render_template('registration.html',
                           title='Registration',
                           form=form)
Exemple #12
0
 def __init__(self, first_name, last_name, email, title, password):
     self.first_name = first_name
     self.last_name = last_name
     self.email = email
     self.title = title
     self.password = bcrypt.generate_password_hash(password)
Exemple #13
0
 def pin(self, plaintext_pin):
     self._pin_hash = bcrypt.generate_password_hash(plaintext_pin)
Exemple #14
0
 def password(self, plaintext_password):
     self._password_hash = bcrypt.generate_password_hash(plaintext_password)
Exemple #15
0
 def authenticator(self, plaintext_authenticator):
     self._authenticator_hash = bcrypt.generate_password_hash(
         plaintext_authenticator)
Exemple #16
0
 def authentification(self, plaintext_authentification):
     self._authentification_hash = bcrypt.generate_password_hash(plaintext_authentification)