Esempio n. 1
0
def login():
    form = LoginForm()
    form.nickname.data = ''
    if request.method == 'POST' and form.validate():
        user = Session().query(User).filter_by(nickname=form.nickname.data).first()
        if user == None:
            flash('Login requested for nickname=' + form.nickname.data)
        else:
            flash('Logined with nickname=' + form.nickname.data)
            g.user = user
        return redirect('/')
    return render_template('login.html', title='Sign in', form=form)
Esempio n. 2
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')
            #flash(f'Logged In', 'success')
            return redirect(next_page) if next_page else redirect(url_for('home'))
        else:
            flash(f'Woops, incorrect email or password', 'danger')

    return render_template('login.html', title='Login', form=form)
Esempio n. 3
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(url_for('index'))
        return redirect(next_page)
    return render_template('login.html', title=_('Sign in'), form=form)
Esempio n. 4
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('accueil'))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', form=form)
Esempio n. 5
0
def login(request):
    """用户名或手机登录"""
    if request.method == 'GET':
        login_form = LoginForm(request)
        context = {'login_form': login_form}
        return render(request, "mainapp/login.html", context)
    elif request.method == 'POST':
        login_form = LoginForm(request, data=request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']

            # user_object = UserInfo.objects.filter(username=username, password=password).first()
            user_object = UserInfo.objects.filter(
                Q(email=username)
                | Q(mobile_phone=username)).filter(password=password).first()

            if user_object:
                # 用户名写入session
                request.session['user_id'] = user_object.id
                # 两周后过期
                request.session.set_expiry(60 * 60 * 24 * 14)

                return redirect('mainapp:index')
            login_form.add_error('username', '用户名或密码错误')

        context = {'login_form': login_form}
        return render(request, "mainapp/login.html", context)
Esempio n. 6
0
def signin(request):
    if request.method == 'GET':
        form = LoginForm()
        return render(request, 'mainapp/signin.html', {'form': form})
    else:
        user_id = request.POST['user_id']
        user_pw = request.POST['user_pw']
        member = Member.objects.get(user_id=user_id, user_pw=user_pw)
        request.session['user_id'] = member.user_id
        request.session['member_id'] = member.member_id

        if member:
            return redirect('/swipe/')
            # return render(request, 'mainapp/swipe.html')
        else:
            return redirect('/main')


#   # 두번째 시도
# def signin(request):
#     if request.method == "GET":
#         return render(request, 'mainapp/signin.html')
#         # 잘못된 접근입니다. 알림뜨게 하기

#     elif request.method == "POST":
#         # 전송받은 아이디, 비밀번호 확인
#         user_id = request.POST.get('user_id')
#         user_pw = request.POST.get('user_pw')

#         #유효성 처리
#         res_data = {}
#         if not (user_id and user_pw):
#             res_data['error']="모든 칸을 다 입력해주세요."
#         else:
#             # 기존 DB에 있는 member 모델과 같은 값인 걸 가져옴.
#             member = Member.objects.get(user_id = user_id, user_pw=user_pw)

#             # 비밀번호가 맞는지 확인한다. 위에 check_password를 참조
#             if check_password(password, member.user_pw):
#                 #응답 데이터 세션에 값 추가. 수신측 쿠키에 저장된다.
#                 request.session['user_id'] = member.user_id

#                 #리다이렉트
#                 return redirect('/')
#             else:
#                 res_data['error'] = "비밀번호가 틀렸습니다."
#         return render(request, 'signin.html', res_data)
#                 #응답 데이터 res_data 전달
Esempio n. 7
0
def signin(request):
    if request.method == 'GET':
        form = LoginForm()
        return render(request, 'mainapp/signin.html')
    else:
        user_id = request.POST.get('user_id')
        user_pw = request.POST.get('user_pw')
        # member = Member.objects.get(real_id=user_id, pw=user_pw)
        try:
            member = Member.objects.get(user_id=user_id, user_pw=user_pw)
            request.session['user_id'] = member.user_id
            request.session['user_pw'] = member.user_pw

        except Member.DoesNotExist:
            return redirect('signin')
        else:
            return redirect('/swipe')
Esempio n. 8
0
def test_user_log(user, log_data, incorrect_log_data):
    assert LoginForm(data=log_data).is_valid()
    assert not LoginForm(data=incorrect_log_data).is_valid()