Пример #1
0
def login(request):
    errors = {}
    if request.method == 'POST':
        username = request.POST.get('username', None)
        password = request.POST.get('password', None)
        if not username:
            errors['username'] = '******'
        if not password:
            errors['password'] = '******'
            return render(request, 'client/login-register.html', {
                "type": 1,
                "errors": errors
            })
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login_func(request, user)
                # Force the user logout after 5 minutes of inactivity
                request.session.set_expiry(3000)
                return HttpResponseRedirect('/')
        else:
            errors[
                'username'] = '******'utilisateur ou Mot de passe incorrecte'
    return render(request, 'client/login-register.html', {
        "type": 1,
        "errors": errors
    })
Пример #2
0
    def get(self, request, key):
        verification_key_object = get_object_or_404(VerificationKey, key=key)
        if not verification_key_object.is_valid:
            message = u'Ссылка недействительна, попробуйте получить новую.'
            return self.render_to_response({'message': message})
        user = verification_key_object.user
        if get_user_by_email(user.email):
            message = u'Адрес, который вы пытаетесь подтвердить уже зарегистрирован и подтвержден.'
            return self.render_to_response({'message': message})
        else:
            verification_key_object.unused = False
            verification_key_object.save()
            profile = user.profile
            profile.email_verified = True
            profile.save()
            message = u'Адрес электронной почты %s подтвержден!' % user.email
            messages.info(request, message)

            action_flag = EMAIL_VERIFICATION
            context_dict = {'email': user.email}
            extra = {
                'user': user,
                'obj': profile,
            }
            Logger.objects.create_for_action(action_flag,
                                             context_dict=context_dict,
                                             extra=extra)

            if user.is_active:
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                login_func(request, user)

            return HttpResponseRedirect(reverse('frontpage'))
Пример #3
0
def login(request, template="login.html"):
    if request.method == "POST":
        if request.POST["type"] == "register":
            register_form = RegisterationForm(request.POST)
            login_form = AuthenticationForm()
            if register_form.is_valid():
                user = register_form.save(commit=False)
                user.email = register_form.cleaned_data.get("email")
                user.save()
                profile = Profile.objects.create(user=user)
                send_mail_with_template(u"Selamlar efendim!", user.email, "mails/wellcome.html", {"user": user})
                send_mail_with_template(u"Yeni üye kaydı!", settings.MY_MAIL, "mails/wellcome.html", {"user": user})
                user.backend = "django.contrib.auth.backends.ModelBackend"
                login_func(request, user)
                return redirect("home")
        else:
            login_form = AuthenticationForm(data=request.POST)
            register_form = RegisterationForm()
            if login_form.is_valid():
                login_func(request, login_form.get_user())
                return redirect("home")
    else:
        register_form = RegisterationForm()
        login_form = AuthenticationForm()

    ctx = {"register_form": register_form, "login_form": login_form}

    return render(request, template, ctx)
Пример #4
0
 def register(self, request, form):
     user = User.objects.create_user(
         username=form.cleaned_data.get('username'),
         email=form.cleaned_data.get('email'),
         password=form.cleaned_data.get('password1'))
     login_func(request, user)
     return user
Пример #5
0
 def register(self, request, form):
     user = User.objects.create_user(
         username=form.cleaned_data.get('username'),
         email=form.cleaned_data.get('email'),
         password=form.cleaned_data.get('password1')
     )
     login_func(request, user)
     return user
Пример #6
0
 def register(self, request, form):
     user = User.objects.create_user(
         username=form.cleaned_data.get('username'),
         email=form.cleaned_data.get('email'),
         password=form.cleaned_data.get('password1'))
     authentication = authenticate(
         username=user.username,
         password=form.cleaned_data.get('password1'))
     Profile.objects.create(user=user, name=user.username)
     login_func(request, authentication)
     return user
Пример #7
0
 def post(self, request, verification_key_object):
     user = verification_key_object.user
     form = SetPasswordForm(user, request.POST)
     if form.is_valid():
         form.save()
         verification_key_object.unused = False
         verification_key_object.save()
         if user.is_active:
             user.backend = 'django.contrib.auth.backends.ModelBackend'
             login_func(request, user)
         messages.info(request, u"Пароль пользователя успешно изменён.")
         return HttpResponseRedirect(reverse('frontpage'))
     return self.render_to_response({'form': form, 'user': user})
Пример #8
0
 def register(self, request, form):
     user = User.objects.create_user(
         username=form.cleaned_data.get('username'),
         email=form.cleaned_data.get('email'),
         password=form.cleaned_data.get('password1')
     )
     authentication = authenticate(
         username=user.username,
         password=form.cleaned_data.get('password1')
     )
     Profile.objects.create(user=user, name=user.username)
     login_func(request, authentication)
     return user
Пример #9
0
def login(request):
	if request.method == 'POST':
		username = request.POST['username']
		password = request.POST['password']
		user = authenticate(username=username, password=password)
		if user is not None:
			if user.is_active:
				login_func(request, user)
				if request.GET.get('next', ''):
					return redirect(to = request.POST.get('next', ''))
				else:
					return redirect(to = '/')
			else:
				return notification(request, 'Gebruikeraccount is uitgeschakeld')
		else:
			return notification(request, 'Geen geldige inloggegevens')
	else:
		return render(request, 'login_template.html', {
			'next': request.GET.get('next', ''),
		})
Пример #10
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None

    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()

        # Update the client
        client = Client.objects.filter(user=user)[0]
        client.status = 'Actif'
        client.save()

        login_func(request, user)
        return redirect('home')
    else:
        return render(request, 'mail/mail_invalid.html')
Пример #11
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login_func(request, user)
                if request.GET.get('next', ''):
                    return redirect(to=request.POST.get('next', ''))
                else:
                    return redirect(to='/')
            else:
                return notification(request,
                                    'Gebruikeraccount is uitgeschakeld')
        else:
            return notification(request, 'Geen geldige inloggegevens')
    else:
        return render(request, 'login_template.html', {
            'next': request.GET.get('next', ''),
        })