perf: 优化公钥设置,让用户可以选择是否开启

This commit is contained in:
ibuler
2021-04-25 18:13:41 +08:00
parent ce8143c2ec
commit d9552c0038
5 changed files with 17 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import uuid
import base64
import string
import random
import datetime
from django.conf import settings
from django.contrib.auth.models import AbstractUser
@@ -32,6 +33,9 @@ logger = get_logger(__file__)
class AuthMixin:
date_password_last_updated: datetime.datetime
is_local: bool
@property
def password_raw(self):
raise AttributeError('Password raw is not a readable attribute')
@@ -63,7 +67,12 @@ class AuthMixin:
return self.can_use_ssh_key_login()
def can_use_ssh_key_login(self):
return self.is_local and settings.TERMINAL_PUBLIC_KEY_AUTH
if not settings.TERMINAL_PUBLIC_KEY_AUTH:
return False
if self.is_local or settings.TERMINAL_ONLY_SOURCE_LOCAL_CAN_PUBLIC_KEY_AUTH:
return True
else:
return False
def is_public_key_valid(self):
"""