Example #1
0
def register(request):
    redirect_to = request.POST.get('next', request.GET.get('next', ''))

    if request.method == 'POST':
        form = RegisterForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            username = request.POST.get('username')
            email = request.POST.get('email')
            print(email)
            send_mail(
                subject='注册成功!',
                message='恭喜{}注册成功!'.format(username),
                from_email=settings.EMAIL_FROM,
                recipient_list=[
                    email,
                ],
                fail_silently=False,
            )

        if redirect_to:
            return redirect(redirect_to)
        else:
            return redirect('/users/register/')

    else:
        form = RegisterForm()

    return render(request,
                  'users/register.html',
                  context={
                      'form': form,
                      'next': redirect_to
                  })
Example #2
0
def settingspage(request):
    users = User.objects.all()
    books = Book.objects.all()

    addbook_form = UploadForm(request.POST or None, request.FILES or None)
    adduser_form = RegisterForm(request.POST or None, request.FILES or None)
    if request.method == "POST":
        if addbook_form.is_valid():
            book = addbook_form.save(commit=False)
            book.author = request.user
            book.name = addbook_form.cleaned_data.get("name")
            book.detail = addbook_form.cleaned_data.get("detail")
            book.ISBN_Image = addbook_form.cleaned_data.get("ISBN_Image")
            book.save()
            return redirect(reverse('books'))
        else:
            addbook_form = UploadForm()
        if adduser_form.is_valid():
            adduser_form.save()
        else:
            adduser_form = RegisterForm()

    args = {"users": users, "books": books,
            "addbook_form": addbook_form, "adduser_form": adduser_form}
    return render(request, "profile_settings.html", args)
Example #3
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('home')
    else:
        form = RegisterForm()
    return render(request, 'users/register.html', context={'form': form})
Example #4
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            form.save()
            print('Successfully Created')
    else:
        form = RegisterForm()

    return render(request, 'users/register.html', {'form': form})
Example #5
0
def register(request):
    template = "user_register.html"
    f = RegisterForm()
    messages = None
    context = {'title': 'Registro de usuarios', 'form': f, 'message': messages}
    if request.method == 'POST':
        f = RegisterForm(request.POST)
        if f.is_valid():
            f.save()
        messages = 'Usuario creado correctamente'
    return render(request, template, context)
Example #6
0
    def test_can_save(self):
        self.assertEqual(User.objects.count(), 0)

        test_form = RegisterForm({'username': '******', 
                                  'email': '*****@*****.**', 
                                  'password1': 'asdf',
                                  'password2': 'asdf'})
        test_form.is_valid()
        test_form.save()

        self.assertEqual(User.objects.count(), 1)
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            form.save()
            print('Successfull Registration')
            messages.success(request, "Thanks for successfull Registration")
            return redirect('/success')
    else:
        form = RegisterForm()

    return render(request, 'users/register.html', {'form': form})
Example #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')
            messages.success(
                request, f'Welcome {username},Your Account has been created')
            return redirect('login')
    else:
        form = RegisterForm
    return render(request, 'users/register.html', {'form': form})
Example #9
0
    def test_can_save(self):
        self.assertEqual(User.objects.count(), 0)

        test_form = RegisterForm({
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'asdf',
            'password2': 'asdf'
        })
        test_form.is_valid()
        test_form.save()

        self.assertEqual(User.objects.count(), 1)
Example #10
0
def register(response):
    if response.method == "POST":
        form = RegisterForm(response.POST)
        if form.is_valid():
            form.save()
            return redirect("/accounts/login/")
        else:
            return redirect("/accounts/signup/")

    else:
        form = RegisterForm()

    return render(response, "signup.html", {"form": form})
Example #11
0
def register(request):
    redirect_to = request.POST.get('next', request.GET.get('next', ''))
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            form.save()
            if redirect_to:
                return redirect(redirect_to)
            else:
                return redirect('/')
    else:
        form = RegisterForm()
    return render(request, 'users/register.html', context={'form': form, 'redirect_to': redirect_to})
