示例#1
0
def register(request):
    if request.method == 'GET':
        return render(request, 'common/register.html')
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            User.objects.create(phone=form.cleaned_data['mobile'],
                                pwd_hash=form.cleaned_data['password'])
            return HttpResponseRedirect(reverse('common:login'))
        errors = form.errors
        return render(request, 'common/register.html', {'errors': errors})
示例#2
0
def userform_(request):
    user = get_user(request)
    if request.method == "POST":
        form = UserForm(request.POST, instance=user)
        try:
            form.save()
        except ValueError:
            pass
    else:
        form = UserForm(instance=user)
    return form
示例#3
0
def signup(request):
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('index')
    else:
        form = UserForm
    return render(request, 'common/signup.html', {'form': form})
示例#4
0
def user_add():
    form = UserForm()
    if form.validate_on_submit():
        try:
            user = User(form.username.data, form.password.data,
                        form.is_valid.data)
            db.session.add(user)
            db.session.commit()
            flash("成功添加管理员!")
            return redirect(url_for('.user_index'))
        except:
            flash("添加管理员失败!", category="error")

    return render_template('/admin/user/add.html', form=form)
示例#5
0
def current_user_edit(request):
    """
    Allow an user to edit his own details
    """

    next = request.POST.get(
        'next',
        request.GET.get(
            'next',
            request.META.get('HTTP_REFERER', reverse('current_user_details'))))

    if request.method == 'POST':
        form = UserForm(instance=request.user, data=request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, _(u'Current user\'s details updated.'))
            return HttpResponseRedirect(next)
    else:
        form = UserForm(instance=request.user)

    return render_to_response('generic_form.html', {
        'form': form,
        'next': next,
        'title': _(u'edit current user details'),
    },
                              context_instance=RequestContext(request))
示例#6
0
def user_edit(pk):
    user = User.query.get(pk)
    if user is None:
        return redirect(url_for('.user_index'))
    form = UserForm(obj=user)
    if form.validate_on_submit():
        try:
            user.username = form.username.data
            user.passwd = generate_password_hash(form.password.data)
            user.is_valid = form.is_valid.data
            db.session.add(user)
            db.session.commit()
            flash("管理员编辑成功!")
            return redirect(url_for('.user_index'))
        except:
            flash("管理员编辑失败!", category="error")

    return render_template('/admin/user/edit.html', form=form)
示例#7
0
文件: admin.py 项目: hqhiwqy/AI-2
def user_add():
    form = UserForm()

    # 美化版打印 pprint
    # pprint.pprint(form.username.__dict__)

    # 判断表单验证是否通过
    if form.validate_on_submit():
        # print(form.username.data)
        try:
            user = User(form.username.data, form.password.data,
                        form.is_valid.data)

            # print(form.is_valid.data)
            db.session.add(user)
            db.session.commit()
            flash("成功添加管理员!")
            return redirect(url_for(".user_index"))
        except:
            flash("添加管理员失败!", category="error")
    return render_template("admin/user/add.html", form=form)
示例#8
0
def edit_user(request, username):
    logged_in_user = request.user

    if str(logged_in_user) == username:
        user_record = get_object_or_404(User.objects.prefetch_related(),
                                        username=username)
        page_title = 'Edit Profile'
        form = UserForm(instance=user_record)

        if request.method == 'POST':
            form = UserForm(request.POST, instance=user_record)
            if form.is_valid():
                user_obj = form.save(commit=False)
                user_obj.save()
                return HttpResponseRedirect("/user/" + username + "/view")

        return render(request, "edit-user.html", {
            'form': form,
            'page_title': page_title,
        })
    else:
        page_title = "Sorry"
        return render(request, "edit-user.html", {
            'page_title': page_title,
        })
示例#9
0
文件: views.py 项目: udduu/Django-CRM
def edit_user(request, user_id):
    user_obj = get_object_or_404(User, id=user_id)
    user_form = UserForm(instance=user_obj)
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=user_obj)
        if user_form.is_valid():
            user_form.save()
            return redirect("common:users_list")
        else:
            return render(request, 'users/create.html', {'user_form': user_form, "errors": user_form.errors})
    else:
        return render(request, 'users/create.html', {'user_form': user_form, 'user_obj': user_obj})
示例#10
0
def signup2(request):
    """
    계정생성
    """
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('common:signup3')
    else:
        form = UserForm()
    return render(request, 'common/signup2.html', {'form': form})
示例#11
0
def current_user_edit(request):
    """
    Allow an user to edit his own details
    """

    next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse('current_user_details'))))

    if request.method == 'POST':
        form = UserForm(instance=request.user, data=request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, _(u'Current user\'s details updated.'))
            return HttpResponseRedirect(next)
    else:
        form = UserForm(instance=request.user)

    return render_to_response(
        'generic_form.html', {
            'form': form,
            'next': next,
            'title': _(u'edit current user details'),
        },
        context_instance=RequestContext(request))
示例#12
0
def signup(request):
    """
    계정 생성
    """
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            form.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('index')
    else:
        form = UserForm()
    return render(request, 'common/signup.html', {'form': form})

# def change_password(request):
#     """
#     비밀번호 변경
#     """
#     if request.method == "POST":
#         form = ChangePasswordForm(request.POST)
#         if form.new_password == form.new_re_password:
#
#             if form.is_valid():




