Beispiel #1
0
def login(request):
    message = ''
    logname = ''
    if request.session.get('username'):
        return HttpResponseRedirect('/dev')
    if request.POST:
        post = request.POST
        logname = post['name']
        logpassword = post['password']
        if User.objects.filter(username=logname):
            user = auth.authenticate(username=logname, password=logpassword)
            if user is not None:
                if user.is_active:
                    auth.login(request, user)
                    request.session['username'] = logname
                    return HttpResponseRedirect('/dev')
                else:
                    message = 'not active'
            else:
                message = 'password error'
        else:
            message = 'not exist!'
    print message
    return render_to_response('login.html', {'er_message': message,
                                             'postname': logname,
                                             'hot_topic': ''
                                             })
Beispiel #2
0
def registerUser(request):
    elections = getActiveElections()
    if request.method == 'POST':
        if request.POST['password'] == request.POST['secPassword']:
            if request.POST['email'] == request.POST['secEmail']:
                user = User.objects.create_user(username=request.POST['userName'], email=request.POST['email'], password=request.POST['password'])
                user.first_name = request.POST['firstName']
                user.last_name = request.POST['lastName']
                user.save()
                user = auth.authenticate(username=request.POST['userName'], password=request.POST['password'])
                auth.login(request, user)
    return redirect('/')
Beispiel #3
0
def login(request):
            if request.method == 'POST':
                    username = request.POST['username']
                    password = request.POST['password']
                    user = auth.authenticate(username=username,
                                              password=password)
                    if user is not None and user.is_active:
                            auth.login(request, user)
                            return redirect("/")
                    else:
                            request.session['bad_login'] = 1
                            return render_to_response('aboutus/aboutus.html')
Beispiel #4
0
def login(request):
    elections = getActiveElections()
    if request.method == 'POST':
        username = request.POST['login']
        password = request.POST['password']
        user = auth.authenticate(username=username,password=password)                              
        if user is not None and user.is_active:
            auth.login(request, user)
            return redirect('/')
        else:
            request.session['bad_login'] = 1
            return render_to_response('views/aboutUs.html',{'local': locals(), 'elections': elections})
Beispiel #5
0
def register(request):
            if request.method == 'POST':
                    if request.POST['password'] == request.POST['password2']:
                            # Rejestracja
                            user = User.objects.create_user(username=request.POST['user'], email=request.POST['email'], password=request.POST['password'])
                            user.first_name = request.POST['name']
                            user.last_name = request.POST['name2']
                            #user.profile.miasto = request.POST['miasto']

                            user.save()
                            #p = UserProfile(id=user.id)
                            #p.miasto = request.POST['miasto']
                            #p.save()
                            # Logowanie
                            user = auth.authenticate(username=request.POST['user'], 
                                                     password=request.POST['password'])
                            auth.login(request, user)
                            #Redirect
                            return redirect("/")
            return render_to_response('register/index.html', {'local': locals()})
Beispiel #6
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        if username.find('@engg.clg') > 0 or username.find(
                '@engg.uni') > 0 or username.find(
                    '@medi.clg') > 0 or username.find(
                        '@medi.uni') > 0 or username.find(
                            '@oth.clg') > 0 or username.find('@oth.uni') > 0:
            print('wrong format of username')
            return redirect('login_p1')
        else:
            user = auth.authenticate(username=username, password=password)
            if user is not None:
                auth.login(request, user)
                print("user logged-in")
                return redirect('home_p1')
            else:
                print("user not logged-in")
                return redirect('login_p1')
    else:
        return render(request, 'phase1/login.html')
Beispiel #7
0
def login(request):
    if request.user.is_authenticated:
        return redirect('index')

    if request.method == 'POST':
        email = request.POST['email']
        password = request.POST['password']

        attempt = User.objects.filter(email=email.lower()).first()
        if not attempt:
            messages.error(request, 'Invalid Credentials')
            return redirect('login')

        username = attempt.username
        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request, user)
            return redirect('index')
        else:
            messages.error(request, 'Invalid Credentials')
            return redirect('login')
    else:
        return render(request, 'accounts/login.html')
def creatorlogin(request):
    message = None

    if request.method == "POST":
        username = request.POST["username"]
        password = request.POST["password"]
        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request, user)
            user = get_object_or_404(User, username=request.user)

            a = Profile.objects.create(user=user)

            return redirect("donor_detail")
        else:
            message = "Invalid Credentials"
            context = {"message": message}

            return render(request, template_name="creatorlogin.html", context=context)


    else:
        return render(request, template_name="creatorlogin.html")
