Esempio n. 1
0
 def login_user(self, email, password):
     user = User.get_user_from_email(email=email)
     if not user:
         return {'status': 404, 'message': 'User not found'}
     if check_password_hash(user['password'], password):
         token = jwt.encode(
             {
                 'user':
                 self.parse_user_sensitive_data(user.to_dict()),
                 'exp':
                 datetime.datetime.utcnow() +
                 datetime.timedelta(minutes=config['token']['exp'])
             }, config['secret_key'])
         return {'status': 200, 'message': token.decode('UTF-8')}
     return {'status': 409, 'message': 'invalid password'}
Esempio n. 2
0
    def create_new_user(self, email, password, data):
        user = User.get_user_from_email(email=email)
        if user:
            return {'status': 400, 'message': 'User already exist'}

        if 'rname' in data:
            res = self.resto_service.create_new_restaurant(
                data['rname'], email, data['address'])
            if res['status'] != 200:
                return res

        hashed_password = generate_password_hash(password, method='sha256')
        new_user = User(fname=data['fname'],
                        lname=data['lname'],
                        email=email,
                        password=hashed_password,
                        address=data['address'],
                        rname=data['rname'] if 'rname' in data else None)
        if self.persist_user_to_mongo(new_user):
            return {'status': 200, 'message': 'User created'}
        return {'status': 500, 'message': 'User not created'}