Beispiel #1
0
 def post(self, request, *args, **kwargs):
     form = LoginForm(request.POST, request=request)
     if form.is_valid():
         user = authenticate(username=request.POST.get('email'),
                             password=request.POST.get('password'))
         if user is not None:
             if user.is_active:
                 login(request, user)
                 return HttpResponseRedirect('/')
             else:
                 return render(
                     request, "login.html", {
                         "error":
                         True,
                         "message":
                         "Your Account is InActive. Please Contact Administrator"
                     })
         else:
             return render(
                 request, "login.html", {
                     "error":
                     True,
                     "message":
                     "Your Account is not Found. Please Contact Administrator"
                 })
     else:
         return render(
             request, "login.html", {
                 "error":
                 True,
                 "message":
                 "Your username and password didn't match. Please try again."
             })
Beispiel #2
0
def login_view(request):
    if request.method == 'POST':
        next_url = request.POST.get('next', 'index')
        form = LoginForm(request.POST)
        if form.is_valid():
            username = get_user(form.cleaned_data.get('email'))
            if not username:
                return render(request, 'auth/login.html', {
                    'form': form,
                    'error': _("User not found")
                })
            _user = authenticate(username=username,
                                 password=form.cleaned_data.get('password'))
            if _user is not None:
                if _user.is_active:
                    login(request, _user)
                    return redirect(next_url)
                return render(request, 'auth/login.html', {
                    'form': form,
                    'error': _("Account Disabled")
                })
            return render(request, 'auth/login.html', {
                'form': form,
                'error': _("Invalid login credentials")
            })
        return render(request, 'auth/login.html',
                      {'form': form})  # form errors
    form = LoginForm()
    return render(request, 'auth/login.html', {'form': form})
