def validate(cls, email, password):
        docs = list(r.table(cls._table).filter({'email': email}).run(conn))

        if not len(docs):
            raise ValidationError("Could not find the email address you specified")

        _hash = docs[0]['password']

        if cls.verify_password(password, _hash):
            try:
                token = jwt.encode({id: docs[0]['id']}, current_app.config['SECRET_KEY'], algorithm="HS256")
                return token
            except JWTError:
                raise ValidationError("There was a problem while trying to create a JWT token.")
        else:
            raise ValidationError("The password you entered is incorrect.")
Exemple #2
0
    def validate(cls, email, password):
        docs = list(r.table(cls._table).filter({'email': email}).run(conn))

        if not len(docs):
            raise ValidationError("Could not find email address specified")

        _hash = docs[0]['password']

        if cls.verify_password(password, _hash):
            try:
                token = jwt.encode({'id': docs[0]['id']}, current_app.config['SECRET_KEY'], algorithm='HS256')
                return token
            except JWTError:
                raise ValidationError("There was a problem creating JWT token")
        else:
            raise ValidationError("The password you inputted was incorrect")
Exemple #3
0
    def create(cls, **kwargs):
        fullname = kwargs.get('fullname')
        email = kwargs.get('email')
        password = kwargs.get('password')
        password_conf = kwargs.get('password_conf')

        street_number = kwargs.get('street_number')
        route = kwargs.get('route')
        locality = kwargs.get('locality')
        postal_town = kwargs.get('postal_town')
        administrative_area_level_2 = kwargs.get('administrative_area_level_2')
        administrative_area_level_1 = kwargs.get('administrative_area_level_1')
        country = kwargs.get('country')
        postal_code = kwargs.get('postal_code')
        ocp_admin = kwargs.get('ocp_admin')

        if password != password_conf:
            raise ValidationError(
                "Password and Confirm password need to be the same value")
        password = cls.hash_password(password)
        doc = {
            'fullname': fullname,
            'email': email,
            'password': password,
            'ocp_admin': ocp_admin,
            'address': {
                'street_number': street_number,
                'route': route,
                'locality': locality,
                'postal_town': postal_town,
                'administrative_area_level_2': administrative_area_level_2,
                'administrative_area_level_1': administrative_area_level_1,
                'country': country,
                'postal_code': postal_code
            },
            'date_created': datetime.now(r.make_timezone('+01:00')),
            'date_modified': datetime.now(r.make_timezone('+01:00')),
        }

        print(doc)

        users = list(r.table(cls._table).filter({'email': email}).run(conn))
        if len(users):
            raise ValidationError(
                "Could already exists with e-mail address: {0}".format(email))

        r.table(cls._table).insert(doc).run(conn)
 def create(cls, **kwargs):
     fullname = kwargs.get('fullname')
     email = kwargs.get('email')
     password = kwargs.get('password')
     password_conf = kwargs.get('password_conf')
     if password != password_conf:
         raise ValidationError("Password and Confirm Password need to be the same value")
     password = cls.hash_password(password)
     doc = {
         'fullname': fullname,
         'email': email,
         'password': password,
         'date_created': datetime.now(r.make_timezone('+01:00')),
         'date_modified': datetime.now(r.make_timezone('+01:00'))
     }
     r.table(cls._table).insert(doc).run(conn)
Exemple #5
0
 def create(cls, **kwargs):
     firstname = kwargs.get('firstname')
     lastname = kwargs.get('lastname')
     email = kwargs.get('email')
     password = kwargs.get('password')
     confirmation_password = kwargs.get('confirmation_password')
     if password != confirmation_password:
         raise ValidationError(
             "Password have to be equals to confirmation passoword")
     password = cls.hash_password(password)
     document = {
         'firstname': firstname,
         'lastname': lastname,
         'email': email,
         'password': password,
         'created': datetime.now(r.make_timezone('+01:00')),
         'modified': datetime.now(r.make_timezone('+01:00'))
     }
     r.table(cls._table).insert(document).run(connection)