Beispiel #9
0
def admin_dologin(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        try:
            user = auth.authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                # return HttpResponse("hi")
                if user.user_type == "1":
                    return redirect("admin_home")
                else:
                    messages.error(request, 'Invalid Login Details')
                    return HttpResponseRedirect("admin_login")
            else:
                messages.error(request, 'Invalid Login Details')
                return HttpResponseRedirect("admin_login")
        except:
            messages.error(request, 'Invalid Login Details')
            return HttpResponseRedirect("admin_login")

    else:
        return render(request, 'admin_template/admin_login.html')
def login(request):
    if request.user.is_authenticated:
        return redirect('/student/')
    else:
        if request.method == "POST":
            rollno = request.POST.get('rollno')
            password = request.POST.get('password')

            user = auth.authenticate(username=rollno, password=password)
            
            if (rollno =='library') or (rollno == 'exams') or (rollno == 'accounts') or (rollno == 'transport') or (rollno == 'hostel') or (rollno == 'hod'):
                messages.error(request, "You have to login from the admin panel")
                return redirect('/login/')
            
            elif user is not None:
                auth.login(request, user)
                return redirect('/erp/')

            messages.error(request, "Invalid Credentials")
            return redirect('/login/')

        else:
            return render(request, 'main/login.html')
Beispiel #11
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        
        
        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request, user)
            messages.success(request, 'Login successfull')
            request.session['user_id'] = user.id
            request.session['email'] = user.email

            
            return redirect('index')
            
        
        else:
            messages.error(request,'invalid credentials')
            
            return redirect('login')
    else:
        return render(request,'login.html')
Beispiel #12
0
def login(request):
    global user_name
    engine = pyttsx3.init()
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request, user)
            engine.say("Login Successfully")
            engine.runAndWait()
            user_name = username

            # messages.info(request,'Login Successfully')
            return redirect('home')
        else:
            engine.say("Username or Password is not exist !!!")
            engine.runAndWait()
            messages.info(request, 'Username or Password is not exist !!!')
            return redirect('login')
    else:
        return render(request, 'login.html')
Beispiel #13
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = auth.authenticate(username=username, password=password)

        if user:
            if user.is_active:
                auth.login(request, user)
                return redirect(reverse('dashboard'))

            else:
                messages.warning(
                    request,
                    "Your account is not active. If you've just registered check your inbox for an activation email. Alternatively contact support."
                )
                return redirect(reverse('login'))

        else:
            messages.error(request, 'Invalid username/password')
            return redirect(reverse('login'))
    else:
        return render(request, 'app/login.html')
Beispiel #14
0
def login(request):
    print("hello")
    if request.method == "POST":
        username = request.POST['username']
        password1 = request.POST['password1']
        # user=User.objects.create(username=username,first_name=first_name,last_name=last_name,password1=password1,email=email)
        # user.save();
        # if User.objects.filter(username=username, password1=password1).exists():
        #     print("successfully loggedin!!")
        #     return redirect('ecommerceapp:allProdCat')
        # else:
        #     print("invalid login credentials")
        #     return render(request,'login.html')
        user = auth.authenticate(username=username, password=password1)
        if user is not None:
            auth.login(request, user)
            return redirect('ecommerceapp:allProdCat')
        else:
            messages.info(request, 'invalid details')
            # return redirect('login', user="******")
            return render(request, 'login.html')
    else:
        return render(request, 'login.html')
Beispiel #15
0
def register_views(request):
    form = User_Form(request.POST or None)
    if request.POST:
        email = request.POST.get('email')
        if email.endswith('gmail.com'):
            if form.is_valid():
                user = form.save()
                username = form.cleaned_data.get('username')
                password = form.cleaned_data.get('password')
                user.set_password(password)
                user.save()
                user = auth.authenticate(username=username, password=password)
                if user is not None:
                    login(request, user)
                    return redirect(details_views)
        else:
            context = {
                "form": form,
                "display": "Please Enter Valid Information",
            }
            return render(request, "register.html", context)
    context = {"form": form}
    return render(request, "register.html", context)
Beispiel #16
0
def UserLogIn(request):
    if request.method == 'POST':

        Username = request.POST['username']
        Password = request.POST['password']

        User = auth.authenticate(username=Username, password=Password)
        if User is not None:
            login(request, User)
            if request.user.is_superuser:
                return redirect('/Dashboard')
            else:
                Email = request.POST.get('username')
                password = request.POST.get('password')
                Details = CustomerDetails.objects.get(Username=Email)
                return render(request, 'profile.html', {"user": Details})

        else:
            messages.info(request, 'Wrong Username or Password Please Check')
            return redirect('/Login')
    else:

        return render(request, 'Login.html')
