コード例 #1
0
ファイル: views.py プロジェクト: sagar-shirsath/bucksell
def login_me(request):
    if request.user.is_authenticated():
        if request.user.is_superuser:
            return HttpResponseRedirect(reverse("admin:index"))
        else:
            return HttpResponseRedirect(reverse("item_index"))
    form = LoginForm()
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            email= form.cleaned_data['email']
            password = form.cleaned_data['password']
            try:
                user = User.objects.get(email = email)
            except:
                user = None

            if user and user.check_password(password):
                u = authenticate( username = user.username , password = password)
                if u is not None:
                    if u.is_active:
                        login(request,u)
                        if u.is_superuser:
                            return HttpResponseRedirect(reverse("admin:index"))
                        return HttpResponseRedirect(reverse("item_index"))
            request.flash['message'] = "Sorry Email and Password Does Not Match"


    return render_to_response("user_profiles/login.html" ,{'form':form} ,context_instance = RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: Sentech/sentech
def userLogin(request):
  redirect = ''
  redirect = next(request)

  if not request.user.is_authenticated():
    if request.method == 'POST':
      userlogin = LoginForm(request.POST)
      if userlogin.is_valid():
        username = request.POST.get('username')
        password = request.POST.get('password')

        user = authenticate(username=username, password=password)

        if user is not None:
          login(request, user)
          messages.success(request, 'successfully login.')
          return HttpResponseRedirect(redirect)
      else:
        messages.error(request, 'Your username and/or password were incorrect.')
    else:
      userlogin =  LoginForm()
  else :
    messages.warning(request, 'You\'re already connected')
    return HttpResponseRedirect(redirect)

  return render_to_response('login.html', {'login': userlogin} ,context_instance=RequestContext(request))
コード例 #3
0
 def post(self, request, *args, **kwargs):
     form = LoginForm(request.POST or None)
     if form.is_valid():
         username = form.cleaned_data['username']
         password = form.cleaned_data['password']
         user = authenticate(username=username, password=password)
         if user:
             login(self.request, user)
             return HttpResponseRedirect('/')
     context = {'form': form}
     return render(self.request, self.template, context)
コード例 #4
0
 def post(self, request):
     redirect_to = request.POST.get(REDIRECT_FIELD_NAME,
                                    request.GET.get('next', ''))
     creds = request.POST
     form = LoginForm(creds)
     if form.is_valid():
         login(request, form.get_user())
         return HttpResponseRedirect(redirect_to)
     else:
         return render(request, 'registration/login.html', {
             'form': form,
             'next': redirect_to
         })
コード例 #5
0
ファイル: views.py プロジェクト: jtl4br/cs3240-s17-team23
def upload_file(request):
    if 'loggedIn' not in request.session:
        request.session['loggedIn'] = False
    if request.session['loggedIn'] == False:
        form = LoginForm()
        return render(request, 'logintemp.html', {'form': form})
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            #handle_uploaded_file(request.FILES['file'])
            #return HttpResponseRedirect('/success/url/')
            print(request.FILES)
            return render(request, 'success2.html')
    else:
        form = UploadFileForm()
    return render(request, 'upload.html', {'form': form})
コード例 #6
0
def login(request):
    if request.session.get('user_id'):
        return redirect('registration:profile')

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            person = Person.objects.get(name=form.cleaned_data['name'])
            messages.success(request, 'Login successfully')
            request.session['user_id'] = person.id
            return redirect('registration:profile')
    else:
        form = LoginForm()

    return render(request, 'registration/login.html', {'form': form})
コード例 #7
0
def login_view(request):
    """Логин"""
    form = LoginForm()
    if request.method == 'POST':
        form = LoginForm(request.POST)
        success_url = reverse('main:main')

        if form.is_valid():
            username = form.cleaned_data.get('login')
            password = form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)

            if user and user.is_active:
                login(request, user)
                return redirect(success_url)

    return render(request, 'login.html', {'form': form})
コード例 #8
0
ファイル: views.py プロジェクト: HarshChaudhari/Registration
def login(request):
   username = "******"
   
   if request.method == "POST":
      #Get the posted form
      MyLoginForm = LoginForm(request.POST)
      
      if MyLoginForm.is_valid():
         username = MyLoginForm.cleaned_data['username']
         password1 = MyLoginForm.cleaned_data['password']
         if not Profile1.objects.filter(name=username).filter(password = password1):
                return render(request, 'login.html', {"error_message" : 'Incorrect username/password'})
                
   else:
      MyLoginForm = LoginForm()
		
   return render(request, 'loggedin.html', {"username" : username})
コード例 #9
0
ファイル: views.py プロジェクト: nava45/d
def login_page(request, _next="/home/"):
    if not request.user.is_anonymous():
        return redirect('/home/')
    
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            login(request, form.get_user())
            return redirect(_next)
    else:
        form = LoginForm()
        
    return render(
                  request,
                  'registration/login.html',
                  {'form': form, 'next': _next, 'title': "Please Login"}
                  )