Example #12
0
 def post(self, request, *args, **kwargs):
     form = RegisterForm(request.POST)
     if form.is_valid():
         form.save()
         username = form.cleaned_data['username']
         password = form.cleaned_data['password1']
         user = authenticate(username=username, password=password)
         login(request, user)
         clients = Group.objects.get(name="clients")
         clients.user_set.add(user)
         if not form.cleaned_data.get('remember_me'):
             request.session.set_expiry(0)
         return redirect('/accounts/profile')
     return render(request, 'registration/register.html', {'form': form})
Example #13
0
def register(request):
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                messages.add_message(request, messages.SUCCESS, "Your registration succed. We've sent a verification link to your email address.")
                return redirect(reverse('login'))
            except:
                pass
    else:
        form = RegisterForm()
        
    data = {'form': form}
    return render(request, 'registration/register.html', data)
Example #14
0
def register(request):
    #Register view
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('users:l_register')
    else:
        form = RegisterForm()

    return render(
        request=request,
        template_name='users/register.html',
        context={'form': form}
        )
Example #15
0
 def post(self, request, *args, **kwargs):
     # request.POST['gender'] = int(request.POST['gender'])
     print(request.POST)
     formRegister = RegisterForm(request.POST or None)
     if formRegister.is_valid():
         formRegister.save()
         response = {
             'success': 'true',
             'message': f'New User: {request.POST["username"]}'
         }
     else:
         response = {
             'success': 'false',
             'message': 'Failed Create New User'
         }
     return Response(response)
Example #16
0
def create_user(request):
    #If the user is trying to add info to the server,
    if request.method == 'POST':
        #Feed as arguments to RegisterForm the inputs from the user.
        create_user_form = RegisterForm(request.POST)
        #If username and password are of the right length and email is of the valid form,
        #And password and confirm password identical, 
        if create_user_form.is_valid():
            #Don't save the user in creation as a new user yet. 
            new_user = create_user_form.save()
            pw = create_user_form.cleaned_data.get('password')
            new_user.set_password( pw )
            new_user.save()
 
            #Then create UserProfile object from User object.
            new_UserProfile = UserProfile(user=new_user)
            #new_UserProfile.user = new_user
            new_UserProfile.save() #Then save. 
 
            #Render a Welcome to GroupFit page if the input info is valid. 
            #No need to customize welcome page unless we want to just switch the name: Welcome, username!
            return render(request, 'welcome.html')
 
            #Send an email as well.
    else:
        #If the user didn't plug in anything, create_user_form will be an empty shell?
        create_user_form = RegisterForm()
    return render(request, 'register.html', {'create_user_form': create_user_form})
Example #17
0
def register(request):
    form = RegisterForm(request.POST)
    if form.is_valid():
        user = form.save(commit=False)

        # Generate activation key for user account
        activation_key = generate_activation_key(user.email)
        user.activation_key = activation_key
        user.is_active = False
        user.save()

        send_email.delay('mail/confirmation', {'link': activation_key},
                         u'\u2713 ' + _("Welcome to Prestashop-Sync Service"),
                         [user.email])
        return HttpResponse(
            simplejson.dumps({
                'response':
                _("Email with a confirmation link has been sent"),
                'result':
                'success'
            }))
    else:
        response = {}
        for k in form.errors:
            response[k] = form.errors[k][0]
        return HttpResponse(
            simplejson.dumps({
                'response': response,
                'result': 'error'
            }))
