Esempio n. 1
0
def user_edit(user_id: int):
    user = get(User, user_id)
    if request.method == 'POST':
        form = UserForm(request.form, obj=user)
        if form.validate():
            form.populate_obj(user)
            user.save()
            flash('Yes, usuário alterado com sucesso.', 'success')
            return redirect(url_for('users.user_index'))
    else:
        form = UserForm(obj=user)
    return render_template('users/edit.html', form=form)
Esempio n. 2
0
File: user.py Progetto: nod/cinepy
 def get(self):
     self.render(
         self.tpl, **{
             'nav_active': 'admin',
             'menu_active': 'adduser',
             'userform': UserForm(),
         })
Esempio n. 3
0
def edit_user(user_index=None):
    """
    GET - Renders a edit user form.
    POST - Validates the user form and check if the values are right. If they pass the information is stored in
    the database and the user is updated. The tenant is redirected to the user page.
    If they fail the edit user form is rendered with error messages.

    :param user_index:
    :type user_index: integer
    :return: Renders a template

    :param firstname: Firstname of the user.
    :param lastname: Lastname of the user.
    :param email: Email address of the user.
    :param phone: Phone number of the user.
    :param address: Address 1 of the user.
    :param address2: Address 2 of the user.
    :param city: City of the user.
    :param zip_code: Zip code of the city.
    :param gender: Gender of the user.
    :param ssn: Social Security Number.
    :param expiry_date: Expire date of the users membership.
    :param status: Status of the users membership.
    """
    try:
        if check_session():
            user = UserModel.query.filter_by(id=user_index).first()
            if user is None:
                return "No user have this ID"
            form = UserForm(obj=user)
            if form.validate_on_submit():
                user.firstname = form.firstname.data
                user.lastname = form.lastname.data
                user.email = form.email.data
                user.phone = form.phone.data
                user.address = form.address.data
                user.address2 = form.address2.data
                user.city = form.city.data
                user.zip_code = form.zip_code.data
                user.gender = form.gender.data
                user.ssn = form.ssn.data
                user.expiry_date = form.expiry_date.data
                user.status = form.status.data
                db.session.commit()

                return redirect("/user_page/" + str(user.id))
            if user:
                return render_template('edit_user.html',
                                       title='Edit User',
                                       form=form,
                                       data=user.dict(),
                                       error=form.errors)
            else:
                return "she wrote upon it; no such number, no such zone"

        else:
            return redirect_not_logged_in()
    except:
        flash('Error Editing a user, please try again.')
        return redirect('/')
Esempio n. 4
0
    def post(self):
        # 获取用户传过来的数据
        data = request.json

        # 验证参数有效性
        form = UserForm(data=data)
        if form.validate():
            # # 创建用户
            # user = UserProfile(user_profile_email=data.get("email"),
            #                    user_profile_name=data.get("name"),
            #                    password=data.get("password"))
            # db.session.add(user)
            # db.session.commit()
            # result = user_schema.dump(user)
            UserProfile.create_user(user_profile_email=form.email.data,
                                    user_profile_name=form.name.data,
                                    password=form.password.data)
            user = UserProfile.query.filter_by(user_profile_email=data.get("email")).first()
            result = user_schema.dump(user)

            # 返回结果
            return generate_response(data=result)
        else:
            result = form.errors
            raise FormValidateException(message=result)
Esempio n. 5
0
def user_new():
    user = User()
    if request.method == 'POST':
        form = UserForm(request.form, obj=user)
        if form.validate():
            try:
                form.populate_obj(user)
                validate_user(user)
                user.save()
                flash('Yes, usuário cadastrado com sucesso.', 'success')
                return redirect(url_for('users.user_index'))
            except AttributeError as e:
                flash(str(e), 'warning')
    else:
        form = UserForm(obj=user)
    return render_template('users/new.html', form=form)
Esempio n. 6
0
def index():
    form = UserForm(nickname=current_user.nickname, email=current_user.email)
    if request.method == 'POST' and form.validate():
        mongo.db.users.update({'_id': ObjectId(current_user.get_id())}, {'$set': {'email': form.email.data, 'nickname': form.nickname.data}})
        mongo.db.bookmarks.update({'user._id': ObjectId(current_user.get_id())}, {'$set': {'user.email': form.email.data, 'user.nickname': form.nickname.data}}, multi=True)
        if form.new_password.data:
            mongo.db.users.update({'_id': ObjectId(current_user.get_id())}, {'$set': {'password': bcrypt.generate_password_hash(form.new_password.data, rounds=12)}})
        flash(u'Les modifications ont été correctement enregistrées.')

    return render_template('profil/index.html', form=form)
Esempio n. 7
0
    def get(self, uid):
        user = self._get_user(uid)
        self._admin_or_current_user(user)

        form = PasswordForm()
        if self.current_user.is_admin:
            form = UserForm(obj=user, update=True)

        self.render(self.tpl, **{
            'user': user,
            'userform': form,
            })
