コード例 #1
0
    def create(self, username, password, first_name, last_name, email, permissions):
        new_user = User(
            username=username,
            first_name=first_name,
            last_name=last_name,
            email=email,
            permissions=permissions
        )
        new_user.set_password(password)

        self.database.add(new_user)
        self.database.flush()

        try:
            self.database.commit()

            return new_user
        except SQLAlchemyError:
            print('SQLAlchemy exception when creating a new user.')
コード例 #2
0
def add_user():
    add_user_form = UserForm()
    if add_user_form.validate_on_submit():
        if users_service.exists(add_user_form.username.data):
            flash(u'Username already exists.', 'error')
        else:
            password = add_user_form.password.data.encode('utf-8')
            hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
            new_user = User(username=add_user_form.username.data,
                            password=hashed_password,
                            first_name=add_user_form.first_name.data,
                            last_name=add_user_form.last_name.data,
                            email=add_user_form.email.data,
                            permissions=add_user_form.permissions.data)

            new_user.create()
            flash(u'Successfully added user.', 'success')

        return redirect('admin/users/add')
    else:
        return render_template('admin/add_user.html', form=add_user_form)
コード例 #3
0
def add_user():
    add_user_form = UserForm()
    if add_user_form.validate_on_submit():
        if users_service.exists(add_user_form.username.data):
            flash(u'Username already exists.', 'error')
        else:
            password = add_user_form.password.data.encode('utf-8')
            hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
            new_user = User(username=add_user_form.username.data,
                            password=hashed_password,
                            first_name=add_user_form.first_name.data,
                            last_name=add_user_form.last_name.data,
                            email=add_user_form.email.data,
                            permissions=add_user_form.permissions.data)

            new_user.create()
            flash(u'Successfully added user.', 'success')

        return redirect('admin/users/add')
    else:
        return render_template('admin/add_user.html', form=add_user_form)