コード例 #10
0
ファイル: views.py プロジェクト: marichards/media-db
def login(request, *args, **kwargs):
    # we'll need these forms (in one form or another)
    next=get_next(request)
    added_context={
        'login_form': LoginForm(),
        'registration_form': RegistrationForm(),
        'next': next,
        }
    
    # get request?
    if request.method.lower()=='get':
        return render(request, 'registration/login.html', added_context)
        
    # login attempt:
    login_form=LoginForm(request.POST)
    added_context['login_form']=login_form
    if not login_form.is_valid():
        added_context['login_form']=LoginForm(request.POST).reformat_errors()
        return render(request, 'registration/login.html', added_context)

    username=request.POST['username']
    password=request.POST['password']
    try:
        user=User.objects.get(username=username)
        log.debug('attempting to login %s' %  username)
    except User.DoesNotExist:
        log.info('login attempt from unknown user "%s"' % username)
        login_form.errors.msgs.append('unknown user "%s"' % username)
        return render(request, 'registration/login.html', added_context)
        
    user=auth.authenticate(username=username, password=password)
    if user is None:
        log.info('incorrect user/password for user %s' % username)
        login_form.errors.msgs.append('incorrect user/password')
        return render(request, 'registration/login.html', added_context)
    else:
        auth.login(request, user)
        log.info('user logged in: %s' % username)

    if not next or next==reverse('logout') or next==reverse('login'):
        next=reverse('user_profile', args=(username,))
    return redirect(next)
コード例 #11
0
def index(request):
    form = LoginForm()
    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:
                # if username == 'majnu':
                if user.is_superuser:
                    login(request, user)
                    return redirect('/mca/')
                else:
                    login(request, user)
                    return redirect('/student/')
            else:
                messages.error(request, 'invalid credentials')

    return render(request, 'registration/index.html', {'form': form})
コード例 #12
0
 def get(self, request):
     redirect_to = request.GET.get('next', '')
     if not redirect_to:
         redirect_to = settings.LOGIN_REDIRECT_URL
     if request.user.is_authenticated:
         return redirect(redirect_to)
     form = LoginForm()
     return render(request, 'registration/login.html', {
         'form': form,
         'next': redirect_to,
     })
コード例 #13
0
def home(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            user = Register.objects.filter(email__exact = email,
                                           password__exact = password)
            if user:
                response = HttpResponseRedirect('/successful_login/')
                request.session['email'] = email
                request.session['password'] = password
                response.set_cookie('email', email, 3600)
                return response
            else:
                return render_to_response('fail_home.html', {'form':form},
                                          context_instance=RequestContext(request))
    else:
        form = LoginForm()
    return render_to_response('index.html', {'form':form},
                              context_instance=RequestContext(request))
コード例 #14
0
ファイル: views.py プロジェクト: adsiiit/IIITM-Portal
def loginrequest(request):
	if request.user.is_authenticated():
		return HttpResponseRedirect('/profile/')
	if request.method == 'POST':
		form = LoginForm(request.POST)
		if form.is_valid():
			username = form.cleaned_data['username']
			password = form.cleaned_data['password']
			signin = authenticate(username=username, password=password)
			if signin is not None:
				login(request, signin)
				return HttpResponseRedirect('/profile/')
			else:
				return render_to_response('registration/login.html', {'form':form, 'ln':"active"}, context_instance=RequestContext(request))
		else:
			return render_to_response('registration/login.html', {'form':form, 'ln':"active"}, context_instance=RequestContext(request))

		
	else:
		form = LoginForm()
		context = {'form': form, 'ln':"active"}
		return render_to_response('registration/login.html', context, context_instance=RequestContext(request))
コード例 #15
0
def viewGroups(request):
    if 'loggedIn' not in request.session:
        request.session['loggedIn'] = False
    if request.session['loggedIn'] == False:
        form = LoginForm()
        return render(request, 'logintemp.html', {'form': form})

    groups = request.user.groups.all()

    groups.noGroups = True
    for g in groups:
        groups.noGroups = False
        break

    return render(request, 'viewGroups.html', {'groups': groups})
コード例 #16
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.authenticate()
        if user:
            return redirect("/todo")
        else:
            return HttpResponse("Login Failed Please enter correct!")
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
コード例 #17
0
def createGroup(request):
    if 'loggedIn' not in request.session:
        request.session['loggedIn'] = False
    if request.session['loggedIn'] == False:
        form = LoginForm()
        return render(request, 'logintemp.html', {'form': form})


    storedUsers = SiteUser.objects.all()  # Get all of the users who have been created

    if request.method == 'POST':

        groupName = request.POST.get('name')
        groupCreator = request.session['username']
        users = request.POST.get('users')


        groups = Group.objects.all()
        groupExists = False
        for group in groups:
            print(group.name)
            if str(group.name) == str(groupName):
                groupExists = True

        if groupExists == False:
            new_group = Group.objects.create(name=groupName)
            groupUsers = str(users)
            groupUsers = groupUsers.split() # Get list of usernames entered, split on whitespace
            storedUsers = SiteUser.objects.all() # Get all of the users who have been created

            for user in groupUsers:
                userExists = False
                for stUser in storedUsers:
                    if str(user) == str(stUser.username):
                        userExists = True

                if userExists == False:
                    return render(request, 'createGroupFailed.html')


            #Always add the current user, since they made the group
            request.user.groups.add(new_group)

            currentUsername = request.user.username

            if groupExists == False:
                for user in storedUsers:        # The already made users
                    for name in groupUsers:     # The list of usernames entered to be added to the group
                        if user.username == name:
                            user.groups.add(new_group)
            #return render(request, 'viewGroups.html')


        
        # Go back to appropriate viewGroups page
        groups = request.user.groups.all()

        groups.noGroups = True
        for g in groups:
            groups.noGroups = False
            break

        return render(request, 'viewGroups.html', {'groups': groups})
    else:
        form = NewGroupForm()
    return render(request, 'createGroup.html', {'form': form})
コード例 #18
0
 def get(self, request, *args, **kwargs):
     form = LoginForm(request.POST or None)
     context = {'form': form}
     return render(self.request, self.template, context)