Example #18
0
def register(request):
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = RegisterForm(request.POST)
        print("there is a request")
        # check whether it's valid:
        if form.is_valid():
            user = form.save(commit=False)
            user.set_password(form.cleaned_data['password'])
            user.save()
            blog_id = Blog.objects.count() + 1
            user = User.objects.get(username=request.POST.get('username'))
            blog = Blog(num=blog_id, writer=user, isDefault=True)
            blog.save()
            #    form.save()
            response_data['status'] = 0
            return HttpResponse(json.dumps(response_data),
                                content_type="application/json")
        else:
            response_data['status'] = -1
            response_data['message'] = list(
                form.errors.keys())[0] + ": " + form.errors[list(
                    form.errors.keys())[0]][0]
            print(
                HttpResponse(json.dumps(response_data),
                             content_type="application/json"))
            return HttpResponse(json.dumps(response_data),
                                content_type="application/json")
    else:
        return HttpResponse(json.dumps(response_data),
                            content_type="application/json")
Example #19
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        field_errors = register_form.errors.as_json()
        success = False
        email_error = None
        success_message = None

        if register_form.is_valid():
            user = register_form.save(commit=False)
            user.is_active = False

            try:
                send_mail(request, user)
                user.save()
                success = True
                success_message = 'На указанную вами электронную почту выслано письмо с инструкциями для подтверждения учётной записи'
            except Exception as e:
                email_error = 'Ошибка! Перезагрузите страницу и попробуйте заново.'
                print(e)

        context = {
            'success': success,
            'errors': field_errors,
            'email_error': email_error,
            'success_message': success_message
        }

        return JsonResponse(context)
Example #20
0
def register(request):
    # 获取跳转地址
    redirect_to = request.POST.get('next', request.GET.get('next', ''))
    # 判断是什么提交方法
    form = RegisterForm()
    if request.method == 'POST':
        # 首先使用提交的数据生成form
        form = RegisterForm(request.POST, request.FILES)
        # 判断数据是否合法
        if form.is_valid():
            user = form.save()
            # 返回登录,并提示注册成功,请登录
            messages.success(request, '提示注册成功,请登录!')
            # 判断redirect_to是否存在。
            if redirect_to:
                login(request, user)
                return redirect(redirect_to)
            else:
                # 重定向到login
                return redirect(reverse('login'))
    else:
        return render(request, 'users/register.html', {
            'form': form,
            'next': redirect_to
        })
Example #21
0
def register(request, **kwargs):
    if request.user.is_authenticated():
        messages.error(request, 'Ya estas registrado')
        logging.error('Ya estas registrado: %s ' % request.user.username)
        return redirect(reverse('error'))
    
    form = RegisterForm()
    
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        
        if form.is_valid():
            user = form.save()
            messages.success(request, _("Bienvenido a %s" % current_site.name))

            user = authenticate(username=form.cleaned_data['username'],
                                password=form.cleaned_data['password1'])
            auth_login(request, user)

            return redirect(reverse('home'))
    
    context = {
        'form': form
    }

    c = template.RequestContext(request, context)
    return render_to_response('page.users.register.html', c)
def register_user(request):
    context = {}
    user_creation_form = RegisterForm()
    if (request.method == "POST"):
        uploaded_image = request.FILES["profile_pic"]
        user_creation_form = RegisterForm(request.POST, request.FILES)
        if (user_creation_form.is_valid()):
            user = user_creation_form.save(commit=False)
            user.is_active = False

            user.set_expiration_date()
            user.set_activation_token()
            email = user.email
            token = user.get_activation_token()

            url_to_activate = request.build_absolute_uri(
                '/') + "users/activate/" + token + "/" + str(user.id)
            message = "Please activate your email with the next url " + url_to_activate
            send_mail(
                'Account activation mail',
                message,
                '*****@*****.**',
                [email],
                fail_silently=False,
            )
            user.save()
            fs = FileSystemStorage()
            fs.save(uploaded_image.name, uploaded_image)
            context[
                'message'] = "Registered succcessfully, please wait for activation mail to use your account."
            context["form"] = user_creation_form
            return render(request, "register.html", context)

    context = {"form": user_creation_form}
    return render(request, "register.html", context)
