當前位置: 首頁>>代碼示例>>Python>>正文


Python RegistrationForm.save方法代碼示例

本文整理匯總了Python中accounts.forms.RegistrationForm.save方法的典型用法代碼示例。如果您正苦於以下問題:Python RegistrationForm.save方法的具體用法?Python RegistrationForm.save怎麽用?Python RegistrationForm.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在accounts.forms.RegistrationForm的用法示例。


在下文中一共展示了RegistrationForm.save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: RegisterView

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
class RegisterView(TemplateView):

    template_name = "register.html"

    def __init__(self):
        super(RegisterView, self).__init__()
        self.form = RegistrationForm()

    def get_context(self, request, *args, **kwargs):
        context = {
            'form': self.form
        }
        return context

    def get(self, request, *args, **kwargs):
        return self.render_to_response(self.get_context(request))

    def post(self, request, *args, **kwargs):
        self.form = RegistrationForm(request.POST)
        if self.form.is_valid():
            self.form.save()
            user = auth.authenticate(username=self.form.user.email, password=self.form.str_password)
            auth.login(request, user)
            send([user], 'registration')
            return HttpResponseRedirect("/accounts/personal-data-master/")
        return self.render_to_response(self.get_context(request))
開發者ID:andruwwwka,項目名稱:super5,代碼行數:28,代碼來源:views.py

示例2: create_user

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def create_user(request):
    form = RegistrationForm(request.POST or None)

    if request.method == "POST" and form.is_valid():
        form.save()

        user = authenticate(username=form.cleaned_data["username"],
                password=form.cleaned_data["password1"])
        login(request, user)

        return redirect("accounts:profile")

    return render(request, "accounts/create.html", {
        "form": form,
    })
開發者ID:dstanek,項目名稱:django-tutorial,代碼行數:17,代碼來源:views.py

示例3: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def register(request):
    code = ""
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        email = request.POST['email']
        form = RegistrationForm(request.POST)
        if form.is_valid():
            salt = sha.new(str(random.random())).hexdigest()[:5]
            activation_code = sha.new(salt+username).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(7)
            user = User.objects.create_user(username=username, email=email, password=password)
            user.is_active = False
            user.save()
            profile = form.save(commit=False)
            profile.user = user
            profile.activation_code = activation_code
            profile.key_expires = key_expires
            profile.save()
            return render_to_response('accounts/register.html', 
                {'code':activation_code, 'profile':profile}, context_instance=RequestContext(request))
        else:
            salt = sha.new(str(random.random())).hexdigest()[:5]
            activation_code = sha.new(salt+username).hexdigest()
            return render_to_response('accounts/register.html',
                {'form':form, 'code':activation_code}, context_instance=RequestContext(request))
    else:
        form = RegistrationForm()
        return render_to_response('accounts/register.html',{'form':form, 'code':code})
開發者ID:semillastan,項目名稱:juatsemilla,代碼行數:31,代碼來源:views.py

示例4: login

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def login(request):
    login_form = LoginForm()
    register_form = RegistrationForm()
    
    next = request.REQUEST.get('next', settings.LOGIN_REDIRECT_URL)
    # Special case next urls that will lead us into redirect loops
    if next == settings.LOGIN_URL:
        next = settings.LOGIN_REDIRECT_URL
    
    if 'kind' in request.POST:
        if request.POST['kind'] == 'register':
            register_form = RegistrationForm(request.POST)
            if register_form.is_valid():
                _backend_hackend(request, register_form.save())
                return HttpResponseRedirect(next)
        elif request.POST['kind'] == 'login':
            login_form = LoginForm(request.POST)
            if login_form.is_valid() and login_form.user:
                _backend_hackend(request, login_form.user)
                return HttpResponseRedirect(next)
    context = {
        'login_form': login_form,
        'register_form': register_form,
        'next': next,
    }
    return render_to_response('accounts/login.html', context,
        context_instance=RequestContext(request))
