예제 #1
0
def login_view(request):
    form = LoginForm(request.POST or None)
    context = {
        'form':form
    }
    next_ = request.GET.get('next')
    next_post = request.POST.get('next')
    redirect_path = next_ or next_post or None
    if form.is_valid():
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            if is_safe_url(redirect_path, request.get_host()):
                if redirect_path == next_:
                    return redirect('/carts/checkout')
                return redirect(redirect_path)
            else:
                return redirect('/')
        else:
            form = LoginForm()
            print('User Not Valid')

    return render(request, 'user/login.html', context)
예제 #2
0
def login():
    """
    登录视图
    :return: login.html
    """
    if request.method == 'GET':  # get请求
        form = LoginForm()
        return render_template('home/login.html', form=form)
    else:  # post请求
        form = LoginForm(request.form)
        if form.validate_on_submit():
            data = form.data
            user = User.query.filter_by(name=data['name']).first()
            if user:
                if not user.check_password(data['password']):
                    flash("密码错误", 'err')
                    return redirect(url_for('home.login'))
            else:
                flash("输入的账户不存在", 'err')
                return redirect(url_for('home.login'))

            session['user'] = user.name
            session['user_id'] = user.id
            userlog = Userlog(user_id=user.id)
            db.session.add(userlog)
            db.session.commit()
            return redirect(url_for('home.user'))
        return render_template('home/login.html', form=form)
예제 #3
0
def index(request):

    # if the user is already logged in, redirect to select_company
    if request.user.is_authenticated():
        return redirect('dashboard:main')

    if request.method == 'POST':
        action = 'login'

        if request.POST.get('next', '') != '':
            next = request.POST.get('next')

        login_form = LoginForm(request.POST)

        if login_form.is_valid():
            message, next = login(request, login_form.cleaned_data)

            if message == 'logged-in':
                return redirect('dashboard:main')
    else:
        login_form = LoginForm()

    context = {
        'user': request.user,
        'login_form': login_form
    }

    return render(request, "home/index.html", context)
예제 #4
0
    def test_login_successful(self):
        """学生番号・パスワード一致 -- 成功
        """
        # create form data
        data = {'username': '******', 'password': '******'}
        form = LoginForm(data=data)

        # ログイン成功
        self.assertTrue(form.is_valid(), '正しい学生番号とパスワードでログインできません')
예제 #5
0
파일: views.py 프로젝트: Xayom/Yordam
def home(request):
    template_name = 'home.html'
    form = LoginForm(request.POST or None)
    if request.POST and form.is_valid():
        user = form.login(request)
        if user:
            login(request, user)
            return redirect('home')  # Redirect to a success page.

    post = Post.objects.filter(post_status=1)
    return render(request, template_name, context={'posts': post, 'form': form})
예제 #6
0
파일: views.py 프로젝트: mina998/zblog
def login():
    form = LoginForm()
    if form.validate_on_submit():
        obj = Site.query.filter(Site.name.in_(['username','password','nikename'])).all()
        user = site_to_dict(obj)
        if user['username'] == form.data.get('username') and user['password'] == form.data.get('password'):
            session['login'] = 1
            session['nikename'] = user['nikename']
            return redirect(url_for('admin.index'))
        else:
            flash('帐户或者密码不正确!', category='err')
            return redirect('/login')
    return render_template('/home/login.html',form=form)
예제 #7
0
def login_view(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = authenticate(request,
                                username=data.get('username'),
                                password=data.get('password'))
            if user:
                login(request, user)
                return HttpResponseRedirect(reverse('home'))

    form = LoginForm()
    return render(request, 'generic_form.html', {'form': form})
예제 #8
0
def login_view (request):
  password = ""
  username = ""
  if request.method == "POST":
      formulario = LoginForm(request.POST)
      if formulario.is_valid():
          m = User.objects.get(username=request.POST['username'])
          username = formulario.cleaned_data['username']
          request.session['username'] = m.username
          return HttpResponseRedirect(reverse('perfil.views.user_details', args=[m.username]))

  else:
      formulario = LoginForm()
  ctx = {'formulario':formulario}
  return render_to_response ('home/login.html', ctx,context_instance=RequestContext(request))
예제 #9
0
def contact_home(request):
    contactForm = ContactUserForm(request.POST or None, prefix="contactForm")
    context = {
        'contactForm': contactForm,
    }

    if not request.user.is_authenticated():
        formLogin = LoginForm(request.POST or None, prefix="loginForm")
        formSignup = SignUpForm(request.POST or None, prefix="signupForm")
        formFb = FbForm(request.POST or None, prefix="FBform")
        context['formLogin'] = formLogin
        context['formSignup'] = formSignup
        context['formFb'] = formFb

    if contactForm.is_valid():
        print(contactForm.cleaned_data)
        contactForm.save()
        print("saving form")
    return render(request, 'contact/contact_home.html', context)


# for contact form
# def contact_user_form(request):
# 	if request.method == 'POST':
# 		print(request.POST.get('contactForm-email'))
# 		if form.is_valid():
# 			form.save()
# 		return HttpResponse('success')
예제 #10
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)
예제 #11
0
def checkout_view(request):
    cart_obj, cart_created = Cart.objects.new_or_get(request)
    order_obj = None
    if cart_created or cart_obj.products.count() == 0:
        return redirect("carts:home")
    else:
        order_obj, new_order_obj = Order.objects.get_or_create(cart=cart_obj)
    user = request.user
    billing_profile = None
    login_form = LoginForm()
    guest_form = GuestForm()
    guest_email_id = request.session.get('guest_email_id')
    if user.is_authenticated:
        billing_profile, billing_profile_created = BillingProfile.objects.get_or_create(
            user=user, email=user.email)
    elif guest_email_id is not None:
        guest_email_obj = GuestEmail.objects.get(id=guest_email_id)
        billing_profile, billing_guest_profile_created = BillingProfile.objects.get_or_create(
            email=guest_email_obj.email)
    else:
        pass
    context = {
        "object": order_obj,
        "billing_profile": billing_profile,
        "login_form": login_form,
        "guest_form": guest_form
    }

    return render(request, 'carts/checkout.html', context)
