Пример #1
0
def registerPage(request):
    form = AddUser()
    if request.method == 'POST':
        form =AddUser(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = TwitterUser.objects.create_user(
                username=data['username'],
                password=data['password'],
                display_name=data['display_name'],
            )
            user.follow_users.add(user)
            user.save()
            login(request, user)
            return HttpResponseRedirect(reverse('home'))  

    context = {'form': form}
    return render(request, 'register.html', context)
Пример #2
0
def user_register_csv(request):
    if request.method == "POST":
        form1 = CSVUserUpload(request.POST, request.FILES)
        if form1.is_valid():
            file = request.FILES.get('file')
            register_csv(request, file)
            return redirect('user_register')
    else:
        form1 = CSVUserUpload()
    form = AddUser()
    return render(request, 'user_register.html', {'form': form, 'form1': form1, 'user': '******'})
Пример #3
0
 def post(self, request):
     if 'email' in request.POST: form = AddUser(request.POST, request.FILES)
     else: form = LoginForm(request.POST)
     if form.is_valid():
         data = form.cleaned_data
         if 'email' in data:
             display_name = check_for_name(data["display_name"])
             username = check_for_username(data['username'], display_name)
             dob = datetime.date(int(data["year"]), int(data["month"]), int(data["day"]))
             data["username"] = username
             CustomUser.objects.create_user(
                 username=username,
                 email=data["email"],
                 password=data["password"],
                 dob=dob,
                 display_name=display_name,
                 profile_photo=data["profile_photo"])
         is_authed = auth_user(request, data)
         if is_authed:
             return redirect(reverse("main"))
Пример #4
0
def user_register(request):
    role_list = Role.objects.all().exclude(short_name='super')
    if request.method == "POST":
        form = AddUser(request.POST)
        form.fields['role'].queryset = role_list
        if form.is_valid():
            chars = 'abcdefghijklmnopqrstuvwxyz0123456789@#$%&*'
            secret_key = get_random_string(8, chars)
            post = form.save(commit=False)
            post.set_password(secret_key)
            post.save()
            messages.success(request, "user "+post.name +
                             " was added successfully.")
            return redirect('user_register')
    else:
        form = AddUser()
        form.fields['role'].queryset = role_list
    form1 = CSVUserUpload()
    return render(request, 'user_register.html', {'form': form, 'form1': form1, 'user': '******'})