Esempio n. 8
0
def add_new_user():
    """
    GET - Renders a new user form.
    POST - Validates the user form and check if the values are right. If they pass the informations is stored in
    the database and the user is registered. The tenant is redirected to the user page.
    If they fail the user form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = UserForm()
            if form.validate_on_submit():
                tmp_usr = UserModel(form.firstname.data, form.lastname.data,
                                    form.email.data, form.phone.data,
                                    form.address.data, form.address2.data,
                                    form.city.data, form.zip_code.data,
                                    form.gender.data, form.ssn.data,
                                    form.expiry_date.data, None,
                                    form.status.data)
                db.session.add(tmp_usr)
                db.session.commit()
                flash('Created new user: %s %s with id: %s' %
                      (form.firstname.data, form.lastname.data, tmp_usr.id))

                msg = tmp_usr.id

                form = UserForm()
                return render_template('new_user.html',
                                       title='New User',
                                       form=form,
                                       message=msg)
            return render_template('new_user.html',
                                   title='New User',
                                   form=form)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating a new user, please try again.')
        return redirect('/')
Esempio n. 9
0
File: user.py Progetto: nod/cinepy
    def post(self):
        userform = UserForm(TornadoMultiDict(self.request.arguments))

        try:
            self._validate_or_exception(userform)  # Validate Form
            new_user = self.db.User()  # Declare a blank User model
            userform.populate_obj(new_user)  # Populate User with form data
            new_user.set_password(userform.passwd.data)
            new_user.save()
        except Exception, e:
            self.render(
                self.tpl, **{
                    'error': e,
                    'nav_active': 'admin',
                    'menu_active': 'adduser',
                    'userform': userform,
                })
Esempio n. 10
0
def create():
    form = UserForm(get_data(request))

    if form.validate():
        newUser = User(
            str(uuid4()), form.name.data, False, form.receive_marketing.data,
            form.timezone.data)
        skills = list(filter(None, form.skills.data.split(',')))
        [newUser.addSkill(skill.strip()) for skill in skills]
        newUser.setExternalId(form.external_id.data)
        newUser.changeEmail(form.email.data)
        users.addUser(newUser)
        return jsonify({
            "data":
            newUser.toDict(),
            "links": userHateoasLinks(newUser)
        }), 201

    return jsonify({"errors": list(form.errors.items())}), 400
Esempio n. 11
0
def edit_user():

    form = UserForm()

    if request.method == 'GET':

        user_email = request.args.get('user_email')
        db = OracleDb()
        user = db.sqlalchemy_session.query(ormUser).filter(
            ormUser.user_email == user_email).one()

        # fill form and send to teacher
        form.user_email.data = user.user_email
        form.user_name.data = user.user_name
        form.user_phone.data = user.user_phone

        return render_template('user.html',
                               form=form,
                               form_name="Edit user",
                               action="edit_user")

    else:

        if form.validate() == False:
            return render_template('user.html',
                                   form=form,
                                   form_name="Edit user",
                                   action="edit_user")
        else:
            db = OracleDb()
            # find user
            user = db.sqlalchemy_session.query(ormUser).filter(
                ormUser.user_email == form.user_email.data).one()

            # update fields from form data
            user.user_email = form.user_email.data
            user.user_name = form.user_name.data
            user.user_phone = form.user_phone.data

            db.sqlalchemy_session.commit()

            return redirect(url_for('all_user'))
Esempio n. 12
0
def update(pk):
    try:
        user = users.getUser(pk=pk)
        form = UserForm(get_data(request))
        if form.validate():
            user.changeName(form.name.data)
            user.changeMarketingPreferences(form.receive_marketing.data)
            user.changeTimeZone(form.timezone.data)
            skills = list(filter(None, form.skills.data.split(',')))
            [user.addSkill(skill.strip()) for skill in skills]
            user.setExternalId(form.external_id.data)
            user.changeEmail(form.email.data)
            return jsonify({
                "data":
                user.toDict(),
                "links": userHateoasLinks(user)
            }), 200
        return jsonify({"errors": list(form.errors.items())}), 400
    except IndexError:
        return Response("User not found", 404)
Esempio n. 13
0
def user_edit(id_: int):
    form = UserForm()
    db_sess = db_session.create_session()
    users_type = [(i.id, i.users_type)
                  for i in db_sess.query(UsersTypes).all()]
    form.user_type_id.choices = users_type
    if request.method == "GET":
        user = db_sess.query(Users).filter(Users.id == id_).first()
        if user and current_user.user_type_id == 1:
            form.name.data = user.name
            form.login.data = user.login
            form.email.data = user.email
            form.user_type_id.data = user.user_type_id
        else:
            abort(404)
    if form.validate_on_submit():
        user = db_sess.query(Users).filter(Users.id == id_).first()
        if user and current_user.user_type_id == 1:
            if form.password.data and form.password.data != form.password_again.data:
                return render_template("user.html",
                                       title="Редактирование пользователя",
                                       form=form,
                                       message="Пароли не совпадают")
            elif form.password.data:
                user.set_password(form.password.data)
            user.name = form.name.data
            user.login = form.login.data
            user.email = form.email.data
            # Админ не может себя понизить
            if current_user == user:
                pass
            else:
                user.user_type_id = form.user_type_id.data
            db_sess.commit()
            return redirect('/users')
        else:
            abort(404)
    return render_template('user.html',
                           title='Редактирование пользователя',
                           form=form)
Esempio n. 14
0
    def _user_edit(self, user):
        try:
            post_args = TornadoMultiDict(self.request.arguments)
            if self.current_user.is_admin:
                # Admin can edit the full UserForm
                form = UserForm(post_args, update=True)
            else:
                # Users can only change their passwords
                form = PasswordForm(post_args, user)

            # Validate the form
            self._validate_or_exception(form)

            form.populate_obj(user)
            if form.passwd.data:
                user.set_password(form.passwd.data)
            user.save()

        except Exception, e:
            self.render(self.tpl, **{
                'error': e,
                'user': user,
                'userform': form,
                })
Esempio n. 15
0
def new_user():

    form = UserForm()

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('user.html',
                                   form=form,
                                   form_name="New user",
                                   action="new_user")
        else:
            new_user = ormUser(user_name=form.user_name.data,
                               user_email=form.user_email.data,
                               user_phone=form.user_phone.data)
            db = OracleDb()
            db.sqlalchemy_session.add(new_user)
            db.sqlalchemy_session.commit()

            return redirect(url_for('all_user'))

    return render_template('user.html',
                           form=form,
                           form_name="New user",
                           action="new_user")