Exemple #1
0
def register_user(request):
    emailValue="" 	
    nameValue=""
    phNo=""	
    if request.method == 'POST':
        form=CustomUserCreationForm(request.POST)
        print("printing from register_user")	
        formStr=str(form)	
        #print(formStr)		
        	
        soup = BeautifulSoup.BeautifulSoup(formStr)
        val=soup.find(id="id_email")
        print(val['value'])	
        emailValue=val['value']	
        try:		
            is_valid = validate_email(val['value'],verify=True)
        except Exception, e:
            is_valid=False		
        val=soup.find(id="id_phoneNo")
        phNo=val['value']
        val=soup.find(id="id_first_name")
        nameValue=val['value']		
        print("is_valid")
        print(is_valid)				
        #print(form.Meta.model.USERNAME_FIELD)		
        #print(formStr)		
        	
        if (form.is_valid() & is_valid):
            form.save()
            #languages_known_v = form.Languages
            log = logging.getLogger("wa")
            #log.info(languages_known_v)
            return HttpResponseRedirect('/wa/register_success')
        else:
            form=CustomUserCreationForm(request.POST)
Exemple #2
0
def register(request):
    if request.method == 'POST':
        user_form = CustomUserCreationForm(request.POST)
        if user_form.is_valid():
            user_form.save()
            return redirect(settings.LOGIN_URL)
    else:
        user_form = CustomUserCreationForm()
    return render(request, 'core/register.html', {'form': user_form})
Exemple #3
0
def register_user(request):
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)

        # see if user with this email already exists
        try:
            user = User.objects.get(email=form.data['email'])
            return render_to_response('invalid_user.html')
        except:
            pass

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

            # get new user record id to use in verification link
            try:
                user_id = User.objects.get(email=form.cleaned_data['email']).pk
            except:
                user_id = 0

            # encrypt the user_id
            pad = encode(user_id)
            subject, from_email, to = 'Verify registration', '*****@*****.**', form.cleaned_data[
                'email']

            # verification url for email
            verify_url = request.build_absolute_uri() + pad
            send_verification_email(subject, from_email, to, verify_url)

            if user_id != 0:
                # if cell # entered, send SMS confirmation message
                user = User.objects.get(pk=user_id)
                text = "Your account has been created. "
                cell = filter(lambda c: c in string.digits + '', user.cell)
                if len(cell) > 0:
                    send_sms_msg('Notification', text, from_email, cell,
                                 user.carrier)

            if len(form.cleaned_data['alias']) == 0:
                try:  # default alias to email prefix
                    email = form.cleaned_data['email']
                    record = User.objects.get(email=email)
                    prefix = email[:email.find('@')]
                    record.alias = prefix
                    record.save()
                except:
                    pass

            return HttpResponseRedirect('/user/register_success')
        else:
            print form.errors  # see the form errors in the console.

    args = {}
    args.update(csrf(request))

    args['form'] = CustomUserCreationForm()
    return render_to_response('register.html', args)
Exemple #4
0
def register_user(request):
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)

        # see if user with this email already exists
        try:
            user = User.objects.get(email=form.data['email'])
            return render_to_response('invalid_user.html')
        except:
            pass

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

            # get new user record id to use in verification link
            try:
                user_id = User.objects.get(email=form.cleaned_data['email']).pk
            except:
                user_id = 0

            # encrypt the user_id
            pad = encode(user_id)
            subject, from_email, to = 'Verify registration', '*****@*****.**', form.cleaned_data['email']

            # verification url for email
            verify_url = request.build_absolute_uri()+pad
            send_verification_email(subject, from_email, to, verify_url) 

            if user_id != 0:
            # if cell # entered, send SMS confirmation message
                user = User.objects.get(pk=user_id)
                text = "Your account has been created. "
                cell = filter(lambda c: c in string.digits + '', user.cell)
                if len(cell) > 0:
                    send_sms_msg('Notification', text, from_email, cell, user.carrier)

            if len(form.cleaned_data['alias']) == 0:
                try:  # default alias to email prefix
                    email = form.cleaned_data['email']
                    record = User.objects.get(email=email)
                    prefix=email[:email.find('@')]
                    record.alias = prefix
                    record.save()
                except:
                    pass

            return HttpResponseRedirect('/user/register_success')
        else:
            print form.errors  # see the form errors in the console.

    args = {}
    args.update(csrf(request))
	
    args['form'] = CustomUserCreationForm()
    return render_to_response('register.html', args)
