Exemplo n.º 1
0
def login(request):
    usernameEntered = username = password = ''
    errors = []
    next = request.GET.get('next', '/')
    
    context = get_base_context(request)
    
    if request.POST:
        usernameEntered = request.POST.get('username')
        password = request.POST.get('password')
        next = request.POST.get('next')

        username = usernameEntered

        if len(get_user_model().objects.filter(username=username)) < 1 and len(get_user_model().objects.filter(email=username)) < 1:
            errors = "Your username and/or password are incorrect."
        else:
            user = authenticate(username=username, password=password)
            if user == None and len(get_user_model().objects.filter(email=username)) != 0:
                username = get_user_model().objects.get(email=username).username
                user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    auth_login(request, user)
                    return redirect(request.POST.get('next'))
                else:
                    errors = "Your account is not active, please contact the site admin."
            else:
                errors = "Your username and/or password are incorrect."

    context.update({'logged_in': request.user.is_authenticated(), 'errors':errors, 'username': usernameEntered, 'next': next})
    return render_to_response('openbounty/login.html', context, RequestContext(request))
Exemplo n.º 2
0
def register(request):
    errors = []
    username = email = first = last = password = reenterpassword = ''
    next = request.GET.get('next', '/')
    
    context = get_base_context(request)

    if request.POST:
        username = request.POST.get('username')
        email = request.POST.get('email')
        first = request.POST.get('first')
        last = request.POST.get('last')
        password = request.POST.get('password')
        reenterpassword = request.POST.get('reenterpassword')
        next = request.POST.get('next')

        failed = False

        if username == "":
            errors.append("Username required.")
            failed = True
        elif len(get_user_model().objects.filter(username=username)) != 0:
            errors.append("This username has been used.")
            failed = True
        if first == "":
            errors.append("First Name required.")
            failed = True
        if last == "":
            errors.append("Last Name required.")
            failed = True
        if email == "":
            errors.append("Email required.")
            failed = True
        elif len(get_user_model().objects.filter(email=email)) != 0:
            errors.append("Email already used.")
            failed = True
        if password == "":
            errors.append("Password required.")
            failed = True
        elif password != reenterpassword:
            errors.append("Passwords don't match.")
            failed = True
            
        if not failed:
            print username
            user = get_user_model().objects.create_user(username=username, first_name=first, last_name=last, email=email, password=password)
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    auth_login(request, user)
                    return redirect(request.POST.get('next'))
                else:
                    errors = ["Your account is not active, please contact the site admin."]
            else:
                errors = ["Failed to register."]
            
    errors = "\n".join(errors)
    context.update({'logged_in': request.user.is_authenticated(), 'errors': errors, 'username': username, 'email': email, 'first': first, 'last': last, 'next': next})
    return render_to_response('openbounty/register.html', context, RequestContext(request))
Exemplo n.º 3
0
def profile(request):
    if request.user.is_authenticated():
        user = request.user
        context = get_base_context(request)
        context = venmo(request, context)
        context["committed"] = len(Backing.objects.filter(user=user))
        context["wallet"] = request.user.wallet
        context["name"] = request.user.username
        context["email"] = request.user.email
        try:
            context["started_challenges"] = Challenge.objects.filter(user=user)
        except Challenge.DoesNotExist:
            context["backed_challenges"] = None
        try:
            context["backed_challenges"] = Backing.objects.filter(user=user)
        except Backing.DoesNotExist:
            context["backed_challenges"] = None
        return render(request, "openbounty/profile.html", context)
    else:
        return HttpResponse("You need to login")