Ejemplo n.º 1
0
def get_footer(request):
    context = dict()
    context['csrf_token'] = request.COOKIES.get('csrftoken')
    context['login_form'] = LoginForm(request.POST) if request.method == 'POST' else LoginForm()
    context['register_form'] = RegisterForm(request.POST) if request.method == 'POST' else RegisterForm()
    context['footer_clients'] = StaticFooterPage.objects.filter(menu_type=0)
    context['footer_partners'] = StaticFooterPage.objects.filter(menu_type=1)
    return render_to_string('parts/footer.html', context=context)
Ejemplo n.º 2
0
 def test_1_invalid_login(self):
     """
     Testing user login with wrong user name and/or password
     """
     self.data['email'] = ''
     form = LoginForm(data=self.data)
     # test fails. need to check one more time.
     self.assertFalse(form.is_valid())
Ejemplo n.º 3
0
 def test_1_invalid_login(self):
     """
     Testing user login with wrong user name and/or password
     """
     self.data['email'] = ''
     form = LoginForm(data=self.data)
     #test fails. need to check one more time.
     self.assertFalse(form.is_valid())
Ejemplo n.º 4
0
def user_login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            user = authenticate(username=cd['username'],
                                password=cd['password'])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    if Group.objects.get(user=user) == Group.objects.get(
                            name='U'):
                        return render(request, 'student/dashboard.html')
                    elif Group.objects.get(user=user) == Group.objects.get(
                            name='R'):
                        return render(request, 'repair/dashboard.html')
                else:
                    form = LoginForm()
                    return render(request, 'registration/login.html', {
                        'form': form,
                        'error': "您的账号或者密码不正确!"
                    })
            else:
                form = LoginForm()
                return render(request, 'registration/login.html', {
                    'form': form,
                    'error': "您的账号或者密码不正确!"
                })
    else:
        form = LoginForm()
    return render(request, 'registration/login.html', {'form': form})
Ejemplo n.º 5
0
def login(request):
    if request.method=='POST':
        forms = LoginForm(request.POST)
        if forms.is_valid():                
            user = auth.authenticate(username=forms.cleaned_data['username'],password=forms.cleaned_data['password'])             
            if user is not None and user.is_active:
                auth.login(request, user)
                print('Output from',__file__,'logged in succesfully!')
                return redirect(settings.LOGIN_REDIRECT_URL)
            else:
                return render(request, 'account/login.html',{'status':'ERROR Incorrect username or password'})    
        else:
            return render(request, 'account/login.html',{'status':'ERROR Incorrect username or password'})
    else:
        return render(request,'account/login.html')
Ejemplo n.º 6
0
def register(request):
    if request.method == 'POST':
        user_form = UserRegistrationForm(request.POST)
        if user_form.is_valid():
            # Create a new user object but avoid saving it yet
            new_user = user_form.save(commit=False)
            # Set the chosen password
            new_user.set_password(user_form.cleaned_data['password'])
            # Save the User object
            new_user.save()
            # add the user to group
            if request.POST.get('name') == 'U':
                group = Group.objects.get(name='U')
                new_user.groups.add(group)
                student_information = StudentInformation.objects.create(
                    user=new_user)
            elif request.POST.get('name') == 'R':
                group = Group.objects.get(name='R')
                new_user.groups.add(group)
                repair_information = RepairInformation.objects.create(
                    user=new_user)
            form = LoginForm()
            return render(request, 'registration/login.html', {
                'form': form,
                'message': "注册成功,请登录!"
            })
    else:
        user_form = UserRegistrationForm()
    return render(request, 'account/register.html', {'user_form': user_form})
Ejemplo n.º 7
0
def account_login(request):
  if request.user.is_authenticated():
    return redirect('/account/')

  form  = LoginForm()
  error = None

  if request.method == 'POST':
    form = LoginForm(request.POST)
    if form.is_valid():
      username = request.POST['username']
      password = request.POST['password']
      user = authenticate(email=username, password=password)

      (browser, created) = UserBrowser.objects.get_or_create(
        name=request.META['HTTP_USER_AGENT'])
      if created: browser.save()

      if user and user.is_active:
        '''
          Handle Successful login
        '''
        userLogin = UserLogin.objects.create(
          user=user,
          browser=browser,
          address=get_client_ip(request)
        )
        userLogin.save()
        login(request, user)
        # send message
        messages.add_message(request, messages.SUCCESS, 'Logged in')
        return redirect('/account/')

      else:
        userLogin = InvalidLogin.objects.create(
          user=username,
          browser=browser,
          address=get_client_ip(request)
        )
        userLogin.save()
        error = 'Invalid username or password.' 
        
  return render_to_response('account/login.html', {
    'form': form,
    'error': error
  },
  context_instance=RequestContext(request))
Ejemplo n.º 8
0
 def test_0_valid_login(self):
     """
     Testing user login with clean form data
     """
     form = LoginForm(data=self.data)
     self.assertTrue(form.is_valid())
Ejemplo n.º 9
0
 def test_0_valid_login(self):
     """
     Testing user login with clean form data
     """
     form = LoginForm(data=self.data)
     self.assertTrue(form.is_valid())