Example #23
0
def register_wholesale(request):
    """Регистрация оптового покупателя"""

    if request.POST:
        form = RegisterForm(request.POST)
        company_form = CompanyForm(request.POST)

        if form.is_valid() and company_form.is_valid():
            instance = form.save(commit=False)
            instance.set_password(form.cleaned_data["password"])
            instance.status = User.STATUS_WHOLESALE
            instance.save()

            instance = authenticate(email=instance.email, password=form.cleaned_data["password"])
            user_login(request, instance)

            company = company_form.save(commit=False)
            company.user = request.user
            company.save()

            return redirect(reverse("users.auth.register.completed"))

    else:
        form = RegisterForm()
        company_form = CompanyForm()

    context = {"form": form, "company_form": company_form}

    return render(request, "users/auth/register_wholesale.html", context)
Example #24
0
def register(request):
    context = {}
    if request.POST:
        form = RegisterForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data['username']
            password1 = form.cleaned_data['password1']
            account = authenticate(username=username, password=password1)
            login(request, account)
            return redirect('register_succes')
        else:
            context["registration_form"] = form
    else:
        form = RegisterForm()
        context['register_form'] = form
    return render(request, "register.html", context)
Example #25
0
 def post(self, request):
     form = RegisterForm(request.POST)
     if form.is_valid():
         user = form.save()
         return render_to_response('register_success.html', RequestContext(request))
         #return HttpResponseRedirect('../../coins/')
     else:
         return self.registerPage(request, form)
Example #26
0
def register_user(request):

	if request.method == "POST":
		form = RegisterForm(request.POST)

		if form.is_valid():
			form.save()

			data = form.cleaned_data
			user = authenticate(username=data['username'], password=data['password'])

			return HttpResponseRedirect('/registerSucces/')

	else:
		form = RegisterForm()

	return render(request, 'register.html', {'form':form})
Example #27
0
 def post(self, request, *args, **kwargs):
     form = RegisterForm(request.POST, request.FILES)
     if form.is_valid():
         user = form.save()
         # send_validation_code.apply_async(kwargs={'pk': user.id })
         messages.info(request, _('You were successfully registered.'
             'Validation link was sent to you'), extra_tags='register')
         return HttpResponseRedirect(reverse('users:code_sent'))
     return self.render_to_response({'form': form})
Example #28
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST, request.FILES)
        if form.is_valid():
            user = form.save(commit=False)
            user.password = make_password(user.password)
            user.save()
            return redirect('/user/login/')
        else:
            return render(request, 'register.html', {'error': form.errors})
    return render(request, 'register.html')
Example #29
0
def register(request):
    ''' This will register a normal a user '''
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            user = form.save()
            auth_login(request, user)
            return HttpResponseRedirect(reverse('register_meter'))
    else:
        form = RegisterForm
    return render(request, 'auth/signup.html', {'form': form})
Example #30
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)  # 用提交来的数据,实例化一个用户注册表单

        if form.is_valid():
            data = form.clean()
            new_user = MyUser.objects.create_user(
                username=data["username"],
                email=data["email"],
                password=data["password"])  # 调用UserManager的方法,注册用户
            form.save()  # 调用表单的 save 方法将用户数据保存到数据库
            # 之后加入邮箱验证,和注册后自动登录
            return redirect('/')  # 注册成功,跳转回首页
    else:
        form = RegisterForm()

    # 渲染模板
    # 如果用户正在访问注册页面,则渲染的是一个空的注册表单
    # 如果用户通过表单提交注册信息,但是数据验证不合法,则渲染的是一个带有错误信息的表单
    return render(request, 'users/register.html', context={'form': form})
