예제 #1
0
def login() -> render_template:
    login_form = AuthForm()
    context = {'login_form': login_form}

    if login_form.validate_on_submit():
        username = login_form.username.data
        password = login_form.password.data
        user_doc = get_user(username)

        if user_doc.to_dict():
            password_from_db = user_doc.to_dict()['password']
            if password == password_from_db:
                user_data = UserData(username, password)
                user = UserModel(user_data)
                login_user(user)
                flash('Bienvenido de nuevo!')
                redirect(url_for('hello'))
            else:
                flash("la información no coincide")
        else:
            flash("El usuario no existe")

        return redirect(url_for('index'))

    return render_template('login.html', **context)
예제 #2
0
 def post(self, request):
     f = AuthForm(request, **{'data': request.POST})
     if f.is_valid():
         _username = f.cleaned_data.get('username')
         _password = f.cleaned_data.get('password')
         user = authenticate(username=_username, password=_password)
         login(request, user)
         return redirect('home')
     else:
         return render(request, 'login.html', context={'form': f})
예제 #3
0
파일: views.py 프로젝트: Igggr/fls_delivery
def login():
    if current_user.is_authenticated:
        return redirect(url_for('account'))
    form = AuthForm()
    if form.validate_on_submit():
        print("all ok")
        user = User.query.filter_by(mail=form.mail.data).first()
        if user and user.check_hash(form.password.data):
            login_user(user)
            next_page = request.args.get('next')
            if not next_page:
                next_page = url_for('account')
            return redirect(next_page)
    return render_template('auth.html', form=form)
예제 #4
0
def splash(request):
    signupform = SignupForm()
    authform = AuthForm()
    if request.method == 'POST':
        signupform = SignupForm(request.POST)
        if signupform.is_valid():
            if username_exists(signupform.cleaned_data["username"]):
                messages.error(request, 'Username already exists.')
                return render(request, 'splash.html', {
                    'signupform': signupform,
                    'authform': authform
                })
            if email_exists(signupform.cleaned_data["email"]):
                messages.error(request,
                               'User already exists with this email address.')
                return render(request, 'splash.html', {
                    'signupform': signupform,
                    'authform': authform
                })

            user = User.objects.create_user(
                signupform.cleaned_data["username"],
                signupform.cleaned_data["email"],
                signupform.cleaned_data["password"])
            user.first_name = signupform.cleaned_data["first_name"]
            user.last_name = signupform.cleaned_data["last_name"]
            user.save
            return render(request, 'dashboard.html')
    else:
        signupform = SignupForm()
    return render(request, 'splash.html', {
        'signupform': signupform,
        'authform': authform
    })
예제 #5
0
파일: auth.py 프로젝트: cuijianhui1998/blog
def login():
    form = AuthForm(request.form)
    if request.method == 'POST' and form.validate():
        user = Auth.query.filter_by(
            username=request.form.get('username')).first_or_404()
        if user and user.check_password(request.form.get('password')):
            login_user(user)
            next = request.args.get('next')
            if not next or not next.startswith('/'):
                next = url_for('web.index')
            return redirect(next)
        else:
            flash('密码错误')
    else:
        flash('不存在该用户')

    return render_template('auth/login.html', form=form)
예제 #6
0
def signup() -> render_template:
    signup_form = AuthForm()
    context = {'signup_form': signup_form}

    if signup_form.validate_on_submit():
        username = signup_form.username.data
        password = signup_form.password.data

        user_doc = get_user(username)
        if user_doc.to_dict() is None:
            password_hash = generate_password_hash(password)
            user_data = UserData(username=username, password=password_hash)
            put_user(user_data)
            user = UserModel(user_data)
            login_user(user)
            flash("Bienvenido")
            return redirect(url_for('hello'))
        else:
            flash("El usuario ya existe!")
    return render_template('signup.html', **context)
예제 #7
0
def login(request):

    success_redirect = 'index'
    template = 'app/auth/login.html'

    if request.method == 'POST':

        form = AuthForm(request.POST)
        errors = []
        context = {
            'form': form,
            'errors': errors
        }

        if form.is_valid():

            username = request.POST.get('username')
            password = request.POST.get('password')
            user = authenticate(username=username, password=password)

            # si el usuario existe.
            if user is not None:

                # si el usuario esta activo.
                if user.is_active:

                    auth_login(request, user)
                    return redirect(SUCCESS_REDIRECT)
                    
                else:
                    errors.append(ERR_INACTIVE)
                    return render(request, template, context)
            else:
                errors.append(ERR_NOT_VALID)
                return render(request, template, context)
        else:
            return render(request, template, context)

    form = AuthForm()
    return render(request, template)
예제 #8
0
    def __login(self):
        """Метод обработки запросов пользователя на странице авторизации"""
        if current_user.is_authenticated:
            return redirect(url_for("__index"))

        form = AuthForm()

        # Если пришел POST запрос в форме, обрабатываем его.
        if form.validate_on_submit():
            # Загружаем юзера со всеми его данными.
            user = self.__db_connector.load_user(form.name.data)

            # Если юзер вошел, перенаправляем на главную.
            if user and user.verify_password(form.password.data):
                login_user(user, remember=form.remember_me.data)
                return redirect(request.args.get("next") or url_for("__index"))
            else:
                flash("Упс, похоже, вы ошиблись с данными.", "error")

        # Если юзер не смог войти или просто открыл страницу авторизации,
        # отправляем шаблон с формой.
        return render_template("authorization.html", form=form)
예제 #9
0
def login(request):
    # catch logged-in user and send them to dash
    # if request.user.is_authenticated():
    #    return redirect('dashboard')
    authform = AuthForm(request.POST)
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            auth_login(request, user)
            # Redirect to a success page.
            # return render(request, 'dashboard.html')
            return HttpResponseRedirect('/feed')
        else:
            # Return a 'disabled account' error message
            messages.error(request, 'Account is disabled')
            return render(request, 'login.html', {'form': authform})
    else:
        # Return an 'invalid login' error message.
        messages.error(request, 'Incorrect username or password')
        return render(request, 'login.html', {'form': authform})
예제 #10
0
def password_view(request):
    form = AuthForm()
    auth = False
    msg_obj = None
    gf = False
    if request.method == "POST":
        form = AuthForm(request.POST or None)
        if form.is_valid():
            auth = False
            name = form.cleaned_data.get('name')
            password = form.cleaned_data.get('password')
            obj = Message.objects.all().filter(name__icontains=name, password__iexact=password)
            if obj.exists():
                auth = True
                msg_obj = obj.first()
                print(msg_obj.name)
                if "Amruta" == msg_obj.name:
                    gf = True
                return render(request, 'index.html',
                              {'form': form, 'msg': msg_obj, 'auth': auth, 'gf': gf})
        else:
            form = AuthForm()
    return render(request, 'index.html', {'form': form, 'msg': msg_obj, 'auth': auth, 'gf': gf})
예제 #11
0
 def get(self, request):
     f = AuthForm()
     return render(request, 'login.html', context={'form': f})
예제 #12
0
def logout(request):
    authform = AuthForm()
    auth_logout(request)
    return render(request, 'login.html', {'form': authform})