Exemple #5
0
def register_user(request):
	if request.method == 'POST':
		form=CustomUserCreationForm(request.POST)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/WikiApp/register_success')
	else:
		form= CustomUserCreationForm()
	return render(request,  'WikiApp/session/register.html', {
		'form': form,
	})
Exemple #6
0
def register_user(request):
	if request.method == 'POST':
		form=CustomUserCreationForm(request.POST)
	#for field in form.fields:
	#form.fields[field].required = False
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/wa/register_success')
	else:
		form= CustomUserCreationForm()
	#else:
	#	return render(request,  'wa/session/register.html', {'form': CustomUserCreationForm(request.POST),})
		return render(request,  'wa/session/register.html',{'form':form})
Exemple #7
0
def register_user(request):
    form = CustomUserCreationForm(request.POST)

    if not form.is_valid():
        return HttpResponseBadRequest(_("Submitted data not valid."))

    cd = form.cleaned_data

    user = form.save()
    user = authenticate(email=cd['email'], password=cd['password'])
    login(request, user)

    return HttpResponse(unicode(user))
Exemple #8
0
def register_user(request):
    form = CustomUserCreationForm(request.POST)

    if not form.is_valid():
        return HttpResponseBadRequest(_("Submitted data not valid."))

    cd = form.cleaned_data

    user = form.save()
    user = authenticate(email=cd['email'], password=cd['password'])
    login(request, user)

    return HttpResponse(unicode(user))
Exemple #9
0
def register(request):
    """Register the new user"""
    if request.method != 'POST':
        form = CustomUserCreationForm()
    else:
        print(request.POST)
        form = CustomUserCreationForm(data=request.POST)
        if form.is_valid():
            new_user = form.save()
            authenticated_user = authenticate(
                username=new_user.username, password=request.POST['password1'])
            login(request, authenticated_user)
            return HttpResponseRedirect(reverse('learning_logs:index'))
    context = {'form': form}
    return render(request, 'users/register.html', context)
Exemple #10
0
def userregister(request):
    # Initialize the form either fresh or with the appropriate POST data as the instance
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            new_user = authenticate(username=user.username,
                                    password=request.POST['password1'])
            auth_login(request, new_user)
            messages.success(request, 'Registration complete')
            return HttpResponseRedirect(reverse('profile-update'))
    else:
        form = CustomUserCreationForm()

    return render(request, 'accounts/register.html', {
        'form': form,
    })
Exemple #11
0
def userregister(request):
    # Initialize the form either fresh or with the appropriate POST data as the instance
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            new_user = authenticate(username=user.username,
                                    password=request.POST['password1'])
            auth_login(request, new_user)
            messages.success(request, 'Registration complete')
            return HttpResponseRedirect(reverse('profile-update'))
    else:
        form = CustomUserCreationForm()

    return render(request, 'accounts/register.html', {
        'form': form,
    })
