Example #1
0
def test_email_property():

    prop = EmailProperty()
    prop.name = 'email'
    prop.owner = object()
    result = prop.inflate('*****@*****.**')
    assert result == '*****@*****.**'

    with raises(DeflateError):
        prop.deflate('foo@example')
Example #2
0
def test_email_property():

    prop = EmailProperty()
    prop.name = "email"
    prop.owner = object()
    result = prop.inflate("*****@*****.**")
    assert result == "*****@*****.**"

    with raises(DeflateError):
        prop.deflate("foo@example")
Example #3
0
class Institute(DjangoNode):
    #print("in institute")
    name=StringProperty(max_length=100,required = True)
    email=EmailProperty(unique=True,required = True)
    contact=StringProperty(max_length=10, required = True)
    address = StringProperty(max_length=200)
    select = StringProperty(max_length=12, required = True)
    Date = StringProperty(required = True)

    seek = RelationshipFrom('SeekDonation', 'SEEKFROM', cardinality=ZeroOrMore)

    class Meta:
        app_label = 'core'
Example #4
0
def test_email_property():
    prop = EmailProperty()
    prop.name = 'email'
    prop.owner = object()
    result = prop.inflate('*****@*****.**')
    assert result == '*****@*****.**'

    try:
        prop.deflate('foo@example')
    except DeflateError:
        assert True
    else:
        assert False
Example #5
0
def test_email_property():

    prop = EmailProperty()
    prop.name = 'email'
    prop.owner = object()
    result = prop.inflate('*****@*****.**')
    assert result == '*****@*****.**'

    with raises(DeflateError):
        prop.deflate('foo@example')
Example #6
0
class UserProfileInfo(DjangoNode):
    first_name = StringProperty(max_length=30,required = True)
    last_name = StringProperty(max_length=150, required = True)
    email = EmailProperty(unique=True,required = True)
    username = StringProperty(max_length=150, unique=True, required = True)
    password = StringProperty(max_length=10,unique=True, required = True)
    address = StringProperty(max_length=200)
    pincode = StringProperty(max_length=6)
    phone = StringProperty(max_length=10, required = True)
    latitude = FloatProperty()
    longitude = FloatProperty()
    favGenres = RelationshipTo('Genre', 'FAVORITEGENRE', cardinality=ZeroOrMore)
    favBooks = RelationshipTo('Book', 'FAVORITEBOOK', cardinality=ZeroOrMore)
    bookRating = RelationshipTo('Book', 'RATING', model = RatingRel, cardinality=ZeroOrMore)
    class Meta:
        app_label = 'core'
Example #7
0
def test_email_property():

    prop = EmailProperty()
    prop.name = 'email'
    prop.owner = object()
    result = prop.inflate('*****@*****.**')
    assert result == '*****@*****.**'

    try:
        prop.deflate('foo@example')
    except DeflateError:
        assert True
    else:
        assert False
Example #8
0
class User(BaseModel):
    """
    This class models an user in database
    """

    # Basic field names
    name = StringProperty(required=True)
    username = StringProperty(required=True, unique_index=True)
    address = StringProperty(default=None)
    mail_address = EmailProperty(default=None)

    # Sensible data
    # TODO: Would be good hide password_ on collecting object
    password_ = StringProperty(db_property='password', required=True)

    # Relationships
    wallets = RelationshipTo('.wallet.Wallet', 'OWN')

    def wallet_uid(self):
        if self.wallets.single():
            return self.wallets.single().uid
        return None

    def to_dict(self):
        return dict(name=self.name,
                    username=self.username,
                    uid=self.uid,
                    mail_address=self.mail_address,
                    active=self.active,
                    wid=self.wallet_uid())

    @property
    def password(self):
        """
        Return hashed password
        :return: hashed password
        """
        return self.password_ if self.password_ else None

    @password.setter
    def password(self, value):
        """
        Once password need to be hashed, this method/property is
        used to hash entered password and save the hash instead
        of clean one
        """
        self.password_ = mixture_pwd(self.uid, value)

    @property
    def active(self):
        return self.active_

    @active.setter
    def active(self, state):
        self.active_ = state

    def save(self):
        """
        validates if an username is in use before save it
        :return:
            * Saved user object if it's ok
            * 'username_in_use' if username already in use
            * 'no_password_given' if password is not set
            * 'no_username_given' if username is not set
        """
        if not hasattr(self, 'username') or self.username is None:
            raise UsernameNotGiven()

        if not hasattr(self, 'password_') or self.password_ is None:
            raise UserPasswordNotGiven()

        # validate username
        if len(User.nodes.filter(username=self.username,
                                 uid__ne=self.uid)) == 0:
            return super(User, self).save()
        else:
            # Found user with same username and different uid, so, username is in use
            raise UsernameInUse()

    def create_wallet(self, label):
        """
        Create Wallet associated with user
        :param label: name to identify this wallet
        :return: generated wallet
        """
        wallet = Wallet(label=label)
        wallet.save()

        wallet.owner.connect(self)

        self.wallets.connect(wallet)
        self.save()
        wallet.save()

        return wallet

    @staticmethod
    def login(username, passwd):
        """
        Try to login an user
        :param username: username to login
        :param passwd: user password before hash
        :return:
            * True if login is ok,
            * False if wrong password
            * 'inexistent' if username not found
            * 'inactive' if user.active is False
        """
        # find user by username
        user = User.nodes.get_or_none(username=username)
        if user is None:
            raise UsernameNotFound()

        # Test if user is active
        if user.active:
            # If user is active, compare password
            hash_passwd = mixture_pwd(user.uid, passwd)
            if user.password_ == hash_passwd:
                return user
            else:
                # If password is wrong, raise an exception
                raise UserPasswordIncorrect()
        else:
            # If user is inactive, raise an exception
            raise UserInactive()