def upgrade(request, token=None): profile = request.user.get_profile() organization = get_organization(request) if request.method == 'GET': form = UpgradeForm() organization_form = OrganizationForm(instance=organization) profile_form = EditUserProfileForm( data=dict(title=profile.title, first_name=profile.user.first_name, last_name=profile.user.last_name, username=profile.user.username, mobile_phone=profile.mobile_phone)) return render_to_response("registration/upgrade.html", { 'organization': organization_form, 'profile': profile_form, 'form': form }, context_instance=RequestContext(request)) if request.method == 'POST': form = UpgradeForm(request.POST) organization = Organization.objects.get(org_id=request.POST["org_id"]) organization_form = OrganizationForm(request.POST, instance=organization).update() profile_form = EditUserProfileForm(request.POST) if form.is_valid() and organization_form.is_valid( ) and profile_form.is_valid(): organization.save() invoice_period = form.cleaned_data['invoice_period'] preferred_payment = form.cleaned_data['preferred_payment'] payment_details = PaymentDetails.objects.model( organization=organization, invoice_period=invoice_period, preferred_payment=preferred_payment) payment_details.save() message_tracker = MessageTracker(organization=organization, month=datetime.datetime.today()) message_tracker.save() DataSenderOnTrialAccount.objects.filter( organization=organization).delete() _send_upgrade_email(request.user, request.LANGUAGE_CODE) _update_user_and_profile(request, profile_form) messages.success(request, _("upgrade success message")) if token: request.user.backend = 'django.contrib.auth.backends.ModelBackend' sign_in(request, request.user) Token.objects.get(pk=token).delete() return HttpResponseRedirect(django_settings.LOGIN_REDIRECT_URL) return render_to_response("registration/upgrade.html", { 'organization': organization_form, 'profile': profile_form, 'form': form }, context_instance=RequestContext(request))
def login(request): email = request.POST['email'] password = request.POST['password'] user = authenticate(request, username=email, password=password) next = request.GET.get("next") if user is not None: sign_in(request, user) return redirect(next) else : error_message = 'Incorrect username or password' return render(request, 'authenticate/auth.html', {'error': error_message, 'form': SignUpForm(), 'active_tab': 'login', "next": next })
def activate(request, uidb64, token): try: uid = force_text(urlsafe_base64_decode(uidb64)) user = User.objects.get(pk=uid) except(TypeError, ValueError, User.DoesNotExist, OverflowError): user = None if user is not None and account_activation_token.check_token(user, token): user.is_active = True user.save() sign_in(request, user) return redirect(reverse('home')) else: return HttpResponse("This link is no longer valid, please sign up again")
def login(request): if request.method == "POST": accountID = request.POST['accountID'] password = request.POST['password'] user = authenticate(account_id=accountID, password=password) # user = authenticate(username=accountID, password=password) if user is not None: # messages.success(request, 'Login Success') sign_in(request, user) return redirect('inventori:index') else: messages.error(request, 'Login Gagal') return redirect('account:login') # return redirect_login(request)] return render(request, "page_login.html", {'formRegister': RegisterForm()})
def custom_password_reset_confirm(request, uidb36=None, token=None, set_password_form=SetPasswordForm, template_name='registration/datasender_activate.html'): response = password_reset_confirm(request, uidb36=uidb36, token=token, set_password_form=set_password_form, template_name=template_name) if request.method == 'POST' and type(response) == HttpResponseRedirect: try: uid_int = base36_to_int(uidb36) user = User.objects.get(id=uid_int) except (ValueError, User.DoesNotExist): return response user.backend = 'django.contrib.auth.backends.ModelBackend' sign_in(request, user) redirect_url = django_settings.DATASENDER_DASHBOARD + '?activation=1' \ if user.get_profile().reporter else django_settings.HOME_PAGE return HttpResponseRedirect(redirect_url) return response
def login(request): ctx = {} if request.method == 'POST': email = request.POST.get('email', None) passwd = request.POST.get('password', None) if email and passwd: user = authenticate(request, username=email, password=passwd) else: ctx.update({'error': 'Форма содержит пустые поля.'}) # import pdb # pdb.set_trace() if user is not None and user.is_active: sign_in(request, user) return redirect(to=reverse('site_index'), args=('asdfg', 123)) else: ctx.update({ 'error': 'Пользователь не активен или неверные учётные данные.' }) return render(request, template_name='login.html', context=ctx)
def register(request): if request.method == 'POST': form = ExtendedUserCreationForm(request.POST) profile_form = UserProfileForm(request.POST) if form.is_valid() and profile_form.is_valid(): user = form.save() profile = profile_form.save(commit=False) profile.user = user profile.save() username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = authenticate(username=username, password=password) sign_in(request, user) return redirect('home:index') else: form = ExtendedUserCreationForm() profile_form = UserProfileForm() context = {'form': form, 'profile_form': profile_form} return render(request, 'auth/register.html', context)