コード例 #1
0
ファイル: views.py プロジェクト: psyonara/agonizomai
def account_login(request):
    if request.user.is_authenticated():
        return redirect('home')
    else:
        if request.POST:
            login_form = LoginForm(request.POST)
            if login_form.is_valid():
                users = UserAccount.objects.filter(email=login_form.cleaned_data['email'].lower())
                if len(users) > 0:
                    user = authenticate(email=users[0].email, password=login_form.cleaned_data['password'])
                    if user is not None:
                        if user.is_active:
                            login(request, user)
                            return HttpResponseRedirect(request.POST['next'])
                    else:
                        # user does not authenticate
                        errors = ErrorList()
                        errors = login_form._errors.setdefault(forms.NON_FIELD_ERRORS, errors)
                        errors.append('The password for this account is incorrect.')
                else:
                    # user doesn't exist
                    errors = ErrorList()
                    errors = login_form._errors.setdefault(forms.NON_FIELD_ERRORS, errors)
                    errors.append('There is no account registered with this e-mail address.')
        else:
            login_form = LoginForm()
        return render(request, 'general/login.html', {'form': login_form, 'next': request.GET['next'] if request.GET and 'next' in request.GET.keys() else None})
コード例 #2
0
 def post(self, request):
     form = LoginForm(request.POST)
     if not form.is_valid():
         return render(request, "login.html", {"form": form})
     user = authenticate(request=request,
                         username=form.cleaned_data['username'],
                         password=form.cleaned_data['password'])
     if user is None:
         messages.add_message(request, messages.WARNING,
                              'Profil o podanych danych nie istnieje.')
         return redirect('login')
     login(request, user)
     messages.add_message(request, messages.SUCCESS,
                          'Zostałeś poprawnie zalogowany.')
     return redirect('index')
コード例 #3
0
ファイル: views.py プロジェクト: isaiahiyede/lvtv
def userlogin(request):
    context = {}
    username = ""
    context['login_form'] = LoginForm()

    if request.method == "POST":
        form = LoginForm(data=request.POST)

        if form.is_valid:
            email = request.POST.get('email').strip()
            password = request.POST.get('password').strip()

            user_account = User.objects.filter(
                (Q(email=email) | Q(useraccount__phone_number=email)))

            if not user_account.exists():
                context['email_not_found'] = True
                context['email'] = email
                return render(request, 'general/login.html', context)

            if user_account.exists():
                username = user_account[0].username
            auth_user = authenticate(username=username, password=password)

            if auth_user is not None:
                user = auth_user

                if user.is_active:
                    login(request, user)

                    if user.is_staff:
                        response = redirect(reverse('lvtvAdmin:admin_views'))
                        return response

                    else:
                        response = redirect(reverse("client:client_views"))
                        return response
            else:
                # print "No details found for %s" %(email)
                context['no_record_found'] = True
            return render(request, 'general/login.html', context)
    else:
        return render(request, 'general/login.html', context)
    context = {}
    template_name = 'general/login.html'
    return render(request, template_name, context)
コード例 #4
0
ファイル: views.py プロジェクト: jmjacquet/laboralsalud
def login(request):
    from usuarios.views import ver_permisos
    error = None
    ROOT_URL='/'
    request.session.clear()
    if request.user.is_authenticated():
      return HttpResponseRedirect(ROOT_URL)
       
    form = LoginForm(request.POST or None) 
    # if empresa.mantenimiento == 1:
    #     return render_to_response('mantenimiento.html', {'dirMuni':MUNI_DIR,'sitio':sitio},context_instance=RequestContext(request))
    
    if form.is_valid():                
        usuario = form.cleaned_data['usuario']        
        clave = form.cleaned_data['password']
        empresa = form.cleaned_data['empresa']
        user =  authenticate(usuario=usuario, clave=clave,empresa=empresa)               
        if user is not None:
          if user.is_active:                        
            django_login(request, user)            
            if empresa:
              request.session["empresa"] = empresa.pk                     
              # request.session["permisos"] = list(ver_permisos(request))
              # request.session["permisos"] = list(ver_permisos(request))

            ROOT_URL = reverse('principal')              
            return HttpResponseRedirect(ROOT_URL)
          else:
          ## invalid login
           error = u"Usuario/Contraseña/Empresa incorrectos."
        else:
          ## invalid login
           error = u"Usuario/Contraseña/Empresa incorrectos."
          #return direct_to_template(request, 'invalid_login.html')
    if error:
      messages.add_message(request, messages.ERROR,u'%s' % (error))    
   
    template = 'login.html'      
            
    return render(request,template,{'msj':messages,'form':form})
