Пример #1
0
    def on_put(self, req, res):
        username = req.get_json('username', dtype=str, min=3, max=20)
        password = req.get_json('password', dtype=str, min=8, max=20)
        new_password = req.get_json('new_password', dtype=str, min=8, max=20)

        users = db.fetch_users(username)

        user_id = str(uuid.uuid4())
        pasword = make_password_hashing(new_password)

        if len(users) == 1:
            if not checking_password_hash(password, users[0]['password']):
                error = {
                    'description': 'Incorrect password entered',
                }
                LOG.error(error)
                raise generic_error_handler(401, req=req, error_override=error)
            else:
                db.replace_user_info(user_id, username, pasword)
                
        elif len(users) > 1:
            error = {
                'description': f"There was more than 1 user found for username: '******'"
            }
            LOG.error(error)
            raise generic_error_handler(400, req=req, error_override=error)
        else:
            db.create_user(user_id, username, pasword)
        
        data = {
            'id': user_id,
            'username': username
        }

        self.on_success(res, data)
Пример #2
0
    def on_post(self, req, res):
        username = req.get_json('username', dtype=str)
        password = req.get_json('password', dtype=str)

        users = db.fetch_users(username)
        if len(users) == 1:
            if not checking_password_hash(password, users[0]['password']):
                error = {
                    'description': 'either username or password is invalid'
                }
                LOG.error(error)
                raise generic_error_handler(401, req=req, error_override=error)
            else:
                payload = OrderedDict()
                payload['id'] = users[0]['id']
                payload['username'] = username

                data = jwt_payload_handler(payload)

                payload = {**payload, **data}

                self.on_success(res, payload)

        elif len(users) > 1:
            error = {
                'description':
                f"There was more than 1 user found for username: '******'"
            }
            LOG.error(error)
            raise generic_error_handler(401, req=req, error_override=error)

        else:
            error = {'description': 'either username or password is invalid'}
            LOG.error(error)
            raise generic_error_handler(401, req=req, error_override=error)
Пример #3
0
    def on_patch(self, req, res):
        username = req.get_json('username', dtype=str, min=3, max=20)
        password = req.get_json('password', dtype=str, min=8, max=20)
        new_password = req.get_json('new_password', dtype=str, min=8, max=20)

        pasword = make_password_hashing(new_password)
        
        users = db.fetch_users(username)

        if len(users) == 1:
            if not checking_password_hash(password, users[0]['password']):
                error = {
                    'description': 'Incorrect password entered',
                }
                LOG.error(error)
                raise generic_error_handler(401, req=req, error_override=error)
            else:
                db.update_password(users[0]['id'], pasword)
                data = {
                    'id': users[0]['id'],
                    'username': username
                }

                self.on_success(res, data)

        elif len(users) > 1:
            error = {
                'description': f"There was more than 1 user found for username: '******'"
            }
            LOG.error(error)
            raise generic_error_handler(400, req=req, error_override=error)

        else:
            error = {
                'description': 'Invalid username',
                'details': f"{username} doesn't exist."
            }
            LOG.error(error)
            raise generic_error_handler(404, req=req, error_override=error)