Beispiel #17
0
def signin(request):

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = auth.authenticate(request, username=username, password=password)
        # use= check_password(password1 , password)
        # print(username)
        # print(password)
        # print(username1)
        # print(password1)
        #print(user)

        if user is not None:
            auth.login(request, user)
            return redirect('index')
        else:
            messages.info(request, 'invalid credentials')
            return redirect('signin')

    else:
        return render(request, 'signin.html')
 def post(self, request, *args, **kwargs):
     email=request.POST['email']
     password=request.POST['password']
     user = auth.authenticate(email=email,password=password)
     if user is not None:
         auth.login(request, user)
         # print('a staff logged in')
         if user.is_authenticated and user.is_staff:
             auth.login(request, user)
             # print('a staff logged in')
             return render(request, 'staffpage.html')
         elif user.is_authenticated and user.is_applicant:
             return render(request, 'applicant.html')
         elif user.is_authenticated and user.is_accountant:
             allpayments=finalpayment.objects.all()
             return render(request, 'account1.html', {'allpayments':allpayments})
         elif user.is_authenticated and user.is_admin:
             return render(request, 'admin.html')
         else:
             auth.login(request, user)
             current_user = request.user
             # print('this is a student')
             return render(request, 'student_dashboard.html',{'current_user': current_user})
Beispiel #19
0
def login(request):
    if request.user.is_authenticated == False:
        if request.method == 'POST':
            username = request.POST['username']
            password = request.POST['password']

            user = auth.authenticate(request,
                                     username=username,
                                     password=password)
            if user is not None:
                auth.login(request, user)
                return redirect('/')
            else:
                error = "Wrong Username or Password"
                return render(request, 'accounts/login.html', {
                    'error': error,
                    'username': username,
                    'password': password
                })
        else:
            return render(request, 'accounts/login.html')
    else:
        return redirect('/')