예제 #12
0
def auth_logout(request):
	logout(request)
	form = LoginForm(request.POST or None)
	context = {
		'formLogin':form,
	}
	return HttpResponseRedirect(reverse('home'))
예제 #13
0
    def test_mistake_password(self):
        """学生番号一致・パスワード誤り -- 失敗

        学生番号・パスワードの両方にエラー表示を行う
        """
        # create form data
        data = {'username': '******', 'password': '******'}
        form = LoginForm(data=data)

        # ログイン失敗
        self.assertFalse(form.is_valid(), '誤ったパスワードでログインできました')

        # 学生番号・パスワードの両方にエラー表示
        self.assertTrue('username' in form.errors,
                        'パスワード誤り -- 学生番号にエラーが表示されていません')
        self.assertTrue('password' in form.errors,
                        'パスワード誤り -- パスワードにエラーが表示されていません')
예제 #14
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.get_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', form=form, title='Login')
예제 #15
0
def login(request):
    if request.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:
                auth_login(request, user)
                if request.GET.get('next') is not None:
                    return redirect(request.GET['next'])
                else:
                    return HttpResponseRedirect(reverse('home:home'))
        return render(request, 'home/login.html', {'form': form})
    else:
        form = LoginForm()
    return render(request, 'home/login.html', {'form': form})
예제 #16
0
def login_view(request):
    mensaje = ""
    if request.user.is_authenticated():
        return HttpResponseRedirect('/index')
    else:
        if request.method == "POST":
            form = LoginForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data['username']
                password = form.cleaned_data['password']
                usuario = authenticate(username=username,password=password)
                if usuario is not None and usuario.is_active:
                    login(request,usuario)
                    return HttpResponseRedirect('/index')
                else:
                    mensaje = "Usuario y/o password incorrecto"
        form = LoginForm()
        ctx = {'form':form,'mensaje':mensaje}
        return render_to_response('home/login.html',ctx,context_instance=RequestContext(request))
예제 #17
0
def authorize_page(request):
    """
    Страница авторизации

    :param request: объект c деталями запроса
    :type request: :class:`django.http.HttpRequest`
    :return: Перенаправление на главную страницу

    """

    context = get_base_context()
    context["title"] = "Войти"
    if request.method == "POST":
        if not request.POST.get("remember_me", None):
            request.session.set_expiry(0)
        form = LoginForm(request.POST)
        if form.is_valid():
            context["form"] = form
            username = form.data["login"]
            password = form.data["password"]
            try:
                username = User.objects.get(username=username).username
            except User.DoesNotExist:
                try:
                    username = User.objects.get(email=username).username
                except User.DoesNotExist:
                    messages.error(request, "Логин/Email неверный")
            user = authenticate(request, username=username, password=password)
            if user is not None:
                login(request, user)
                return redirect("/panel/")
            else:
                try:
                    User.objects.get(username=username)
                    messages.error(request, "Неверный пароль")
                except User.DoesNotExist:
                    messages.error(request, "Логин/Email неверный")
        else:
            messages.error(request, "Неправильный формат данных.")
    else:
        context["form"] = LoginForm()
    return render(request, "authorize.html", context)
