Example #1
0
def login_view(request):
    dict = {}
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            #SQL QUERY
            user = UserModel.objects.filter(username=username).first()
            if not user:
                dict['message'] = 'Incorrect username or password! Please try again!'
            else:
                # Check for the password
                if not check_password(password, user.password):
                    dict['message'] = 'Incorrect password or username! Please try again!'
                else:
                    token = SessionToken(user=user)
                    token.create_token()
                    token.save()
                    response = redirect('/feed/')
                    response.set_cookie(key='session_token', value=token.session_token)
                    return response
        else:
            dict['message'] = "Incorrect password or username! Please try again!"
    else:
        form = LoginForm()

    dict['form'] = form
    return render(request, 'login.html', dict)
Example #2
0
def login_view(
    request
):  # this funtion is for showing the login page for a user that have an account
    response_data = {}  # dictionary
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = UserModel.objects.filter(username=username).first()

            if user:
                if check_password(password, user.password):
                    token = SessionToken(user=user)
                    token.create_token()
                    token.save()
                    response = redirect('feed/')
                    response.set_cookie(key='session_token',
                                        value=token.session_token)
                    return response
                else:
                    ctypes.windll.user32.MessageBoxW(
                        0, u"invalid username or password", u"Error",
                        0)  # to show message box
                    response_data[
                        'message'] = 'Incorrect Password! Please try again!'
            else:
                ctypes.windll.user32.MessageBoxW(0,
                                                 u"invalid username/password",
                                                 u"Error", 0)

    elif request.method == 'GET':
        form = LoginForm()
    response_data['form'] = form
    return render(request, 'login.html', response_data)
Example #3
0
def login_view(request):
    dict = {}
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = UserModel.objects.filter(username=username).first()
            if user:
                # Check for the password
                if not check_password(password, user.password):
                    dict['message'] = 'Incorrect Password! Please try again!'
                #Creating session for user if user is found
                else:
                    print "Login was successfull"
                    token = SessionToken(user=user)
                    token.create_token()
                    token.save()
                    response = redirect('/feed/')
                    response.set_cookie(key='session_token', value=token.session_token)
                    return response
            else:
                print "Username is incorrect"
                dict['message'] = "Username is incorrect or user does not exist."
    else:
        form = LoginForm()
    dict['form'] = form
    return render(request, 'login.html', dict)
Example #4
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash('Successfully login')
        # flash('Login requested for user {}, remember_me={}'.format(form.username.data, form.remember_me.data))
        return redirect(url_for('index'))
    return render_template('login.html', title='Sign In', form=form)
Example #5
0
def login_view(request):
    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 is not None:
                # the password verified for the user
                if user.is_active:
                    print("User is valid, active and authenticated")
                    login(request, user)
                    return HttpResponseRedirect('/')
                else:
                    print(
                        "The password is valid, but the account has been disabled!"
                    )
            else:
                # the authentication system was unable to verify the username and password
                print("The username and password were incorrect.")

    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
Example #6
0
def login_view(request):
    try:
        cart_id = request.session['cart_id']
        cart = Cart.objects.get(id=cart_id)
        request.session['total'] = cart.items.count()
    except:
        cart = Cart()
        cart.save()
        cart_id = cart.id
        request.session['cart_id'] = cart_id
        cart = Cart.objects.get(id=cart_id)
    form = LoginForm(request.POST or None)
    #categories = Category.objects.all()
    if form.is_valid():
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        # raise ValueError('A very specific bad thing happened.')
        aunth_user = authenticate(username=username, password=password)
        if aunth_user:
            login(request, aunth_user)
            return HttpResponseRedirect(reverse('main_page'))
    context = {
        'form': form,
        # 'categories': categories
    }
    return render(request, 'login.html', context)
Example #7
0
def login_view(request):
    response_data = {}
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = User.objects.filter(username=username).first()

            if user:
                if check_password(password, user.password):
                    token = SessionToken(user=user)
                    token.create_token()
                    token.save()
                    response = redirect('/feed')
                    response.set_cookie(key='session_token', value=token.session_token)
                    return response

                else:
                    response_data['message'] = 'Incorrect Password! Please try again!'

    elif request.method == 'GET':
        form = LoginForm()

    response_data['form'] = form
    return render(request, 'login.html', response_data)
Example #8
0
def login():
    form = LoginForm(csrf_enabled=False)
    if form.validate_on_submit():
        flash(
            'Login request for user {}, with pass {}, remember me - {}'.format(
                form.username.data, form.password.data, form.remember_me.data))
        return redirect(url_for('index'))
    return render_template('login.html', form=form)
Example #9
0
def login(request):
    username = "******"
    if request.method == "POST":
        myform = LoginForm(request.POST)
        if myform.is_valid():
            username = myform.cleaned_data["username"]
    else:
        myform = LoginForm()
    return render(request, "myapp/template/loggedin.html", {"username" : username})
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' and form.password.data == 'password':
            flash('You have been logged in!', 'success')
            return redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check username and password', 'danger')
    return render_template('login.html', title='Login', form=form)
