사용자 이름 대신 전자 메일로 사용자를 인증하려고합니다.전자 메일 및 결과 라우팅 문제를 사용한 인증
나는 django-userena
을 사용하고 있으며 문서 등을 사용하고 있습니다. 나는 필요한 거의 모든 것을 설정했다. 같은 모양 : USERENA_WITHOUT_USERNAMES = True
설정에
그러나 가입 후, 나는 일련의 문제에 직면했습니다.
사용자 이름을 인수로 사용하는 일부보기 기능을 변경했지만이 방법으로도 내 문제가 해결되지 않았으며 정확하지 않을 수 있습니다.) 그것을 할 방법. 예를 들어
($ ./manage.py check_permissions
후)이 URL http://127.0.0.1:8000/accounts/signup/complete/
로 라우팅하여이 오류를 얻을 : 내가 부족 아무것도
global name 'username' is not defined
/userena/views.py in directto_user_template
user = get_object_or_404(User, username_iexact=username)
있습니까?
는 UPDATE :
userena/templates/userena/emails/activation_email_message.txt, error at line 8
1 {% load i18n %}{% autoescape off %}
2 {% if not without_usernames %}{% blocktrans with user.username as username %}Dear {{ username }},{% endblocktrans %}
3 {% endif %}
4 {% blocktrans with site.name as site %}Thank you for signing up at {{ site }}.{% endblocktrans %}
5
6 {% trans "To activate your account you should click on the link below:" %}
7
8 {{ protocol }}://{{ site.domain }}{% url userena_activate user.username activation_key %}
9
10 {% trans "Thanks for using our site!" %}
11
12 {% trans "Sincerely" %},
13 {{ site.name }}
14 {% endautoescape %}
업데이트 2 :
Caught NoReverseMatch while rendering: Reverse for 'userena_activate' with arguments '('[email protected]', '70b60d1d97015e03ba8d57f31e4c7ff14d6ab753')' and keyword arguments '{}' not found.
그것은 userena가 URL과 사용자 이름으로 이메일을 시도하는 분명하다 : 여기 내가 얻을 그 출력 : 괜찮습니다. SignupFormOnlyEmail
클래스 형식의 소스 코드를 보면 임의의 사용자 이름이 자동으로 생성된다고합니다.
class SignupFormOnlyEmail(SignupForm):
"""
Form for creating a new user account but not needing a username.
This form is an adaptation of :class:`SignupForm`. It's used when
``USERENA_WITHOUT_USERNAME`` setting is set to ``True``. And thus the user
is not asked to supply an username, but one is generated for them. The user
can than keep sign in by using their email.
"""
def __init__(self, *args, **kwargs):
super(SignupFormOnlyEmail, self).__init__(*args, **kwargs)
del self.fields['username']
def save(self):
""" Generate a random username before falling back to parent signup form """
while True:
username = sha_constructor(str(random.random())).hexdigest()[:5]
try:
User.objects.get(username__iexact=username)
except User.DoesNotExist: break
self.cleaned_data['username'] = username
return super(SignupFormOnlyEmail, self).save()
업데이트 :
나는 마지막으로 문제를 해결했다. 나는 django-userena
옆에도 django-email-as-username
을 사용하고있었습니다. 이것이 내 문제의 원인이었습니다. 분명히, 그들은 약간의 갈등을 가지고 있습니다. 당신은 키워드 인수 (username
및 activation_key
)와 URL 경로 userena_activate
을 정의한
오류 메시지에 모든 것 : 변수 'username'이 정의되지 않았습니다. 귀하의 의견, posts.py, pls 코드 – yedpodtrzitko
코드는 [Github] (http://github.com/bread-and-pepper/django-userena/blob/master/userena/views.py)에 있습니다. 나는 더 많은 정보와 함께 게시물을 업데이 트됩니다 .. 예를 들어, 라인 142 봐, "활성화"기능 .. – Soask