Exemple #12
0
def signup(request):

  context = {}

  form = CustomUserCreationForm()

  context['form'] = form 

  if request.method == 'POST':
    
    form = CustomUserCreationForm(request.POST)

    if form.is_valid():

      print form.cleaned_data 
      # name = form.cleaned_data['name']
      email = form.cleaned_data.get('email', None)
      password = form.cleaned_data.get('password', None)


      try:
        form.save()
        # new_user = User.objects.create_user(email, password)
        context['valid'] = "Thank You For Signing Up and Welcome to Reyathena!"
        
        # auth_user = authenticate(username=email, password=password)
        # login(request, auth_user)

        return HttpResponseRedirect('/sport_list/')

      except IntegrityError as e:
        context['valid'] = "We know its annoying but, a User With That Name Already Exists"
        message = """
        We know its annoying but, a User With That Name Already Exists
        <a href= '/login_view/'>login<a>
        """

        return HttpResponse(message)
    else:
      context['valid'] = form.errors

  elif request.method == 'GET':
    context['valid'] = "Please join Reyathena and Sign Up!"

  return render (request, 'signup.html', context)
Exemple #13
0
def register(request):
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            log.info('{} is a new user!'.format(request.user.username))
            form.save()
            return redirect('home')
        else:
            form = CustomUserCreationForm()
            error = "Try Again!"
            args = {'form': form, 'erro': error}
            log.info('Someone tried create profile!')
            return render(request, 'account/signup.html', args)
    else:
        form = CustomUserCreationForm()
        error = ''
        args = {'form': form, 'erro': error}
        return render(request, 'account/signup.html', args)
Exemple #14
0
def create(request):
    """
    """
    print "inside create"
    if request.method == 'POST': # If the form has been submitted...
        form = CustomUserCreationForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            print "form is valid"
            # CreatingUser
            # ...
            user = form.save(commit=True)
            password = form.cleaned_data['password1']
            # request.POST['password1'] = request.POST['password2']
            auth_user = authenticate(username=user.username, password=password)
            if auth_user is not None:
                login(request, auth_user)
                if user.first_name and user.last_name:
                    response_data = {
                        "username": user.username,
                        "email": user.email,
                        "first_name": user.first_name,
                        "last_name": user.last_name,
                    }
                else:
                    response_data = {
                        "username": user.username,
                        "email": user.email,
                    }
                return HttpResponse(json.dumps(response_data), content_type="application/json")
        else:
            response_data = {
                "err": dict(form.errors.items())
            }
            return HttpResponse(json.dumps(response_data), content_type="application/json")
            #return redirect("mm_login")
            #return HttpResponse("Got User form, user is %s" % user.username)
            #return HttpResponseRedirect('/thanks/') # Redirect after POST
    else:
        form = CustomUserCreationForm() # An unbound form

        return render_to_response('registration/create.html', {
            'form': form},
            context_instance = RequestContext(request)
        )
Exemple #15
0
def register(request, template_name="docs/authors/signup.html"):
    redirect_to_url = reverse('docs:index')
    if request.user.is_authenticated():
        return HttpResponseRedirect(redirect_to_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            ue = postdata.get('username', '')
            pw = postdata.get('password1', '')
            new_user = authenticate(username=ue, password=pw)
            if new_user and new_user.is_active:
                login(request, new_user)
                return HttpResponseRedirect(redirect_to_url)
            
    else:
        form = CustomUserCreationForm()
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
Exemple #16
0
def register(request):
    #user = User(username="", password="")
    #form_user = CustomUserCreationForm()#instance=user)
    #ProfileInlineFormset = inlineformset_factory(User, Player, fields=('DCI',))
    #formset = ProfileInlineFormset()#instance=user)
    if request.method == 'POST':
        form_user = CustomUserCreationForm(request.POST)#, instance=user)
        #formset = ProfileInlineFormset(request.POST)#, instance=user)
        if form_user.is_valid():
            form_user.save()
            #formset = ProfileInlineFormset(request.POST, instance=created_user)
            #if formset.is_valid():
            #    created_user.save()
                #formset.save()
            return HttpResponseRedirect('/register/complete')
    else:
        form_user = CustomUserCreationForm()
    token = {}
    token.update(csrf(request))
    token['noodle_form'] = form_user
    #token['formset'] = formset
    return render(request, 'registration/registration_form.html', context=token)