Beispiel #20
0
def login(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']

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

        if user is not None:
            auth.login(request, user)
            if user.groups.exists():
                return redirect('account page')
            # globalUrls = Link.objects.filter(links__name='Global')  # returns queryset using foreign key to where group is Global
            # userGroup = user.groups.all()[0]  # object

            # if (userGroup.name != "Global"):
            #     userUrls = Link.objects.filter(links__name=userGroup.name)  # queryset
            #     links = list(chain(globalUrls, userUrls))  # concat querysets
            #     context = {'links': links, 'Role': userGroup.name}
            # else:
            #     context = {'links': globals}
            # return render(request, 'account.html', context)

            # links = Link.objects.all()
            # category = user.get_group_permissions()
            # category = Group.

            # return render(request, 'account.html', {'links': links}, {'category': category})
            # return render(request, 'account.html', {'links': links})
            else:
                messages.info(request,
                              'Can\'t login without an assigned role!')
                return redirect('/')
        else:
            messages.info(request, 'Invalid Credentials.')
            return redirect('/')
    else:
        return render(request, 'home.html')
Beispiel #21
0
def personalAccount(request):
    if (request.method == "POST"):
        email = request.POST["email"]
        password = request.POST["password"]
        if (User.objects.filter(email=email).exists()):
            customer = User.objects.filter(email=email).first()
            username = customer.username
            user = auth.authenticate(username=username, password=password)
            presence = Presence()
            if user is not None:
                if (customer.is_staff):
                    auth.login(request, user)
                    if (Parcel.objects.filter(email=email).exists()):
                        presence.val = True
                    else:
                        presence.val = False
                    return render(request, "after_login_staff.html", {
                        "presence": presence,
                        "email": email
                    })
                else:
                    auth.login(request, user)
                    if (Parcel.objects.filter(email=email).exists()):
                        presence.val = True
                    else:
                        presence.val = False
                    return render(request, "after_login.html", {
                        "presence": presence,
                        "email": email
                    })
            else:
                messages.info(request, "Wrong Password! Please try again")
                return render(request, "login.html")

        else:
            messages.info(request, "User could not be found! Please try again")
            return render(request, "login.html")
Beispiel #22
0
def userlogin(request):
    if request.method == 'POST':
        if 'create' in request.POST:
            name = request.POST['name']
            email = request.POST['email']
            password = request.POST['password']
            username=email

            if User.objects.filter(username=username).exists():
                messages.error(request,'That username is already taken')
                return redirect('userlogin')
            else:
                user = User.objects.create_user(username=email,password=password,email=email,first_name=name,last_name=name)
                user.save()
                #
                # u_id = User.objects.get(username=email)
                # addusr = UserDetails(user_id=u_id,number=number,address=address)
                # addusr.save()

                messages.success(request,'You are now registered and can log in')
                return redirect('userlogin')

        if 'login' in request.POST:
            username = request.POST['email']
            password = request.POST['password']

            user = auth.authenticate(username=username,password=password)
            if user is not None:
                auth.login(request,user)
                return redirect('/dashboard/')
            else:
                messages.error(request,"Invalid Credentials")
                print("fail")
                return redirect('dashboard')
        else:
            return render(request,'app/userlogin.html')
    return render(request,'app/login.html')
Beispiel #23
0
def login(request):

    if  request.method == ('POST'):
        email = request.POST.get('email')
        password = request.POST.get('password')

# find out how to get the user post data
        #username = username in request.POST
        # password = password in request.POST

        user = auth.authenticate(username=email,password=password)
        

        if user is not None:
            auth.login(request, user)
            return redirect('home')

        else:
            messages.info(request,'Username or password is incorrect')
            return redirect('login')


    else:
        return render(request, 'login.html',)
Beispiel #24
0
def register(request):
    if request.method == 'POST':
        name = request.POST.get('name')
        contact = request.POST.get('contact')
        password = request.POST.get('pass')
        print(name, contact, password)
        if User.objects.filter(username=contact).exists():
            # messages.info(request,'contact already exist')
            return redirect('/register')
        else:
            user = User.objects.create_user(username=contact,
                                            password=password,
                                            first_name=name,
                                            last_name=password)
            user.save()
            print('user created')
            user = auth.authenticate(username=contact, password=password)
            if user is not None:
                auth.login(request, user)
                return redirect('shop')
            else:
                return redirect('seller')
            return redirect('register')
    return render(request, 'user/register.html')
Beispiel #25
0
def login (request) :
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

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

        if user is not None :
            auth.login(request,user)
            # if destination.desti == 1 :
            #     return redirect('destination/destination')
            # else :
            return redirect('/')
        elif username == '':
            messages.error(request, 'Please Enter Your Username')
            return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
        elif password == '' :
            messages.error(request, 'Please Enter Your Password')
            return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
        else :
            messages.error(request, 'Invalid Credentials')
            return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    else :
        return render(request, 'login.html')
Beispiel #26
0
def login(request):
    username = request.data.get("username")
    password = request.data.get("password")
    if username is None or password is None:
        return Response({'error': 'Please provide both username and password'}, status=HTTP_400_BAD_REQUEST)

    user = auth.authenticate(username=username, password=password)
    if not user:
        return Response({'error': 'Invalid Credentials'}, status=HTTP_404_NOT_FOUND)

    if not user.is_staff:
        return activate_account(request, user)
        # return Response({'error': 'Account is not Active'}, status=HTTP_403_FORBIDDEN)

    data = {
        'id' : user.id,
        'username': user.username,
        'first_name': user.first_name,
        'expire':str(datetime.now() + timedelta(days=30))
    }

    token = generate_token(data)
    Token.objects.update_or_create(user_id=user.id, defaults={'token': token})
    return Response({'token': token}, status=HTTP_200_OK)
def login(request):

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = auth.authenticate(username=username, password=password)
        print(type(user))
        if user is not None:
            auth.login(request, user)
            if (user.is_staff == False and user.is_superuser == False):
                return redirect("/patient")
            elif (user.is_staff == True and user.is_superuser == False):
                return redirect("/receptionist")
            elif (user.is_staff == False and user.is_superuser == True):
                return redirect("/doctor")
            elif (user.is_staff == True and user.is_superuser == True):
                return redirect("/hr")
        else:
            print(request, "invalid Credentials")
            messages.info(request, "invalid Credentials")
            return redirect("login")
    else:
        return render(request, 'login.html')
Beispiel #28
0
def logincheck(request):
        print('logincheck')
        response_data = {}
        response_data['access_granted'] = False
        username = request.POST['username']
        password = request.POST['password']    
        print(username)
        print(password)
        user = auth.authenticate(username = username, password=password)
        print('##############LOGIIN###############')
        if user is not None:
            print(username, 'access_granted' )
            resp=  str('Welcome ' + username+ ' you may proceed to login-')
            response_data['access_granted'] = True
            response_data['error'] = resp
            return JsonResponse(response_data)
        else:
            print(username)
            if User.objects.filter(username=username).exists():
                response_data['error'] = 'Invalid Password'
                return JsonResponse(response_data)
            else:
                response_data['error'] = 'Username does not exist'
                return JsonResponse(response_data)
def login(request):
    if request.POST:
        error = False

        if 'username' in request.POST:
            username = request.POST['username']
        else:
            error = True

        if 'password' in request.POST:
            password = request.POST['password']
        else:
            error = True

        if not error:
            user = auth.authenticate(username=username, password=password)

            context = {'name': None}
            context.update(csrf(request))

            if user is not None:
                auth.login(request, user)

    return redirect('diningdeck:index')
def login(request):
    if request.POST:
        error = False

        if 'username' in request.POST:
            username = request.POST['username']
        else:
            error = True

        if 'password' in request.POST:
            password = request.POST['password']
        else:
            error = True

        if not error:
            user = auth.authenticate(username=username, password=password)

            context = {'name': None}
            context.update(csrf(request))

            if user is not None:
                auth.login(request, user)

    return redirect('diningdeck:index')
Beispiel #31
0
def login(request):
    c = {}
    #c.update(csrf(request))
    if request.user.is_authenticated:
        return redirect('/welcome')
    else:
        c = {}
        #c.update(csrf(request))
        if request.method == 'POST':
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)

            if user is not None:
                auth.login(request, user)
                return redirect('/welcome')

            else:
                messages.info(request, 'Username or Password does not match')
                return redirect('/')

        else:
            pass
    return render(request, 'register.html')
