Beispiel #1
0
    def update(self, params, meta, **kwargs):
        registration_id = kwargs['registration_id']
        validated = kwargs['validated']
        hashed_password = data_hashing(validated['password'])

        account = self.db.get(Account, is_active=False, _id=registration_id)
        if account is None:
            raise HTTPNotFound(
                description=
                "The account does not exist by given registration_id or already activated."
            )

        if account.approve_code == validated['approve_code']:
            admin = User(email=validated['email'],
                         password=hashed_password,
                         role=ERoles.admin,
                         first_name=validated['first_name'],
                         last_name=validated['last_name'],
                         account_id=account.id)

            account.is_active = True
            self.db.session.add(admin)
            token_payload = create_auth_token_payload(
                admin.id, role=admin.role, account_id=admin.account_id)
            token = encode_jwt_token(token_payload)
            add_user_token(admin.id, token)
            return {
                "token": token,
                "id": admin.id,
                "email": admin.email,
                "first_name": admin.first_name,
                "last_name": admin.last_name
            }
        else:
            raise HTTPConflict(description="Approve code does not match.")
Beispiel #2
0
    def delete(self, params, meta, **kwargs):
        others = params.get('others')
        payload = kwargs['token']
        user_id = payload['sub']

        token = encode_jwt_token(payload)
        remove_user_token(user_id, token)

        if others:
            remove_user_tokens(user_id)
            add_user_token(user_id, token)
Beispiel #3
0
    def create(self, params, meta, **kwargs):
        validated = kwargs['validated']
        hashed_password = data_hashing(validated['password'])
        user = self.db.login(validated['email'], hashed_password)

        if user.role.name is "manager":
            token_payload = create_auth_token_payload(user.id,
                                                      role=user.role,
                                                      tenant_id=user.tenant_id)
            token = encode_jwt_token(token_payload)
        else:
            token_payload = create_auth_token_payload(
                user.id, role=user.role, account_id=user.account_id)
            token = encode_jwt_token(token_payload)
        add_user_token(user.id, token)

        return {"token": token}
Beispiel #4
0
    def create(self, params, meta, **kwargs):
        user = self.db.create_user(validated=kwargs['validated'],
                                   jwt_token=kwargs['token'],
                                   role=self.role)

        token_payload = create_auth_token_payload(user.id,
                                                  role=user.role,
                                                  account_id=user.account_id)
        token = encode_jwt_token(token_payload)
        add_user_token(user.id, token)

        return {
            "token": token,
            "role": user.role.name,
            "id": user.id,
            "email": user.email,
            "first_name": user.first_name,
            "last_name": user.last_name
        }