Пример #1
0
def create_secretary(request):

    is_administrator = request.user.groups.filter(
        name='administrator').exists()

    if is_administrator:
        update_form = None

        if request.POST:
            update_form = RegisterForm(request.POST)
            # Registration form
            if update_form.is_valid():
                data = request.POST.copy()
                user = UserModel.objects.create_user(
                    username=uuid.uuid4(),
                    password=data.get('password'),
                    email=data.get('email'),
                    first_name=data.get('first_name'),
                    last_name=data.get('last_name'),
                    forfait_hour=0,
                    images="default.jpg")
                student_group = Group.objects.get(name='secretary')

                user.groups.add(student_group)
                return redirect('/admin-panel')

    else:
        redirect('/')

    context = {'form': update_form, 'subject': 'secretary', 'description': ''}

    return render(request, 'admin-panel/add-user.html', context)
def index(request):

    # Package offers
    all_packages = Package.objects.all()
    register_form = None

    if request.POST:
        register_form = RegisterForm(request.POST)
        # Registration form
        if register_form.is_valid():
            data = request.POST.copy()
            user = UserModel.objects.create_user(
                username=uuid.uuid4(),
                password=data.get('password'),
                email=data.get('email'),
                first_name=data.get('first_name'),
                last_name=data.get('last_name'),
                forfait_hour=20,
                images="default.jpg")
            student_group = Group.objects.get(name='student')
            user.groups.add(student_group)
            return redirect('/login')

    context = {'all_packages': all_packages, 'form': register_form}

    return render(request, 'home.html', context)
Пример #3
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)

        if form.is_valid():
            user = User.objects.create(
                username=form.cleaned_data.get('username'),
                email=form.cleaned_data.get('email'),
            )

            user.set_password(form.cleaned_data.get('password'))

            user.save()

            profile = Profile.objects.create(
                user=user,
                line_id=form.cleaned_data.get('line_id'),
                gender=form.cleaned_data.get('gender'),
                facebook=form.cleaned_data.get('facebook'),
                birth_date=form.cleaned_data.get('birth_date'),
            )

    else:
        form = RegisterForm()

    context = {'form': form}

    return render(request, 'polls/register.html', context=context)
Пример #4
0
def register(request):  
    '''signup view'''     
    if request.method=="POST":  
        form=RegisterForm(request.POST)  
        if form.is_valid():  
            username=form.cleaned_data["username"]  
            email=form.cleaned_data["email"]  
            password=form.cleaned_data["password"]  
            user=User.objects.create_user(username, email, password)  
            user.save()
            return HttpResponseRedirect('/keenhome/accounts/login/')
        else: 
            form = RegisterForm()      
            return render_to_response("polls/register.html", {'form':form}, context_instance=RequestContext(request))  

    #This is used for reinputting if failed to register    
    else: 
        form = RegisterForm()      
        return render_to_response("polls/register.html", {'form':form}, context_instance=RequestContext(request))
Пример #5
0
def register(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    context = ({'user': get_authenticate_user(request)})
    form = RegisterForm()

    try:
        path = request.GET['continue']
    except KeyError:
        path = '/'

    if request.method == 'POST':
        form = RegisterForm(request.POST, request.FILES)
        if form.save_user():
            return HttpResponseRedirect(path)
        else:
            HttpResponseRedirect('/')

    user = get_authenticate_user(request)
    context.update({'user': user, 'form': form})
    return render(request, 'signup.html', context)
Пример #6
0
def create_user(request):

    is_secratery = request.user.groups.filter(name='secretary').exists()
    is_administrator = request.user.groups.filter(
        name='administrator').exists()

    if is_administrator or is_secratery:
        register_form = None

        if request.POST:
            register_form = RegisterForm(request.POST)
            # Registration form
            if register_form.is_valid():
                data = request.POST.copy()
                user = UserModel.objects.create_user(
                    username=uuid.uuid4(),
                    password=data.get('password'),
                    email=data.get('email'),
                    first_name=data.get('first_name'),
                    last_name=data.get('last_name'),
                    forfait_hour=20,
                    images="default.jpg")
                student_group = Group.objects.get(name='student')
                user.groups.add(student_group)

                return redirect('/admin-panel')

    else:
        redirect('/')

    context = {
        'form':
        register_form,
        'subject':
        'user',
        'description':
        'Add user to hour driving school and let him get all the famous advantage and lessons of our Driving School.'
    }

    return render(request, 'admin-panel/add-user.html', context)
Пример #7
0
def register(request):
    if request.session.get('is_login', None):
        # 登录状态不允许注册。你可以修改这条原则!
        return redirect("/index/")
    if request.method == "POST":
        register_form = RegisterForm(request.POST)
        message = "请检查填写的内容!"
        if register_form.is_valid():  # 获取数据
            username = register_form.cleaned_data['username']
            password1 = register_form.cleaned_data['password1']
            password2 = register_form.cleaned_data['password2']
            email = register_form.cleaned_data['email']
            sex = register_form.cleaned_data['sex']
            if password1 != password2:  # 判断两次密码是否相同
                message = "两次输入的密码不同!"
                return render(request, 'login/register.html', locals())
            else:
                same_name_user =Userlg.objects.filter(name=username)
                if same_name_user:  # 用户名唯一
                    message = '用户已经存在,请重新选择用户名!'
                    return render(request, 'login/register.html', locals())
                same_email_user = Userlg.objects.filter(email=email)
                if same_email_user:  # 邮箱地址唯一
                    message = '该邮箱地址已被注册,请使用别的邮箱!'
                    return render(request, 'login/register.html', locals())
                # 当一切都OK的情况下,创建新用户
                new_user = Userlg()
                new_user.name = username
                #new_user.password = password1
                new_user.password = hash_code(password1)  # 使用加密密码
                new_user.email = email
                new_user.sex = sex
                new_user.save()
                return redirect('/login/')  # 自动跳转到登录页面
    register_form = RegisterForm()
    return render(request, 'login/register.html', locals())
Пример #8
0
def Register(request):
    if request.method == "POST":
        form = RegisterForm(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 HttpResponseRedirect(reverse('layout'))

    else:
        form = RegisterForm()
    return render(request, 'polls/Register.html', {'form': form})
Пример #9
0
def register(request):
    '''signup view'''
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            user = User.objects.create_user(username, email, password)
            user.save()
            return HttpResponseRedirect('/keenhome/accounts/login/')
        else:
            form = RegisterForm()
            return render_to_response("polls/register.html", {'form': form},
                                      context_instance=RequestContext(request))

    #This is used for reinputting if failed to register
    else:
        form = RegisterForm()
        return render_to_response("polls/register.html", {'form': form},
                                  context_instance=RequestContext(request))