Beispiel #32
0
def login(request):
    if request.method == 'POST':
        email = request.POST['email']
        password = request.POST['password']
        user = auth.authenticate(username=email, password=password)
        if user is not None:
            auth.login(request, user)
            if request.user.last_name == "Reception":
                return redirect('reception')
            if request.user.last_name == "HR":
                return redirect('dashboard')
            if user.last_name == "Doctor":
                pro = Doctor.objects.filter(user=user).first()
            if user.last_name == "Patient":
                pro = Patient.objects.filter(user=user).first()
            if pro.verify == '0':
                return redirect('verify')
            else:
                return redirect('profile')
        else:
            messages.info(request, "Invalid Credentials!")
            return redirect('login')
    else:
        return render(request, 'accounts/login.html')
Beispiel #33
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request, user)
            if user.is_superuser:
                request.session['user_loggedin'] = True
                request.session['admin_loggedin'] = True
                request.session.set_expiry(0)
                return redirect(reverse('selectusr'))
            request.session['user_loggedin'] = True
            request.session.set_expiry(0)
            return redirect(reverse('chatmain'))
        else:
            messages.info(request, "Invalid Credentials")
            return redirect(reverse('login'))
    else:
        if request.session.has_key('user_loggedin'):
            return redirect(reverse('chatmain'))
        else:
            return render(request, 'login.html')
Beispiel #34
0
def login(request):

    if request.method == 'POST':

        email = request.POST['email']
        password = request.POST['passwords']
        user = auth.authenticate(email=email, password=password)

        if user is not None:
            u = User.objects.get(email=email)
            if u.type == 'donor':
                auth.login(request, user)
                messages.success(request, 'logged in successfully')
                return redirect('/')
            else:
                messages.success(request, 'invalid credentials')
                return redirect('login')
        else:
            messages.success(request, 'invalid credentials')
            return redirect('login')

    else:

        return render(request, "login.html")
Beispiel #35
0
def logine(request):
    if request.user.is_authenticated:
        if request.user.is_superuser:
            return redirect('admin')
        else:
            return redirect('index')
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = auth.authenticate(username=username, password=password)
        print(username)
        if user is not None:
            if username == 'admin' and password == 'test':
                auth.login(request, user)
                return redirect('admin')

            else:
                auth.login(request, user)
                return redirect('index')
        else:
            messages.error(request, 'Invalid username/password!')
            return HttpResponseRedirect(request.path_info)
    else:
        return render(request, 'login.html')
Beispiel #36
0
def login_confirm(request):
    if request.method == 'POST':
        email = request.POST.get('email')
        password = request.POST.get('password')
        user = auth.authenticate(username=email, password=password)
        if user is not None:
            if user.is_teacher == 1:
                auth.login(request, user)
                tid = User.objects.only("id").get(email=email)
                return render(request, "teacher_navbar_dashboard1.html", {"tea_id": tid.id})
            elif user.is_student == 1:
                auth.login(request, user)
                sid = User.objects.only("id").get(email = email)
                quiz = Quiz_Details.objects.all()[:3]
                user_quiz = {
                    "quizes": quiz,
                    "s_id": sid.id
                }
                return render(request, "student_dash1.html", user_quiz)
        else:
            messages.info(request, 'Invalid Credentials !')
            return redirect('login')
    else:
        return render(request, 'index.html')