예제 #1
0
def register():
    body = request.get_json()
    try:
        # userRegistrationSchema.validate(body)
        username = body.get('username')
        user_email = body.get('email')
        firstname = body.get('firstname')
        lastname = body.get('lastname')
        gender = body.get('gender')
        password = body.get('password')

        user_password = bcrypt.generate_password_hash(
            password=password).decode('utf-8')

        users_registered = User.objects(username=username)
        if len(users_registered) == 0:
            User(username=username,
                 email=user_email,
                 password=user_password,
                 gender=gender,
                 firstname=firstname,
                 lastname=lastname).save()
            new_profile = User.objects(username=username)[0]
            return {
                'username': new_profile.username,
                'email': new_profile.email,
                'token': get_token()
            }, 201
        else:
            return jsonify({'message': 'User already exists!'}), 409
    except Exception as e:
        return {'error': str(e)}, 400
예제 #2
0
    def get(self):
        """[Retrieves all Boards by user]
        
        Raises:
            InternalServerError: [If Error in retrieval]
        
        Returns:
            [json] -- [Json object with message and status code]
        """
        try:
            user_id = get_jwt_identity()
            user = User.objects(id=ObjectId(user_id)).only('username')
            now = datetime.datetime.now()
            boards = Board.objects(added_by=ObjectId(user_id))
            boards_list = []
            for board in boards:
                board_dict = board.to_mongo().to_dict()
                data = timeago.format(board.created_at, now)
                board_dict['time_stamp'] = data
                board_dict['username'] = user[0].username
                boards_list.append(board_dict)
            res = {'data': boards_list, 'message': "Successfully retrieved", "count": len(boards_list)}
            boards_josn = dumps(res)
            return Response(boards_josn, mimetype="application/json", status=200)


        except Exception as e:
            print(e)
            raise InternalServerError
예제 #3
0
 def get_statistics(cls, company_id: str) -> dict:
     """
     Returns a statistics report per company
     """
     return {
         "time": datetime.utcnow(),
         "company_id": company_id,
         "server": {
             "version":
             current_version,
             "deployment":
             get_deployment_type(),
             "uuid":
             get_server_uuid(),
             "queues": {
                 "count": Queue.objects(company=company_id).count()
             },
             "users": {
                 "count": User.objects(company=company_id).count()
             },
             "resources":
             cls.threads.resource_monitor.get_stats(),
             "experiments":
             next(iter(cls._get_experiments_stats(company_id).values()),
                  {}),
         },
         "agents": cls._get_agents_statistics(company_id),
     }
예제 #4
0
 def get(self, id):
     try:
         user = User.objects(id=id).to_json()
         return Response(user, mimetype="application/json", status=200)
     except DoesNotExist:
         raise UserNotExistsError
     except Exception as err:
         raise InternalServerError
예제 #5
0
def login():
    body = request.get_json()
    username = body.get('username')
    password = body.get('password')
    profile = User.objects(username=username).first()
    if profile and bcrypt.check_password_hash(profile.password, password):
        token = get_token()
        Session(username=username, session_id=token).save()
        return {'token': token}, 200
    return {'message': 'Invalid username or password'}, 401
예제 #6
0
 def get(self):
     users = User.objects().to_json()
     return Response(users, mimetype="application/json", status=200)