У меня есть страница экрана блокировки, которая состоит только из поля пароля (INPUT) и просто изображения имени пользователя над полем пароля. Имейте в виду, что экран блокировки отличается от страницы входа.
Обратите внимание, что: - Форма входа требует имя пользователя и пароль, тогда как форма экрана блокировки требует только пароль, поскольку пользователь фактически не вышел из системы, но его держал где-то, насколько мне известно.
Вот простая функция входа view.py
def lockscreen(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('core:dashboard')
else:
messages.info(request, 'Username OR Password is incorrect!')
context = {}
return render(request, 'accounts/lockscreen.html', context)
html
<div class="auth-form-transparent text-left p-5 text-center">
<img src="{% static 'images/faces/face15.jpg' %}" class="lock-profile-img" alt="img">
<form class="pt-5" method="POST">
{% csrf_token %}
<div class="form-group">
<label for="examplePassword1">Password to unlock</label>
<input type="password" name="password" class="form-control text-center" id="exampleInputPassword" placeholder="Password">
</div>
<div class="mt-5">
<button type="submit" value="Login" class="btn btn-block btn-gradient-primary btn-lg font-weight-medium auth-form-btn" >Unlock</button>
</div>
<div class="mt-3 text-center">
<a href="{% url 'login' %}" class="auth-link">Sign in using a different account</a>
</div>
</form>
</div>
forms.py
class CreateUserForm(UserCreationForm):
username = forms.CharField(max_length=255, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder':'User Name ...'}))
password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder':'Password ...'}))
password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder':'Confirm Password ...'}))
email = forms.CharField(max_length=255, widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder':'E-mail ...'}))
name = forms.CharField(max_length=255, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder':'Full Name ...'}))
phone = forms.CharField(max_length=255, widget=forms.NumberInput(attrs={'class': 'form-control', 'placeholder':'Phone Number ...'}))
account_type = forms.ChoiceField(choices = ACCOUNT_TYPE, widget=forms.Select(attrs={'class': 'form-control', 'placeholder':'Phone Number ...'}))
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']
Любая идея, как чтобы достичь такой ситуации. Спасибо