Esempio n. 1
0
    def _update_password(self):
        result = None
        user = User(phone_number=self.phone_number, validate=True)
        if user.is_registered():
            if user.is_valid():
                hashed_password = user.generate_hash_password(self.new_password)
                dct = {Keys.PASSWORD: hashed_password}
                result = user.update(db, dct)

            elif user.is_invalid():
                pass
        else:
            not_registered_before = RegisteredBefore(status=404, message=MessagesKeys.NOT_REGISTERED_BEFORE,
                                                     params=None)
            return False, not_registered_before
        if result[0]:
            result = self.create_success_message(Result.language.PASSWORD_CHANGE_SUCCESSFULLY)
            dct = result.dictionary_creator()
            return self.serialize(dct, self.converter)

        dct = result.dictionary_creator()
        return self.serialize(dct, self.converter)
Esempio n. 2
0
    def handle_state_password(self):
        result = None
        user = User(phone_number=session[Keys.FORGET_PASS][Keys.USER_ID])
        if user.is_registered():
            hashed_password = user.generate_hash_password(self.password)
            dct = {Keys.PASSWORD: hashed_password}
            result = user.update(db, dct)
        else:
            not_registered_before = RegisteredBefore(
                status=404,
                message=MessagesKeys.NOT_REGISTERED_BEFORE,
                params=None)

            dct = not_registered_before.dictionary_creator()
            return self.serialize(dct, self.converter)

        if not result[0]:
            dct = result.dictionary_creator()
            return self.serialize(dct, self.converter)
        session.clear()
        result = self.create_success_message(
            Result.language.PASSWORD_CHANGE_SUCCESSFULLY)
        dct = result.dictionary_creator()
        return self.serialize(dct, self.converter)