Пример #1
0
    def post(self):
        data = AccountPost.parser.parse_args()

        account = AccountModel(**data)
        try:
            account.save_to_db()
        except Exception as e:
            return {"message": "An error occurred creating the account."}, 500

        return account.json(), 201
Пример #2
0
    def put(self, name):
        data = Account.parser.parse_args()

        account = AccountModel.find_by_name(name)

        if account is None:
            account = AccountModel(name, **data)
        else:
            account.is_active = data['is_active']

        account.save_to_db()
        return account.json()
Пример #3
0
    def post(self, user_id):
        account_json = resource.get_json()
        data = account_schema.load(account_json)

        account = AccountModel(user_id, **data)

        try:
            account.save_to_db()
        except:
            return {"message": "An error occurred while adding the account."}, 500

        return account_schema.dump(account), 201
Пример #4
0
    def post(self, name):
        if AccountModel.find_by_name(name):
            return {
              "message": "An item with name '{}' already exists."
              .format(name)}, 400

        data = Account.parser.parse_args()

        account = AccountModel(name, **data)

        try:
            account.save_to_db()
        except:
            return {"message": "An error occurred adding the account."}, 500

        return account.json(), 201
Пример #5
0
def signup_post():
    email = request.form.get("email")
    firstname = request.form.get("firstname")
    lastname = request.form.get("lastname")
    password = request.form.get("password")

    user = AccountModel.query.filter_by(email=email).first()

    if user:
        flash(gettext("user_email_exists"))
        return redirect(url_for("auth.signup"))

    new_user = AccountModel(email=email,
                            firstname=firstname,
                            lastname=lastname,
                            password=AccountModel.encrypt_password(password))
    new_user.save_to_db()

    return redirect(url_for("auth.login"))
Пример #6
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument(
         'name',
         type=str,
         required=True,
         help="This field cannot be left blank!"
     )
     parser.add_argument(
         'email',
         type=str,
         required=True,
         help="This field cannot be left blank!"
     )
     parser.add_argument(
         'password',
         type=str,
         required=True,
         help="This field cannot be left blank!"
     )
     data = parser.parse_args()
     try:
         new_user = AccountModel(
             name=data['name'],
             email=data['email'],
             password=data['password'],
             role=self.role
         )
         new_user.save_to_db()
         access_token = create_access_token(identity=new_user)
         return {
             'message': 'User {} was created'.format(data['email']),
             'role': self.role,
             'access_token': access_token,
         }
     except AssertionError as exception_message:
         return {'message': 'Error: {}.'.format(exception_message)}, 400