Ejemplo n.º 1
0
    def post(self):
        """
        Issue an auth token for the user based on the username and password
        """

        email = g.parsed_data.get('email')
        password = g.parsed_data.get('password')

        # Look up the user model
        try:
            user = User.query.filter_by(email=email).one()
        except Exception:
            # User doesnt exist
            raise InvalidLoginException

        # Check the user password
        if not user.check_password(password):
            # User is not legit
            raise InvalidLoginException

        # Generate a new Auth Key
        new_key = AuthKey(user)
        db.session.add(new_key)
        db.session.commit()

        return return_created_successfully(new_key)
Ejemplo n.º 2
0
    def post(self):
        new_trip = Trip(g.user)
        new_trip.from_dict(g.parsed_data)

        try:
            gatemate.db.session.add(new_trip)
            gatemate.db.session.commit()
        except Exception:
            raise gatemate.exceptions.DataValidationException('Unable to add to Database')

        return return_created_successfully(new_trip)
Ejemplo n.º 3
0
    def post(self):
        new_user = User()
        new_user.from_dict(g.parsed_data)

        try:
            gatemate.db.session.add(new_user)
            gatemate.db.session.commit()
        except Exception:
            raise gatemate.exceptions.DataValidationException('Email address already in use.')

        return return_created_successfully(new_user)
Ejemplo n.º 4
0
    def put(self, id):
        if int(id) != g.user.id:
            raise gatemate.exceptions.NotAuthorisedException('You may only access data for your own user.')

        user = User.query.get(id)
        user.from_dict(g.parsed_data)

        try:
            gatemate.db.session.add(user)
            gatemate.db.session.commit()
        except Exception:
            raise gatemate.exceptions.DataValidationException('Unable to update data. Email already in use.')

        return return_created_successfully(user)