Example #11
0
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']
 else:
 MyLoginForm = Loginform()
 return render(request, 'loggedin.html', {"username" : username})
Example #12
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash("Kullanıcı adı veya parola hatalı!", "danger")
            return redirect(url_for('login'))
        login_user(user)
        return redirect(url_for('index'))
    return render_template('login.html', title='GiriÅŸ Yap', form=form)
Example #13
0
def test_login_form(test_app):
    form = LoginForm()

    assert str(form.hidden_tag()) == ""
    assert (str(form.username.label) ==
            '<label for="username">Enter your username</label>')
    assert form.username()
    assert form.password.label
    assert form.password()
    assert form.submit
Example #14
0
 def post(self,request):
     myfrom=LoginForm(request.POST)
     if myfrom.is_valid():
         username=request.POST['username']
         password=request.POST['password']
         if authenticate(request,username=username,password=password):
             request.session[username]=username
             return redirect('home',username)
         else:
             return HttpResponse(self,'Invalid User :(')
Example #15
0
def login(request):
   username = "******"
   if request.method == "POST":
      #Get the posted form
      MyLoginForm = LoginForm(request.POST)
      if MyLoginForm.is_valid():
         print ("Entered")
         username = MyLoginForm.cleaned_data['username']
         password = MyLoginForm.cleaned_data['password']
         user=Userdata(username=username,password=password)
         query="select id from myapp_userdata where username=%s and password=%s and status='accepted'"
         params=[username,password]
         with connection.cursor() as cursor:
             cursor.execute(query,params)
             dbuser=cursor.fetchall()
         query1="select id from myapp_userdata where username=%s and password=%s "
         params=[username,password]
         with connection.cursor() as cursor:
             cursor.execute(query1,params)
             dbuser1=cursor.fetchall()
#         dbuser=Userdata.objects.raw("select id from myapp_userdata where username=%s and password=%s",[username,password])
#         print (dbuser.fetchone())
         if len(dbuser)>0:
            print ("USername "+username+" "+"Password "+password)
            user=authenticate(username=username,password=password)
            if(username=='girish'):
              alldata = Userdata.objects.filter(username = username)
              request.session['username'] = username
              request_context = RequestContext(request)
              return HttpResponseRedirect('/myapp/approval',{"User" : alldata})
            else:
              request.session['username'] = username
              print(request.session.get_expiry_age)
              query="select a.image from myapp_userdata a where a.username=%s and a.status='accepted'"
              params=[username]
              with connection.cursor() as cursor:
               cursor.execute(query,params)
               dbuser_pro=cursor.fetchall()
              alldata = Userdata.objects.filter(username = username)
              username="******"+username+"\n ,Your login is success"
              htmls='myapp/loggedin.html'
              return HttpResponseRedirect('/myapp/message',{"User" : dbuser_pro})
         elif len(dbuser1)>0:
            username="******"+username+"\n ,Waiting for the approval."
            htmls='myapp/faillogin.html'
            return render(request, htmls, {"username" : username})
         else:
            username="******"+username+"\n ,Entered Username or Password are wrong. Please try again."
            htmls='myapp/faillogin.html'
            response=render(request, htmls, {"username" : username})

            return response
#      username=dbuser
   else:
        pass
Example #16
0
    def post(self, request):
        fm = LoginForm(request=request, data=request.POST)
        if fm.is_valid():
            uname = fm.cleaned_data['username']
            upass = fm.cleaned_data['password']
            user = authenticate(username=uname, password=upass)
            if user is not None:
                login(request, user)
                return HttpResponseRedirect('/')

        return render(request, 'login.html', {'form': fm})