Example #31
0
def reg_form(request, token=None):
    status, obj = check_token_status(request, token)
    if not status:
        return obj  # Retuen a template
    reg_token = obj

    if request.method == 'POST':
        form = RegisterForm(request.POST)
        form.instance.backend = 'django.contrib.auth.backends.ModelBackend'
        if form.is_valid():
            with transaction.atomic():
                form.save()
                reg_token.valid = False
                reg_token.user = form.instance
                reg_token.save()

                u = User()
                u = form.instance
                u.profile.title = reg_token.title
                u.profile.display_name = reg_token.display_name
                u.save()
                u.profile.save()
                for g in reg_token.groups.all():
                    g.user_set.add(form.instance)
            try:
                exec(settings.CODE_FOR_REG_NOTIFICATION)
            except AttributeError:
                pass
            login(request, form.instance)
            return redirect('users:edit', username=form.instance.username)

    try:
        error = form.errors
    except UnboundLocalError:
        error = None

    return render(request, 'users/reg_form.html', {
        "token": token,
        "obj": reg_token,
        "error": error,
    })
Example #32
0
def reg_form(request, token=None):
    status, obj = check_token_status(request, token)
    if not status:
        return obj  # Retuen a template
    reg_token = obj

    if request.method == 'POST':
        form = RegisterForm(request.POST)
        form.instance.backend = 'django.contrib.auth.backends.ModelBackend'
        if form.is_valid():
            with transaction.atomic():
                form.save()
                reg_token.valid = False
                reg_token.user = form.instance
                reg_token.save()

                u = User()
                u = form.instance
                u.profile.title = reg_token.title
                u.profile.display_name = reg_token.display_name
                u.save()
                u.profile.save()
                for g in reg_token.groups.all():
                    g.user_set.add(form.instance)
            try:
                exec(settings.CODE_FOR_REG_NOTIFICATION)
            except AttributeError:
                pass
            login(request, form.instance)
            return redirect('users:edit', username=form.instance.username)

    try:
        error = form.errors
    except UnboundLocalError:
        error = None

    return render(request, 'users/reg_form.html', {
        "token": token,
        "obj": reg_token,
        "error": error,
    })
Example #33
0
def register_view(request):
    if request.method == 'GET':
        form = RegisterForm()
    else:  # consider this is POST method only
        form = RegisterForm(request.POST)

        if form.is_valid():
            user = form.save()
            send_register_email(user)
            return redirect(reverse('users:account:login'))

    return render(request, 'users/register.html', {'form': form})
Example #34
0
def register(request):
    if request.method == 'POST':

        form = RegisterForm(request.POST)

        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')

            # email = form.cleaned_data.get('email')
            # password1 = form.cleaned_data.get('password1')
            # password2 = form.cleaned_data.get('password2')
            # # form = RegisterForm(username=username,email=email,password=password,password2=password2)

            messages.success(
                request,
                f'Your account has been created you are now able to login')

            return redirect("users:login")
    else:
        form = RegisterForm()
    return render(request, 'users/register.html ', {'form': form})
Example #35
0
def register(request):
  form = RegisterForm()
  if request.method == 'POST':
    form = RegisterForm(request.POST)
    if form.is_valid():
      user = form.save()
      mail_welcome(user)
      authenticate(request, user)
      util.add_success(request, "Welcome to %s" % ConfigData.get_configdata('SITE_NAME'))
      return redirect(reverse('admin_dashboard'))

  c = template.RequestContext(request, locals())
  return render_to_response('users_register.html', c)
Example #36
0
def register(request):
    # 先从 post 请求中获取 next 参数值,如果没有再从get请求中获取next
    # get 请求中,next 通过 url 传递,即 /?next=value
    # post 请求中,next 通过表单传递,即 <input type="hidden" name="next" value="{{ next }}"/>
    redirect_url = request.POST.get('next', request.GET.get('next'))
    if request.method == "POST":
        # request.POST 是一个类字典数据结构,记录了用户提交的注册信息
        # 这里提交的就是用户名(username)、密码(password)、邮箱(email)
        form = RegisterForm(request.POST)
        # 校验form表单的合法性
        if form.is_valid():
            # 保存到数据库
            form.save()
            # 重定向到登录页
            return redirect('../login')
    else:
        form = RegisterForm()

    return render(request, 'users/register.html', {
        'form': form,
        'next': redirect_url
    })
