Example #1
0
def login(request):


    if (request.method == "POST"):
        user = authenticate(username=request.POST['username'], password=request.POST['password'])

        if user is not None:


            if user.is_active:
                messages.add_message(request, messages.SUCCESS, 'Login Successful')
                ulogin(request, user)
                if not request.POST.get('remember_me', None):
                    request.session.set_expiry(0)
                try:
                    if request.GET['next']:
                        return redirect(request.GET['next'])
                except:
                    pass

            else:
                messages.add_message(request, messages.ERROR, 'User inactive')
        else:
            messages.add_message(request, messages.ERROR, 'Login wrong')

    return render(request, "login.html")
Example #2
0
def login(request):

    if (request.method == "POST"):
        user = authenticate(username=request.POST['username'],
                            password=request.POST['password'])

        if user is not None:

            if user.is_active:
                messages.add_message(request, messages.SUCCESS,
                                     'Login Successful')
                ulogin(request, user)
                if not request.POST.get('remember_me', None):
                    request.session.set_expiry(0)
                try:
                    if request.GET['next']:
                        return redirect(request.GET['next'])
                except:
                    pass

            else:
                messages.add_message(request, messages.ERROR, 'User inactive')
        else:
            messages.add_message(request, messages.ERROR, 'Login wrong')

    return render(request, "login.html")
Example #3
0
def userlogin(request):
    username = request.POST.get('username')
    password = request.POST.get('password')
    rdurl = request.POST.get('next')
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            ulogin(request, user)
            return JsonResponse(ResultSet(1, '', {'url': rdurl}).todict())
        else:
            return JsonResponse(ResultSet(0, '用户未激活!').todict())
    else:
        return JsonResponse(ResultSet(0, '账号/密码错误!').todict())
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        print('\n\n11111111\n\n',user,username,password)
        if user is not None : 
            ulogin(request, user)
#            return HttpResponse(request.user.is_authenticated)
            return render(request,'products/home.html')
        else :
            return(render(request,'accounts/login.html'))

    return(render(request,'accounts/login.html'))
Example #5
0
def login(request):
    if request.user.is_authenticated:
        return redirect('/dashboard')
    if request.method == 'GET':
        return render(request, 'authApp/login.html')        
    elif request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(request, username=username, password=password)
        if user is not None:
            ulogin(request, user)
            return redirect('/dashboard')
        else:
            messages.error(request, 'failed to login')
            return redirect('/auth/login')
Example #6
0
def register(request):
    if request.user.is_authenticated:
        return redirect('/dashboard')
    if request.method == 'GET':
        return render(request, 'authApp/register.html', context={
            'regform': RegistrationForm(),
        })
    elif request.method == 'POST':
        regform = RegistrationForm(request.POST)
        if not regform.is_valid():
            return render(request, 'authApp/register.html', context={
                'regform': regform,
            })
        # form valid
        user = regform.save() # registration succeeded
        ulogin(request, user) # user logged in
    return redirect('/dashboard')
def login(request):
    context_dict = {}
    if not request.user.is_authenticated:
        if request.method == 'POST':
            email = request.POST.get('email')
            password = request.POST.get('password')
            user = authenticate(username=email, password=password)
            if user:
                ulogin(request, user)
                return redirect(reverse('dashboard'))
            else:
                messages.error(request, "Email or password is incorrect")
                return redirect(reverse('login'))
        else:
            return render(request, 'login.html', context_dict)
    else:
        return redirect(reverse('dashboard'))
    return render(request, 'login.html', {})
Example #8
0
def login(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)
        if user:
            if user.is_active and has_role(user, Customer):
                ulogin(request, user)
                return HttpResponseRedirect(reverse('engine:c_score'))
            else:
                messages.error(request, "Your account is not active")
                return render(request, 'accounts/user_login.html')
        else:
            messages.error(request, "Invalid Username or Password")
            return render(request, 'accounts/user_login.html')
    else:
        if request.user.is_authenticated:
            return HttpResponseRedirect(reverse('engine:c_score'))
        else:
            return render(request, 'accounts/user_login.html')
Example #9
0
def login(request):
    context = {}
    success = False
    if request.method == 'POST':    
        form = LoginForm(request.POST)
#        context['form'] = form

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

            if user is not None:
                if user.is_active:
                    ulogin(request, user)
                    context['message'] = "Welcome"
                    success = True
                else:
                    context['message'] = "This user account has been disabled."
            else:
                try:
                    user = User.objects.get(username=request.POST['username'])
                    context['message'] = "There is already a user by that name, but that is not the right password. Try again?"
                except User.DoesNotExist:
                    # Create a new user. Note that we can set password
                    # to anything, because it won't be checked; the password
                    # from settings.py will.
                    user = User.objects.create_user(request.POST['username'], request.POST['email'], request.POST['password'])
                    context['message'] = "Welcome new user"
                    success = True
        else:
            context['message'] = "Sorry, something is broken."
    else:
        context['form'] = LoginForm()
    t = loader.get_template('levels/form.html')
    c = RequestContext(request, context)    
    return HttpResponse(content=t.render(c), status=200 if success else 401)