2009-12-03 50 views

回答

3

你可以隨時修改this line到:

new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'], 
             password=self.cleaned_data['password1'], 
             email=self.cleaned_data['email'], 
             profile_callback=profile_callback, 
             send_email = False) 

或者你可以改變this line到:

def create_inactive_user(self, username, password, email, 
         send_email=False, profile_callback=None): 
+2

你需要調用雖然activate_user(或者用戶的帳戶將無法使用) – Jiaaro 2009-12-03 17:04:31

+1

在Django中註冊新版本,文件沒有按forms.py」到目前爲止,這樣的。檢查這個鏈接:http://bitbucket.org/ubernostrum/django-registration/src/tip/registration/forms.py – anhtran 2009-12-04 05:08:37

+0

這是非常簡單的事,不用修改代碼。哦,快點。我不知道這個答案有多老... – teewuane 2013-02-08 18:24:41

1

而不是變更登記程序,爲什麼不激活用戶same way django-registration does

user.is_active =真 user.save() profile.activation_key = 「ALREADY_ACTIVATED」 profile.save()

看着它之後更...我想你想要的是同時使用解決方案。也許添加上面的代碼,只是由多米尼克建議變更後(雖然我會建議使用的信號,或繼承的形式,如果可能的話)

確定最終的答案:

new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'], 
            password=self.cleaned_data['password1'], 
            email=self.cleaned_data['email'], 
            profile_callback=profile_callback, 
            send_email = False) 
RegistrationProfile.objects.activate_user(new_user.activation_key) 
+0

我弄錯了嗎?我沒有試過我的代碼,只是看看django-registration中的代碼。 – 2009-12-03 16:47:43

+0

不,我實際上只是編輯了我的答案,因爲我認爲我們的解決方案都是必需的:) – Jiaaro 2009-12-03 16:49:58

+0

這是哪裏去的?你知道沒有修改django註冊碼的方法嗎?我想像一個信號,當用戶創建.. – teewuane 2013-02-08 18:03:45

6
更好

以解決問題根比繃帶它通過調用命令來自動激活用戶。

這種方法添加到登記models.py:

def create_active_user(self, username, email, password, 
          site): 
     """ 
     Create a new, active ``User``, generate a 
     ``RegistrationProfile`` and email its activation key to the 
     ``User``, returning the new ``User``. 
     """ 
     new_user = User.objects.create_user(username, email, password) 
     new_user.is_active = True 
     new_user.save() 

     registration_profile = self.create_profile(new_user) 

     return new_user 
    create_active_user = transaction.commit_on_success(create_active_user) 

然後,編輯註冊/後端/默認/ INIT的.py並找到寄存器()方法。

更改以下打電話給你的新方法:

#new_user = RegistrationProfile.objects.create_inactive_user(username, email, 
                  #password, site) 
new_user = RegistrationProfile.objects.create_active_user(username, email, 
                  password, site) 
+0

我遵循你的程序,但是當我輸入用戶它不會像激活。 – XMen 2012-01-21 11:19:52

13

在Django登記的當前尖端的版本有一個簡單的後端,沒有電子郵件,你可以寫自己的後端,指定你想要的工作流程。有關文檔,請參見此處https://bitbucket.org/ubernostrum/django-registration/src/fad7080fe769/docs/backend-api.rst

要使用沒有電子郵件的簡單郵件,只需更改您的urls.py以指向此後端,例如。

(r'^accounts/', include('registration.backends.simple.urls')),  
+0

這是正確的答案 – 2016-03-25 04:22:09

7

爲什麼不使用this method,只使用自帶的Django的註冊,而不是默認的後臺簡單的後臺?

新的工作流程將是... 1.用戶註冊時,填寫登記表。創建 2.用戶的帳戶,並立即激活,沒有中間確認或活化步驟。 3.新用戶立即登錄。

等你的主要網址

。PY你會改變:

url(r'^accounts/', include('registration.backends.default.urls')), 

url(r'^accounts/', include('registration.backends.simple.urls')), 
相關問題