開發者ID:ariel17,項目名稱:servertail,代碼行數:29,代碼來源:views.py

示例5: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
    def register(self, request, **kwargs):
        """
        Create and immediately log in a new user.
        
        """
        invitation_key = kwargs.get('invitation_key', None)
        email = kwargs.get('email', None)
        if request.POST:
            form = RegistrationForm(request.POST)
            if form.is_valid():
                user = form.save(commit=False)
                user.email = email  # email was omitted from form - it's required to use the same email invitation was sent to
                user.save()  # default groups and all pending accesses are automatically assigned - signal
        else:
            return None
        #username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
        #User.objects.create_user(username, email, password)
        
        # authenticate() always has to be called before login(), and
        # will return the user we just created.
        new_user = authenticate(username=user.username, password=form.cleaned_data['password1'])

        login(request, new_user)
        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     invitation_key=invitation_key,
                                     request=request)
        return new_user
開發者ID:bluusystemsinc,項目名稱:bluu,代碼行數:30,代碼來源:backends.py

示例6: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(data=request.POST)
        if form.is_valid():
            user = form.save()
            return redirect('/accounts/register_success')
    else:
        form = RegistrationForm()
    return render(request,'accounts/register.html', {'form':form,})
開發者ID:curlylrt,項目名稱:testsite,代碼行數:11,代碼來源:views.py

示例7: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def register(request):
    next_url = request.GET.get('next', None)
    if request.method == 'GET':
        form = RegistrationForm()
        return render(request, 'registration/registration_page.html', {'registration_form': form})

    if request.method == 'POST':

        # create a form instance and populate it with data from the request
        form = RegistrationForm(request.POST, )
        if form.is_valid():

            client = request.session['client']
            new_user = form.save(commit=False)

            try:  # create a user on the API
                data = client.create_user(new_user.email, request.POST['password1'],
                                          new_user.first_name, new_user.last_name,
                                          new_user.phone_number)

                new_user.booker_id = data.get('CustomerID', None)
                if not new_user.booker_id:
                    raise ValidationError(data['ErrorMessage'],
                                          code=data['ErrorCode'])
                new_user.save()
            except ValidationError as error:
                form.add_error(None, error)
                return render(request, 'registration/registration_page.html',
                              {'registration_form': form})

            # login to the api
            client.login(new_user.email, request.POST['password1'])

            # authenticate and login the user locally
            new_user = authenticate(email=request.POST['email'].lower(),
                                    password=request.POST['password1'])
            auth_login(request, new_user)
            try:
                request.cart.replace(request.session.get('CART-ID'), new_user)
            except CartDoesNotExist:
                pass
            # store the user password for the length of the session
            client.user = new_user

            messages.info(request, 'Thanks for registering. You are now logged in.')

            # redirect user the profile page
            if next_url:
                return HttpResponseRedirect(next_url)
            return HttpResponseRedirect(reverse('welcome'))

        return render(request, 'registration/registration_page.html',
                      {'registration_form': form, 'next': next_url})
開發者ID:headphonesjones,項目名稱:Blohaute,代碼行數:55,代碼來源:views.py

示例8: create_user

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def create_user(request):
    if not request.user.is_authenticated():
        form = RegistrationForm(request.POST or None)

        if request.method == "POST" and form.is_valid():
            form.save()

            user = authenticate(username=form.cleaned_data["username"],
                    password=form.cleaned_data["password1"])
            login(request, user)

            comando = "cd templates/assets/img; mkdir %s" % user.username
            os.system(comando)
            comando = "cd media/photos ;zip %s.zip readme.txr" % user.username
            os.system(comando)
            return HttpResponseRedirect("/slides/")
    else:
        return HttpResponseRedirect("/slides/")

    return render(request, "registration/create_user.html", {
        "form": form,
    })
開發者ID:hugoandregg,項目名稱:converter,代碼行數:24,代碼來源:views.py