예제 #18
0
def basic_instruction(request):
	context={}
	if not request.user.is_authenticated():
		formLogin = LoginForm(request.POST or None, prefix="loginForm")
		formSignup = SignUpForm(request.POST or None, prefix="signupForm")
		formFb = FbForm(request.POST or None, prefix="FBform")
		context['formLogin'] = formLogin
		context['formSignup'] = formSignup
		context['formFb'] = formFb
		
	return render(request,"instruction/basicInstruction.html",context)
예제 #19
0
def login_view(request):
    message = ""
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    else:
        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 and user.is_active:
                    login(request, user)
                    return HttpResponseRedirect('/home/')
                else:
                    message = "User and/or passwordd invalid"
        form = LoginForm()
        ctx = {'form': form, 'message': message}
        return render_to_response('home/login.html', ctx,
            context_instance=RequestContext(request))
예제 #20
0
def login(request):
    message = None
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)
            if user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect('/accounts/loggedin')
            else:
                message = "Your account is inactive"
    else:
        form = LoginForm()
    return render_to_response(
        'registration/login.html',
        {'message': message, 'form': form},
        context_instance=RequestContext(request)
        )
예제 #21
0
    def get(self, request):
        if request.user.is_authenticated():

            homeUser = request.GET.get('Username', None)
            Username = Url.objects.filter(user=request.user)
            return render(request, self.template, {
                'form': self.form(initial={'user': request.user}),
            })
        return render(request, self.template, {
            'form': HomeForm(),
            'login': LoginForm()
        })
예제 #22
0
def rego_email_sent(request):
    context = {}
    # if not logged in
    if not request.user.is_authenticated():
        formLogin = LoginForm(request.POST or None, prefix="loginForm")
        formSignup = SignUpForm(request.POST or None, prefix="signupForm")
        formFb = FbForm(request.POST or None, prefix="FBform")
        context = {
            'formLogin': formLogin,
            'formSignup': formSignup,
            'formFb': formFb,
        }
    return render(request, "home/regoEmailSent.html", context)
예제 #23
0
def email_already_in_use(request):
    context = {}
    # if not logged in
    if not request.user.is_authenticated():
        formLogin = LoginForm(request.POST or None, prefix="loginForm")
        formSignup = SignUpForm(request.POST or None, prefix="signupForm")
        formFb = FbForm(request.POST or None, prefix="FBform")
        context = {
            'formLogin': formLogin,
            'formSignup': formSignup,
            'formFb': formFb,
        }
    return render(request, "home/emailAlreadyInUse.html", context)
예제 #24
0
def home(request):
    context = {}
    # if not logged in
    if not request.user.is_authenticated():
        formLogin = LoginForm(request.POST or None, prefix="loginForm")
        formSignup = SignUpForm(request.POST or None, prefix="signupForm")
        formFb = FbForm(request.POST or None, prefix="FBform")
        context = {
            'formLogin': formLogin,
            'formSignup': formSignup,
            'formFb': formFb,
        }
    return render(request, 'home/frontPage.html', context)
예제 #25
0
def forgot_password_page(request):
	if request.user.is_authenticated:
		return redirect('userProfile')

	formLogin = LoginForm(request.POST or None, prefix="loginForm")
	formSignup = SignUpForm(request.POST or None, prefix="signupForm")
	formFb = FbForm(request.POST or None, prefix="FBform")
	forgotPasswordForm = ForgotPasswordForm(request.POST or None, prefix='forgotPassword')
	context = {
		'formLogin':formLogin,
		'formSignup':formSignup,
		'formFb':formFb,
		'forgotPasswordForm':forgotPasswordForm,
	}		
	return render(request,'userApp/forgotPassword.html',context)
예제 #26
0
def login(request):
	if request.method == 'POST':
		form = LoginForm(data=request.POST)
		if form.is_valid():
			#login the user
			user = form.get_user()
			auth_login(request, user)
			return redirect('/')
	else:
		form = LoginForm()
	return render(request, 'accounts/login.html', {'form':form})
예제 #27
0
def nav_login_form(context, api=False):
    """
    Passes context to template `base_login_form.html`.    
    ::
    
      {
        'user': '******',
        'login_form': 'user login form',
      }
    """
    form = LoginForm()
    user = context['user']

    return {
        'user': user,
        'login_form': form,
    }
예제 #28
0
def index(request):
    form = LoginForm()
    if request.POST:
        try:
            log_out = request.POST['logout']
        except MultiValueDictKeyError:
            log_out = False
        if log_out:
            logout(request)
            messages.success(request, 'Wylogowano')
            return redirect('home:index')
        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)
                messages.success(request, 'Witaj ' + username)
                return redirect('home:index')
            else:
                messages.warning(request, 'Twoje konto nie jest aktywne')
        else:
            messages.warning(request, 'Błędna nazwa użytkownika lub hasło')
    return render(request, 'profile/index.html', {'form': form})
예제 #29
0
def login_form(request):
    return {'login_form' : LoginForm()}