Esempio n. 1
0
    def __init__(self, request, *args, **kwargs):
        super(RegenerateTwoFactorForm, self).__init__(request, *args, **kwargs)
        v_seed = TOTPOracle(auth_url=get_auth_url(), user_data=request.user).user_get_totp_key(request.user.id)
        if not v_seed:
            return False

        email = TOTPOracle(auth_url=get_auth_url(), user_data=request.user).user_get_email_address(request.user.id)
        if (email == "None") or (email is None):
            email = "MissingField"

        self.fields['seed'].initial = v_seed
        self.fields['email_address'].initial = email
Esempio n. 2
0
    def allowed(self, request, datum):
        has_email_set = TOTPOracle(
            auth_url=get_auth_url(),
            user_data=request.user).user_get_email_address(request.user.id)
        has_token_set = TOTPOracle(auth_url=get_auth_url(),
                                   user_data=request.user).user_get_totp_key(
                                       request.user.id)

        if (has_email_set == "None"
                or has_email_set is None) or (has_token_set == "None"
                                              or has_token_set is None):
            return False
        return True
Esempio n. 3
0
    def __init__(self, request, *args, **kwargs):
        super(ActivateTwoFactorForm, self).__init__(request, *args, **kwargs)
        v_seed = kwargs.get('data', {}).get('seed')
        email = TOTPOracle(auth_url=get_auth_url(),
                           user_data=request.user).user_get_email_address(
                               request.user.id)

        if not v_seed:
            v_seed = totp.get_random_base32_key(byte_key=16)
            kwargs.get('initial', {})['seed'] = v_seed
            if (email == "") or (email == "None") or (email is None):
                email = "MissingField"
            else:
                # send email...
                send_activation_email(
                    sender=getattr(settings, 'ACTIVATION_EMAIL_ADDRESS',
                                   '*****@*****.**'),
                    recipient=email,
                    subject=getattr(settings, 'ACTIVATION_EMAIL_SUBJECT',
                                    'TOTP Activation'),
                    totp_token=v_seed,
                    request=request)

        self.fields['seed'].initial = v_seed if (
            type(v_seed) == str) else v_seed.decode('utf-8')
        self.fields['email_address'].initial = email
Esempio n. 4
0
    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        manager = TOTPOracle(auth_url=get_auth_url(),
                             user_data=self.request.user)
        email_address = manager.user_get_email_address(self.request.user.id)
        if email_address == "None" or email_address is None:
            context['emailaddress'] = "MissingField"
        else:
            context['emailaddress'] = email_address

        return context
Esempio n. 5
0
    def handle(self, request, data):
        user = self.request.user
        try:
            token_seed = data.get("seed")
            token_otp = data.get("token")
            #user_email = data.get("email_address")
            twofactor = TOTPOracle(auth_url=get_auth_url(), user_data=user)
            twofactor.enable(user.id, token_seed, token_otp)
            messages.success(request, _('[2FA]: Two Factor Auth successfully enabled.'))
        except:
            exceptions.handle(request, _('[2FA]: Error while enabling two factor authentication plugin.'))

        return True 
Esempio n. 6
0
    def get_data(self):
        objects = []
        try:
            manager = TOTPOracle(auth_url=get_auth_url(),
                                 user_data=self.request.user)
            totp_key = manager.user_get_totp_key(self.request.user.id)
            email = manager.user_get_email_address(self.request.user.id)
            if (email == "None") or (email is None):
                email = "MissingAddress"

            if totp_key and not ((totp_key == "None") or (totp_key is None)):
                objects.append(
                    TwoFactorData(self.request.user.id,
                                  self.request.user.username, totp_key, True,
                                  email))
        except:
            objects = []

        return objects
Esempio n. 7
0
 def delete(self, request, obj_id):
     tokenmanager = TOTPOracle(auth_url=get_auth_url(),
                               user_data=request.user)
     tokenmanager.disable(request.user.id)