コード例 #5
0
ファイル: views.py プロジェクト: Crowdcomputer/CC
def Login(request):
    if request.user.is_authenticated():
        return redirect('/')
    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:
                redirect_to = request.REQUEST.get('next', '')
                login(request, user)
                return HttpResponseRedirect(redirect_to)
            else:
                messages.info(request,'username and password not valid')
                return render_to_response('general/login.html', {'form': form}, context_instance=RequestContext(request))
        else:
            return render_to_response('general/login.html', {'form': form}, context_instance=RequestContext(request))
    else:
        form = LoginForm()
        context = {'form': form}
        return render_to_response('general/login.html', context, context_instance=RequestContext(request))
コード例 #6
0
def user_login(request):
    # check if the form was submitted
    if request.method == 'POST':
        # grab the form
        form = LoginForm(request.POST)
        # validation of the form
        if form.is_valid():
            # cleaned up data from form
            cd = form.cleaned_data
            username = cd['username']
            password = cd['password']
            # authenticate with the user record
            user = authenticate(username=username, password=password)
            # check if login credentials are authentic
            if user:
                # login the user to django session
                login(request, user)
                return redirect('groups')
            else:
                # re-display form with error message
                # the same form
                form = LoginForm()
                # the error
                error = 'Invalid Username/Password'
                # template parameters to display
                parameters = {'form': form, 'error': error}
                # re-render the template
                return render(request, 'users/login.html', parameters)
    else:
        # display the form for submission
        form = LoginForm()
        # the template parameters
        parameters = {
            'form': form,
        }
        # render the login template
        return render(request, 'users/login.html', parameters)
コード例 #7
0
 def get(self, request):
     if request.user.id is not None:
         return redirect('index')
     return render(request, "login.html", {"form": LoginForm()})
コード例 #8
0
ファイル: sokohali_views.py プロジェクト: isaiahiyede/izzyUzo
    def post(self, request, *args, **kwargs):
        request = self.request

        #next = request.GET.get('next', '')
        if request.GET.has_key('next'):
            next_page = request.GET['next']
        #get next from cookies, if user is most likely a first timer
        elif request.COOKIES.has_key('next_page'):
            next_page = request.COOKIES["next_page"]
        else:
            next_page = ""

        error_msg = "There was an error with your E-Mail/Password combination. Please check and try again."

        form = LoginForm(request.POST)

        if form.is_valid():
            data_gotten = str(request.POST.get('username_email')).strip()
            print 'data gottem: ', data_gotten
            if '@' in data_gotten:
                try:
                    username_email = Subscriber.objects.get(
                        user__email=data_gotten).user.username
                except:
                    error_msg = "Email not found"
                    messages.warning(request, error_msg)
                    return redirect(request.META.get('HTTP_REFERER', '/'))
            else:
                try:
                    username_email = data_gotten
                except:
                    error_msg = "Username not found"
                    messages.warning(request, error_msg)
                    return redirect(request.META.get('HTTP_REFERER', '/'))

            password = form.cleaned_data['password']
            # print username_email
            user = authenticate(username=username_email, password=password)
            print "User", user
            # if not user:
            # 		user = sokohali_authenticate(username = username_email, password=password)
            if user is None:  # or useraccount is None:
                messages.warning(request, error_msg)
                return redirect(request.META.get('HTTP_REFERER', '/'))

            else:
                redirect_to = next_page
                print 'user: '******'':
                                response = redirect(
                                    reverse("sokohaliAdmin:client_dashboard"))
                            else:
                                response = redirect(redirect_to)
                    elif user.subscriber:
                        if redirect_to == '':
                            response = redirect(
                                reverse("sokohaliAdmin:client_dashboard"))
                        else:
                            response = redirect(redirect_to)
                    else:
                        response = redirect(reverse("access_denied"))

                    return response

                else:
                    error_msg = "Sorry, you need to activate your account before you can log-in.\
														Please contact customer service. Thank you."

                    messages.warning(request, error_msg)
                    return redirect(request.META.get('HTTP_REFERER', '/'))

            # else:
            #     redirect_to = next_page
            #     print 'user: '******'':
            #                 response = redirect (reverse ("sokohaliAdmin:client_dashboard"))
            #             else:
            #                 response = redirect(redirect_to)
            #         else:
            #             response = redirect (reverse ("access_denied"))
            #
            #         return response
            #
            #             #return redirect(redirect_to)
            #     else:
            #         error_msg = "Sorry, you need to activate your account before you can log-in.\
            #                         Please contact customer service. Thank you."
            #         messages.warning(request, error_msg)
            #         return redirect (request.META.get('HTTP_REFERER', '/'))

        else:
            #print form.errors
            messages.warning(request, error_msg)
            return redirect(request.META.get('HTTP_REFERER', '/'))