# def check_password(request):
#     """
#     비밀번호 매칭
#     """
#     random_number = sample(range(10), 6)
#     random_password = ''.join(random_number)
#
#     user_id = request.user.id
#     user = User.objects.get(pk=user_id)
#     user.password1 = random_password
#
#     send_mail('임시 비밀번호를 확인하세요',
#               '발급된 임시 비밀번호는 {}입니다.'.format(random_password),
#               '*****@*****.**',
#               ['{}'.format(user.email)],
#               fail_silently=False)
#
#     return redirect('index')
示例#13
0
def signup(request):
    """
    계정생성
    """
    if request.method == "POST":#입력으로 전달받은 데이터를 이용하여 사용자를 생성
        form = UserForm(request.POST)#is_valid() 함수로 폼 체크시 위 3개 속성을 필수값으로 체크.
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')#form.cleaned_data.get 함수는 입력값을 개별적으로 얻고 싶은 경우에 사용하는 함수
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)#신규 사용자를 저장한 후에 자동 로그인 될 수 있도록 authenticate와 login함수 사용
            login(request, user)#authenticate와 login함수는 django.contrib.auth 패키지의 함수로 사용자 인증과 로그인을 담당
            return redirect('index')
    else:
        form = UserForm()
    return render(request, 'common/signup.html', {'form': form})
示例#14
0
def signup(request) :
    # 계정 생성
    if request.method == "POST": # 계정 생성
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            # 회원가입 화면에서 입력한 값  얻는다.
            username = form.cleaned_data.get("username")
            raw_password = form.cleaned_data.get("password1")
            # 자동 로그인
            user = authenticate(username = username , password = raw_password)
            login(request, user)
            return redirect('pybo:index')
    else :  # 회원가입 화면 반환
        form = UserForm()
    return render(request, 'common/signup.html', {'form' : form})
示例#15
0
def signup(request):
    """
    계정생성
    """
    spot = Spot.objects.all().values('country_name').distinct()
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('common:login')
    else:
        form = UserForm()
    return render(request, 'common/signup.html', {'form': form, 'spot': spot})
示例#16
0
def signup(request):
    """
    아이디 생성
    POST 요청인 경우 화면에서 입력한 데이터로 새로운 사용자를 생성, GET 요청인 경우 common/signup.html 화면을 반환
    """
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('index')
    else:
        form = UserForm()
    return render(request, 'common/signup.html', {'form': form})
示例#17
0
def create_user(request):
    user_form = UserForm()
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        if user_form.is_valid():
            user = user_form.save(commit=False)
            if request.POST.get("password"):
                user.set_password(request.POST.get("password"))
            user.save()
            return redirect("common:users_list")
        else:
            return render(request, 'create.html', {'user_form': user_form, "errors": user_form.errors})
    else:
        return render(request, 'create.html', {'user_form': user_form})
示例#18
0
def signup(request):
    """
    계정생성
    """
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            #raw_password = form.cleaned_data.get('password')
            raw_password = form.cleaned_data.get('password1') # 구글링해서 {'email': '*****@*****.**', 'password1': 'skflskfl', 'username': '******', 'password2': 'skflskfl'}
            print('form.cleaned_data →',form.cleaned_data)
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('index')
    else :
        form = UserForm()
    return render(request, 'common/signup.html', {'form':form})
示例#19
0
文件: views.py 项目: p-ej/pybo
def signup(request):
    """
    계정생성
    signup 함수는 POST 요청인 경우 화면에서 입력한 데이터로 새로운 사용자를 생성
    GET 요청인 경우 common/signup.html 화면을 반환한다
    POST 요청에서 form.cleaned_data.get 함수는 회원가입 화면에서 입력한 값을 얻기 위해 사용하는 함수이다.
    여기서는 로그인 시 필요한 아이디, 비밀번호를 얻기 위해 사용되었다.
    그리고 회원가입이 완료된 이후에 자동으로 로그인되도록 authenticate 함수와 login 함수를 사용했다.

    authenticate, login 함수는 django.contrib.auth 패키지에 있는 함수로 사용자 인증과 로그인을 담당한다.
    """
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('index')
    else:
        form = UserForm()
    return render(request, 'common/signup.html', {'form': form})
示例#20
0
def change(request, user_id):
    """
    비밀번호바꾸기
    """
    # 접근 제한 걸어야함
    changer = get_object_or_404(User, pk=user_id)
    if request.method == "POST":
        form = UserForm(request.POST, instance=changer)
        if form.is_valid():
            form.save()
            # username = form.cleaned_data.get('username')
            # raw_password = form.cleaned_data.get('password1')
            # user = authenticate(username=username, password=raw_password)  # 회원가입후 바로 로그인을 위한 함수
            # login(request, user)
            return redirect('index')
        else:
            return render(request, 'common/change_form.html', {'form': form})
    else:
        form = ChangeForm(instance=changer)
        return render(request, 'common/change_form.html', {'form': form})
示例#21
0
def signup(request):
    """
    계정 생성
    """
    #request가 POST방식이면
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            # 유효하면 전송받아온 값 저장
            form.save()
            username = form.cleaned_data.get('username')
            # 입력값 얻어옴
            raw_password = form.cleaned_data.get('password1')

            # 완료후 자동으로 로그인되도록 authenticate와 login함수를 이용!
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('index')

    # request가 GET방식이면
    else:
        # 입력창 보여주기
        form = UserForm()
    return render(request, 'common/signup.html', {'form': form})