Esempio n. 1
0
    def post(self):
        data = g.data

        new_user = UserModel(username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']),
                             icon_url=data['icon_url'])

        try:
            new_user.save_to_db()
            access_token = create_access_token(
                identity=to_identity(data['username']))
            refresh_token = create_refresh_token(
                identity=to_identity(data['username']))
            return {
                'message': 'User {} was created'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            db.session.rollback()
            return {'message': 'Registration went wrong'}, 500
Esempio n. 2
0
    def post(self):
        data = parser.parse_args()
        new_user = UserModel(
            username=data.get("username"),
            password=UserModel.generate_hash(data.get("password")),
            email=data.get("email"),
        )
        try:
            if UserModel.find_by_username(data.get("username")) or UserModel.find_by_email(data.get("email")):
                return {"message": f"User alread exists"}

            new_user.save_to_db()
            access_token = create_access_token(identity=data.get("username"))
            refresh_token = create_refresh_token(identity=data.get("username"))

            return {
                "message": f"User {data.get('username')} was created",
                "access_token": access_token,
                "refresh_token": refresh_token,
            }

        except:
            return {"message": "Something went wrong"}, 500