示例9: register_user

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def register_user(request):
	if request.method == 'POST':
		form = RegistrationForm(request.POST)
		if form.is_valid():
			obj = form.save()
			return HttpResponse('<meta http-equiv="refresh" content="1;url=/"/>Registration was successfull')
		
	args = {}
	args.update(csrf(request))
	
	args['form'] = RegistrationForm()
	
	return render_to_response('register.html', args)
開發者ID:JakeBeaver,項目名稱:django-website,代碼行數:15,代碼來源:views.py

示例10: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def register(request):
    registration_form = RegistrationForm(request.POST or None, request=request)
    if registration_form.is_valid():
        user = registration_form.save()
        _backend_hackend(request, user)

        return HttpResponseRedirect(request.REQUEST.get('next', '/'))

    context = {
        'registration_form': registration_form,
        'months': range(1, 13),
        'years': range(2011, 2036),
    }
    return TemplateResponse(request, 'accounts/register.html', context)
開發者ID:BetaDesign,項目名稱:clutch,代碼行數:16,代碼來源:views.py

示例11: registration

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def registration(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse("accounts-home"))

    if request.method == "POST":
        form = RegistrationForm(request, request.POST)
        if form.is_valid():
            user = form.save()
            send_activation(user)
            return render(request, "accounts/registration_done.html")
    else:
        form = RegistrationForm(request)

    return render(request, "accounts/registration.html", {"form": form})
開發者ID:harish211,項目名稱:freesound,代碼行數:16,代碼來源:views.py

示例12: registration

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def registration(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse("accounts-home"))

    if request.method == "POST":
        form = RegistrationForm(request, request.POST)
        if form.is_valid():
            user = form.save()
            send_activation2(user)
            return render_to_response('accounts/registration_done.html', locals(), context_instance=RequestContext(request))
    else:
        form = RegistrationForm(request)

    return render_to_response('accounts/registration.html', locals(), context_instance=RequestContext(request))
開發者ID:djzikario,項目名稱:freesound,代碼行數:16,代碼來源:views.py

示例13: registration

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def registration(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('accounts-home'))

    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = form.save()
            send_activation(user)
            return render(request, 'accounts/registration_done.html')
    else:
        form = RegistrationForm()

    return render(request, 'accounts/registration.html', {'form': form})
開發者ID:oriolromani,項目名稱:freesound,代碼行數:16,代碼來源:views.py

示例14: register_user

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def register_user(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        args['form'] = form
        if form.is_valid():
            form.save()  # save user to database if form is valid

            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
            activation_key = hashlib.sha1(salt+email).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(2)

            #Get user by username
            user=User.objects.get(username=username)

            # Create and save user profile
            new_profile = UserProfile(user=user, activation_key=activation_key,
                key_expires=key_expires)
            new_profile.save()

            # Send email with activation key
            email_subject = 'Account confirmation'
            email_body = "Hey %s, thanks for signing up. To activate your account, click this link within \
            48hours http://127.0.0.1:8000/accounts/confirm/%s" % (username, activation_key)

            send_mail(email_subject, email_body, '[email protected]',
                [email], fail_silently=False)

            return HttpResponseRedirect('/accounts/register_success')
    else:
        args['form'] = RegistrationForm()

    return render_to_response('accounts/register.html', args, context_instance=RequestContext(request))
開發者ID:kimozzi,項目名稱:kimozzi,代碼行數:38,代碼來源:views.py

示例15: registration

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import save [as 別名]
def registration(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            password = new_user.password
            new_user.set_password(password)
            create_cloud_container ( new_user.username )
            new_user.save()
            user = authenticate(username=new_user.username, password=password)
            login(request, user)
            return HttpResponseRedirect('/%s' % user.username)
    else:
        form = RegistrationForm()
    return render(request, 'registration.html', {'form': form}, context_instance=RequestContext(request))
開發者ID:Twikie,項目名稱:twikie,代碼行數:17,代碼來源:views.py


注:本文中的accounts.forms.RegistrationForm.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。