Exemplo n.º 1
0
def login_User(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)

        if user != None:
            if user.is_active == True:
                userprofile = user.userprofile

                login(request, user)
                messages.success(request, 'Welcome, %s!' % (username))
                Activity.log_activity("ACTIVITY_LOGIN", user.userprofile)
                next_url = request.GET.get('next', URL_HOME)

                if "//" in next_url and re.match(r'[^\?]*//', next_url):
                    next_url = settings.LOGIN_REDIRECT_URL
                return redirect(next_url)

            else:
                messages.error(request, "You haven't activated your account yet. Please check your email.")
        else:
            messages.error(request, 'Invalid Login credentials. Please try again.')

    next_path = request.GET.get('next', URL_HOME)
    form = AuthenticationForm()
    return render_to_response(HTML_LOGIN, {'form':form}, RequestContext(request, {'next': next_path}))
Exemplo n.º 2
0
def logout_User(request):
    # Update last_logout date field
    user = get_object_or_404(UserProfile, pk=request.user.userprofile.id)
    user.last_logout = datetime.now()
    user.save()

    Activity.log_activity("ACTIVITY_LOGOUT", request.user.userprofile)
    messages.success(request, "See you next time!")
    logout(request)
    return redirect(URL_HOME)