Ejemplo n.º 1
0
Archivo: cli.py Proyecto: withgame/zou
def create_admin(email, password):
    "Create an admin user to allow usage of the API when database is empty."
    "Set password is 'default'."

    try:
        # Allow "*****@*****.**" to be invalid.
        if email != "*****@*****.**":
            auth.validate_email(email)
        password = auth.encrypt_password(password)
        persons_service.create_person(
            email, password, "Super", "Admin", role="admin"
        )
        print("Admin successfully created.")

    except IntegrityError:
        print("User already exists for this email.")
        sys.exit(1)

    except auth.PasswordsNoMatchException:
        print("Passwords don't match.")
        sys.exit(1)
    except auth.PasswordTooShortException:
        print("Password is too short.")
        sys.exit(1)
    except auth.EmailNotValidException:
        print("Email is not valid.")
        sys.exit(1)
Ejemplo n.º 2
0
    def post(self):
        (
            email,
            password,
            password_2,
            first_name,
            last_name,
        ) = self.get_arguments()

        try:
            email = auth.validate_email(email)
            auth.validate_password(password, password_2)
            password = auth.encrypt_password(password)
            persons_service.create_person(email, password, first_name,
                                          last_name)
            return {"registration_success": True}, 201
        except auth.PasswordsNoMatchException:
            return (
                {
                    "error": True,
                    "message": "Confirmation password doesn't match.",
                },
                400,
            )
        except auth.PasswordTooShortException:
            return {"error": True, "message": "Password is too short."}, 400
        except auth.EmailNotValidException as exception:
            return {"error": True, "message": str(exception)}, 400
Ejemplo n.º 3
0
def create_admin(email):
    "Create an admin user to allow usage of the API when database is empty."
    "Set password is 'default'."

    try:
        auth.validate_email(email)
        password = auth.encrypt_password("default")
        persons_service.create_person(email,
                                      password,
                                      "Super",
                                      "Admin",
                                      role="admin")
        print("Admin successfully created.")

    except auth.PasswordsNoMatchException:
        print("Passwords don't match.")
        sys.exit(1)
    except auth.PasswordTooShortException:
        print("Password is too short.")
        sys.exit(1)
    except auth.EmailNotValidException:
        print("Email is not valid.")
        sys.exit(1)
Ejemplo n.º 4
0
 def test_validate_email(self):
     self.assertEqual(auth.validate_email("*****@*****.**"),
                      "*****@*****.**")
     self.assertRaises(auth.EmailNotValidException, auth.validate_email,
                       "johngmail.com")
Ejemplo n.º 5
0
    def post(self):
        """
        Allow a user to register himself to the service.
        ---
        tags:
            - Authentification
        parameters:
          - in: body
            name: Credentials
            description: The email, password, confirmation password, first name and last name of the user
            schema:
                type: object
                required:
                - email
                - password
                - password_2
                - first_name
                - last_name
                properties:
                    email:
                        type: string
                    password:
                        type: string
                    password_2:
                        type: string
                    first_name:
                        type: string
                    last_name:
                        type: string
                    
        responses:
          201:
            description: Registration successful
          400:
            description: Invalid password or email
        """
        (
            email,
            password,
            password_2,
            first_name,
            last_name,
        ) = self.get_arguments()

        try:
            email = auth.validate_email(email)
            auth.validate_password(password, password_2)
            password = auth.encrypt_password(password)
            persons_service.create_person(email, password, first_name,
                                          last_name)
            return {"registration_success": True}, 201
        except auth.PasswordsNoMatchException:
            return (
                {
                    "error": True,
                    "message": "Confirmation password doesn't match.",
                },
                400,
            )
        except auth.PasswordTooShortException:
            return {"error": True, "message": "Password is too short."}, 400
        except auth.EmailNotValidException as exception:
            return {"error": True, "message": str(exception)}, 400