Example #17
0
def loginview(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = authenticate(
                request, username=data['username'], password=data['password'])
            if user:
                login(request, user)
                return HttpResponseRedirect(request.GET.get('next', reverse('home')))
    form = LoginForm()
    return render(request, 'login.html', {'form': form})
Example #18
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.verify_password(form.password.data):
            login_user(user)
            print('login success!')
            return redirect(url_for('index'))
        else:
            print('login failed ><')
            return redirect(url_for('login'))

    return render_template('login.html', form=form)
Example #19
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.verify_password(form.password.data):
            login_user(user)
            print("login success!")
            return redirect(url_for("index"))
        else:
            print("login failed ><")
            return redirect(url_for("login"))

    return render_template("login.html", form=form)
Example #20
0
def login():
    if g.user and g.user.is_authenticated:
        # The url_for takes the name of the function as parameter
        return redirect(url_for('index'))
    lForm = LoginForm()
    if lForm.validate_on_submit():
        session['remember_me'] = lForm.remember_me.data
        # Let OpenID authenticate the user elsewhere
        return oid.try_login(lForm.openid.data, ask_for=['nickname', 'email'])
    else:
        return render_template('login.html',
                               title='Sign in',
                               form=lForm,
                               providers=app.config['OPENID_PROVIDERS'])
Example #21
0
def login(request):
    username = "******"

    if request.method == "POST":
        #Get the posted form
        MyLoginForm = LoginForm(request.POST)
        print("In First IF ------------------------------------->")
        if MyLoginForm.is_valid():
            print("In IF ------------------------------------->")
            username = MyLoginForm.cleaned_data['username']
            request.session['username'] = username
    else:
        MyLoginForm = LoginForm()

    return render(request, 'loggedin.html', {"username": username})
Example #22
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html', title='Sign In', form=form)
Example #23
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash("Invalid username or password")
            return redirect(url_for("login"))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get("next")
        if not next_page or url_parse(next_page).netloc != "":
            next_page = url_for("index")
        return redirect(next_page)
    return render_template("login.html", title="Sign in", form=form)
Example #24
0
def login():
    """
    Goes to login page and requests for username and password.
    :return: If username and password is the same as the on in the database, redirect
    user to dashboard. Else, print invalid message.
    """
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if form.password.data == user.password:
                login_user(user, remember=form.remember.data)
                flash('You were logged in')
                return redirect(url_for('dashboard'))
        flash('Incorrect username/password. Try again.')
    return render_template('login.html', form=form)
Example #25
0
def user_login(request):
    form = LoginForm()
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        cli = Client.objects.get(username=username)
        user = authenticate(request, username=username, password=password)
        request.session.set_expiry(3600)
        if user:
            if user.is_active:
                if 'last_login' in request.session:
                    last_login = request.session.get('last_login')
                else:
                    currentDT = datetime.datetime.now()
                    request.session['last_login'] = str(
                        currentDT.strftime("%d-%m-%Y %H:%M"))
                login(request, user)

                return HttpResponseRedirect(reverse('myapp:index'))
            else:
                return HttpResponse('Your account is disabled')

        else:
            return HttpResponse('Invalid login details.')
    else:
        return render(request, 'myapp/login.html', {'form': form})
Example #26
0
 def post(self, request):
     myform = LoginForm(request.POST)
     if myform.is_valid():
         userid = request.POST['userid']
         password = request.POST['password']
         # if not Auser.objects.filter(userid=userid) or Guser.objects.filter(userid=userid):
         #     messages.warning(request,'User is Not Registered :(')
         if Auser.objects.filter(userid=userid, password=password):
             return redirect('./panel/{}'.format(userid))
         elif Guser.objects.filter(userid=userid, password=password):
             return redirect('./gpanel')
         else:
             messages.warning(request, 'User is Not Registered :(')
     else:
         messages.warning(request, 'Data is Invalid :(')
     return HttpResponseRedirect(request.path)
Example #27
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
def login(request):
   username = "******"
   
   if request.method == "POST":
      #Get the posted form
      MyLoginForm = LoginForm(request.POST)
      
      if MyLoginForm.is_valid():
         username = MyLoginForm.cleaned_data['user']
         request.session['username'] = username
         
   else:
      MyLoginForm = Loginform()
		
   #return render(request, 'loggedin.html', {"username" : username})
   return HttpResponseRedirect(reverse('data'))
Example #29
0
def user_login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect(reverse('myapp:index'))  #
            else:
                return HttpResponse('Your account is disabled.')
        else:
            return HttpResponse('Invalid login details.')
    else:
        if 'visits' in request.session.keys(
        ):  # Setting the counter in login page
            request.session['visits'] = request.session['visits'] + 1
        else:
            request.session['visits'] = 0
        form = LoginForm()
        return render(
            request, 'myapp/login.html', {
                'requser': request.user,
                'form': form,
                'visits': request.session['visits']
            })
Example #30
0
def login(request):
    username = "******"
    print username

    if request.method == "POST":
        # Get the posted form
        MyLoginForm = LoginForm(request.POST)

        if MyLoginForm.is_valid():
            username = MyLoginForm.cleaned_data['username']
            print username
    else:
        MyLoginForm = LoginForm()
    if Login.objects.filter(username=username).exists():
        return render(request, 'blockscreen.html', {"username": username})
    else:
        return HttpResponseBadRequest("username or password is wrong")
Example #31
0
def login(request):

    username = "******"
    if request.method == "POST":
        username = '******'
        #Get the posted form
        MyLoginForm = LoginForm(request.POST)
        username = MyLoginForm.errors
        # Now do all validations here.
        if MyLoginForm.is_valid():
            username = '******'
            username = MyLoginForm.cleaned_data['username']
            username += MyLoginForm.cleaned_data['password']
    else:
        MyLoginForm = LoginForm()

    return render(request, 'loggedin.html', {"username": username})