Beispiel #3
0
def login_crm(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect('/')
    if request.method == 'POST':
        form = LoginForm(request.POST, request=request)
        if form.is_valid():
            user = authenticate(username=request.POST.get('email'),
                                password=request.POST.get('password'))
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect('/')
                else:
                    return render(request, "login.html", {
                        "error": True,
                        "inactiveuser": form.errors
                    })
            else:
                return render(request, "login.html", {
                    "error": True,
                    "usernone": form.errors
                })
        else:
            return render(request, "login.html", {
                "error": True,
                "errors": form.errors
            })
    return render(request, 'login.html')
Beispiel #4
0
def login_2(request):
    """
    """
    logged_user = user_form(request)
    if logged_user:
        return redirect('/accueil')
    form = LoginForm(data=request.POST or None)
    if form.is_valid():
        user_pseudo = form.cleaned_data['pseudo']
        user_password = form.cleaned_data['password']
        user = authenticate(request,
                            username=user_pseudo,
                            password=user_password)
        if user:
            if user.is_active:
                logi(request, user)
                #request.session.set_expiry(0)
                url = request.META['HTTP_REFERER'].split('=')
                if len(url) == 2:
                    return redirect(url[1])
                return redirect('/accueil')
        return render(request, 'login.html', {
            'form': form,
            'info': "Identifiant et/ou mot de passe incorrecte."
        })
    return render(request, 'login.html', {'form': form})
Beispiel #5
0
def manager_login(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.appuser.account_type == AppUsers.MANAGER:
                    login(request, user)
                    # Redirect to manager subdomain
                    return redirect("http://manager.osmith.me")
                else:
                    return render(request, "login_error.html",
                                  {"form": form, "account_type": "manager", "error_message": "domain_error"})
            else:
                form = LoginForm()
                return render(request, "login_error.html",
                              {"form": form, "account_type": "manager", "error_message": "incorrect"})
        else:
            return render(request, "login_error.html",
                          {"form": form, "account_type": "manager", "error_message": "invalid"})
    else:
        form = LoginForm()
        return render(request, "login.html", {"form": form, "account_type": "manager"})
Beispiel #6
0
def login(request):
    if request.method == 'GET':
        return render(request, 'common/login.html')
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid() and form.errors == {}:
            user = User.objects.filter(
                phone=form.cleaned_data.get('mobile')).first()
            request.session['user_id'] = user.id
            return HttpResponseRedirect(reverse('common:checked_index'))
        errors = form.errors
        return render(request, 'common/login.html', {'errors': errors})
Beispiel #7
0
 def post(self, request):
     form = LoginForm(data=request.POST)
     if form.is_valid():
         user = authenticate(
             request,
             username=form.cleaned_data["username"],
             password=form.cleaned_data["password"],
         )
         if user:
             login(request, user)
             return HttpResponseRedirect(reverse("success"))
     return render(request, "login_page.html", {"login_form": form})
Beispiel #8
0
    def post(self, request, *args, **kwargs):
        form = LoginForm(request.POST, request=request)
        if form.is_valid():

            user = User.objects.filter(email=request.POST.get('email')).first()
            # user = authenticate(username=request.POST.get('email'), password=request.POST.get('password'))
            if user is not None:
                if user.is_active:
                    user = authenticate(username=request.POST.get(
                        'email'), password=request.POST.get('password'))

                    if user is not None:
                        login(request, user)
                        if user.has_sales_access:
                            return HttpResponseRedirect('/')
                        elif user.has_marketing_access:
                            return redirect('marketing:dashboard')
                        else:
                            return HttpResponseRedirect('/')
                    return render(request, "login.html", {
                        "ENABLE_GOOGLE_LOGIN": settings.ENABLE_GOOGLE_LOGIN,
                        "GP_CLIENT_SECRET": settings.GP_CLIENT_SECRET,
                        "GP_CLIENT_ID": settings.GP_CLIENT_ID,
                        "error": True,
                        "message":
                        "Your username and password didn't match. \
                        Please try again."
                    })
                return render(request, "login.html", {
                    "ENABLE_GOOGLE_LOGIN": settings.ENABLE_GOOGLE_LOGIN,
                    "GP_CLIENT_SECRET": settings.GP_CLIENT_SECRET,
                    "GP_CLIENT_ID": settings.GP_CLIENT_ID,
                    "error": True,
                    "message":
                    "Your Account is inactive. Please Contact Administrator"
                })
            return render(request, "login.html", {
                "ENABLE_GOOGLE_LOGIN": settings.ENABLE_GOOGLE_LOGIN,
                "GP_CLIENT_SECRET": settings.GP_CLIENT_SECRET,
                "GP_CLIENT_ID": settings.GP_CLIENT_ID,
                "error": True,
                "message":
                "Your Account is not Found. Please Contact Administrator"
            })

        return render(request, "login.html", {
            "ENABLE_GOOGLE_LOGIN": settings.ENABLE_GOOGLE_LOGIN,
            "GP_CLIENT_SECRET": settings.GP_CLIENT_SECRET,
            "GP_CLIENT_ID": settings.GP_CLIENT_ID,
            # "error": True,
            # "message": "Your username and password didn't match. Please try again."
            "form": form
        })
Beispiel #9
0
    def post(self, request, *args, **kwargs):
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            try:
                user = authenticate(username=username, password=password)
            except PermissionDenied as p:
                print(p)
            if user:
                login(request, user)
                nextUrl = getNextUrl(request)
                return HttpResponseRedirect(nextUrl)
            else:
                logger.debug('UnAuthorized user...')
                return self.render_form_with_error(request, form,
                                                   'login failed')
Beispiel #10
0
def connexion(request):
    erreur = False
    if request.method == "POST":

        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                next_url = request.POST['next'] or '/'
                return redirect(next_url)
            else:
                erreur = True
    else:
        next_url = request.GET.get('next', '')
        form = LoginForm()

    return render(request, "common/login.html", locals())
Beispiel #11
0
 def post(self, request, *args, **kwargs):
     url = request.GET.get("next")
     login_form = LoginForm(request.POST)
     if login_form.is_valid():
         username = request.POST["username"]
         password = request.POST["password"]
         user = auth.authenticate(username=username, password=password)
         if user is not None and user.is_active:
             auth.login(request, user)
             return HttpResponsePermanentRedirect(request.GET.get("next"))
         else:
             self.context = {
                 "login_form": login_form,
                 "password_is_wrong": True
             }
             return render(request, "common/login.html", self.context)
     else:
         self.context = {
             "login_form": login_form,
             "errors": login_form.errors
         }
         return render(request, "common/login.html", self.context)
Beispiel #12
0
def login(request):
    if request.session.get('is_login', None):
        return redirect(reverse('index'))

    if request.method == "POST":
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            try:
                user = models.User.objects.get(username=username)
                if user.password == hash_code(password):  # 哈希值和数据库内的值进行比对
                    request.session['is_login'] = True
                    request.session['user_id'] = user.id
                    request.session['user_name'] = user.name
                    request.session['user_role'] = user.role
                    return redirect(reverse('index'))
                else:
                    messages.add_message(request, messages.WARNING, '密码不正确')
            except User.DoesNotExist:
                messages.add_message(request, messages.WARNING, '用户不存在')
        return render(request, 'login.html', locals())
    login_form = LoginForm()
    return render(request, 'login.html', locals())