Example #37
0
def register_view(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            user = form.save()

            send_user_email_verification(request, user)

            messages.success(request, 'Your account has been created!')
            return redirect('users:login')
    else:
        form = RegisterForm()
    return render(request, 'users/register.html', {'form': form})
Example #38
0
def register(request):
    if (request.method=='POST'):
        form = RegisterForm(data=request.POST)
        if(form.is_valid()):
            #check captcha first
            session = UserSession.objects.get(session_key=request.session.session_key)
            print("session captcha: "+session.captcha)
            print("form captcha: "+form.cleaned_data["captcha"])
            if(session.captcha != form.cleaned_data["captcha"]):
                messages.add_message(request, messages.ERROR, _('The captcha was entered wrong.'))
            else:
                referer = request.META.get('HTTP_REFERER')
                user = form.save()
                user.groups.add(Group.objects.get(name='User'))
                user.is_active = False
                user.set_password(user.password)
                user.save()
                import uuid
                lv_uuid = str(uuid.uuid1())[0:30]

                message = """<html>
                <body>
                    <h3>Registration at """+get_current_site(request).name+"""</h3><br/>
                    <p>
                        Please click the following link to end your registration.
                    </p>
                    <p>
                        <a href='https://"""+get_current_site(request).domain+""""/user/activate/"""+lv_uuid+"""/'>Activation Link</a>
                    </p>
                </html>
                """

                send_mail('Registration at '+get_current_site(request).name, 'Hello '+user.username+
                          '\n\nPlease click the following the link to end your registration.\n\n'+
                          'Activation Link: https://'+get_current_site(request).domain+'/user/activate/'+lv_uuid+'/', settings.SYSTEMMAIL,
                        [user.email], fail_silently=False,html_message=message)
                profile = UserProfile()
                profile.user = user
                profile.posts = 0
                profile.threads = 0
                profile.activate = lv_uuid
                profile.theme = Theme.objects.get(default=True)
                profile.banned = False
                profile.save()
                messages.add_message(request, messages.INFO, _('User successful registrated.'))
                #return redirect(urlresolvers.reverse('board.views.index'))
                return redirect(referer)
    else:
        form = RegisterForm()
        f_profile = ProfileForm()
    return render_to_response('user/register.html',{'form':form},context_instance=RequestContext(request))
Example #39
0
def reg_form(request, token=None):
    status, obj = check_token_status(request, token)
    if not status:
        return obj  # Retuen a template
    reg_token = obj

    error = []
    if request.method == 'POST' and not error:
        form = RegisterForm(request.POST)
        form.instance.backend = 'django.contrib.auth.backends.ModelBackend'
        if form.is_valid():
            with transaction.atomic():
                form.save()
                reg_token.valid = False
                reg_token.user = form.instance
                reg_token.save()

                u = User()
                u = form.instance
                u.profile.title = reg_token.title
                u.save()
                for g in reg_token.groups.all():
                    g.user_set.add(form.instance)
            login(request, form.instance)
            return redirect('users:edit fancy',
                            username=form.instance.username)
        else:
            if "username" in form.errors:
                error.append("error_username")
            if "email" in form.errors:
                error.append("error_email")

    return render(request, 'users/reg_form.html', {
        "token": token,
        "title": reg_token.title,
        "error": error,
    })
Example #40
0
def register(request):
    """Register a new user."""
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            # TODO: Send registration email for confirmation.
            user.is_active = True
            user.set_password(form['password'].data)
            user.save()
            return login(request)
    else:  # request.method == 'GET'
        form = RegisterForm()
    return jingo.render(request, 'users/register.html',
                        {'form': form})
Example #41
0
def register(request):
    # 对于表单提交
    if request.method == 'POST':
        form = RegisterForm(request.POST, request.FILES)
        if form.is_valid():
            user = form.save(commit=False)
            # 对user做其他修改
            user.save()
            # 一般session保存比较小的东西,主要是关于用户状态的东西
            request.session['uid'] = user.id
            return redirect('/user/info/?')
        else:
            return render(request, 'register.html', {'errors': form.errors})

    return render(request, 'register.html')
Example #42
0
def reg_form(request, token=None):
    status, obj = check_token_status(request, token)
    if not status:
        return obj  # Retuen a template
    reg_token = obj

    error = []
    if request.method == 'POST' and not error:
        form = RegisterForm(request.POST)
        form.instance.backend = 'django.contrib.auth.backends.ModelBackend'
        if form.is_valid():
            with transaction.atomic():
                form.save()
                reg_token.valid = False
                reg_token.user = form.instance
                reg_token.save()

                u = User()
                u = form.instance
                u.profile.title = reg_token.title
                u.save()
                for g in reg_token.groups.all():
                    g.user_set.add(form.instance)
            login(request, form.instance)
            return redirect('users:edit fancy', username=form.instance.username)
        else:
            if "username" in form.errors:
                error.append("error_username")
            if "email" in form.errors:
                error.append("error_email")

    return render(request, 'users/reg_form.html', {
        "token": token,
        "title": reg_token.title,
        "error": error,
    })
Example #43
0
def register_done(request):
    name = "ola"
    phn = "00"
    if request.method == "POST":
        mlf = RegisterForm(request.POST)
        if mlf.is_valid():
            abc = mlf.save()
            email = mlf.cleaned_data['email']
            password = mlf.cleaned_data['password']
            try:
                email1 = users.objects.get(email=email, password=password)
                request.session['id'] = email1.id
            except ObjectDoesNotExist:
                pass
    else:
        name = "Error"
    form = RegisterForm(request.POST)
    return render(request, 'register_done.html', {"name": name, "phno": form})
Example #44
0
def register(request):
    d = {}
    d["url"] = "/register"
    d["sub"] = "Register"
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            u = form.save(commit = False)
            password = form.cleaned_data["password"]
            u.set_password(password)
            u.save()
            return HttpResponseRedirect("/")
        else:
            d["form"] =form
            return render(request,"register.html",d)

    else:
        d["form"] = RegisterForm()
        return render(request,"register.html",d)
Example #45
0
def new(request):
    """
    Renders the signup form, allowing a user to create a new user.
    Processes results from the form, attempting to create a new user.
    If new user is created, redirects to the users profile
    
    @renders: users/new.html to show the signup form
    @redirects: /user/<username> to show the newly created users profile.
    """
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            new_user = authenticate(username=request.POST['username'],
                                    password=request.POST['password1'])
            login(request, new_user)
            return redirect("/user/" + new_user.username)
    else:
        form = RegisterForm()
    return render(request, "users/new.html", {'form': form})
Example #46
0
def register(request):
    form = RegisterForm(request.POST)
    if form.is_valid():
        user = form.save(commit=False)

        # Generate activation key for user account
        activation_key = generate_activation_key(user.email)
        user.activation_key = activation_key
        user.is_active = False
        user.save()

        send_email.delay('mail/confirmation', {'link': activation_key},
                   u'\u2713 ' + _("Welcome to Prestashop-Sync Service"), [user.email])
        return HttpResponse(simplejson.dumps({'response': _("Email with a confirmation link has been sent"),
                                       'result': 'success'}))
    else:
        response = {}
        for k in form.errors:
            response[k] = form.errors[k][0]
        return HttpResponse(simplejson.dumps({'response': response, 'result': 'error'}))
Example #47
0
def register(request):
    """Регистрация нового пользователя"""

    if request.POST:
        if request.POST.get("type") == "wholesale":
            return redirect(reverse("users.auth.register.wholesale"))

        form = RegisterForm(request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.set_password(form.cleaned_data["password"])
            instance.save()
            instance = authenticate(email=instance.email, password=form.cleaned_data["password"])
            user_login(request, instance)

            return redirect(reverse("users.auth.register.completed"))

    else:
        form = RegisterForm()

    context = {"form": form}

    return render(request, "users/auth/register.html", context)