示例#1
0
def register(request):
    if request.method == 'POST': # If the form has been submitted... 
        # ContactForm was defined in the previous section 
        form = UserRegForm(request.POST) # A form bound to the POST data 
        if form.is_valid(): # All validation rules pass 
            # Process the data in form.cleaned_data 
            # ... 
            first_name=request.POST["first_name"]
            last_name= request.POST["last_name"] 
            user_name=request.POST["username"] 
            pass_word=request.POST["password"]  
            password2=request.POST["password2"] 
            emailid=request.POST["email"] 
            user = User.objects.filter(email=emailid).exists() 
            user1 = User.objects.filter(username=user_name).exists()  
            if user is False and user1 is False: 
                user = User.objects.create_user(user_name,emailid,pass_word) 
                user.last_name = last_name 
                user.first_name = first_name                            
                return HttpResponseRedirect(reverse('polls:created_user'))
            else:
                return render(request, 'polls/register.html', {'form':form, 'error_message':"Already Registered"},)
        else:
            return render(request, 'polls/register.html', {'form':form},)
    else:
        form=UserRegForm()
        return render(request, 'polls/register.html', {'form':form},)
示例#2
0
文件: views.py 项目: jsmoxon/Roomater
def create_search_profile(request):
    if request.method == "POST":
        user_form = UserRegForm(request.POST)
        form = SearchRegForm(request.POST, request.FILES)
        if form.is_valid() and user_form.is_valid():
            # upload photo
            file = request.FILES["file"]
            store_in_s3(file)
            p = PhotoUrl(url="http://roommater.s3.amazonaws.com/" + str(file))
            p.save()
            user = User.objects.create_user(request.POST["username"], request.POST["email"], request.POST["password"])
            newprofile = UserProfile(pic=p.url, user=user, name=request.POST["name"], about=request.POST["about"])
            newprofile.save()
            username = request.POST["username"]
            password = request.POST["password"]
            user = authenticate(username=username, password=password)
            login(request, user)
            if request.REQUEST.get("next" "") != None:
                redirect_to = request.REQUEST.get("next" "")
            else:
                redirect_to = "/dash/"
            return redirect(redirect_to)
    else:
        user_form = UserRegForm()
        form = SearchRegForm()
    return render_to_response(
        "registration/login.html", {"form": form, "user_form": user_form}, context_instance=RequestContext(request)
    )
示例#3
0
文件: views.py 项目: jsmoxon/Roomater
def create_survey(request):
    standard_questions = Question.objects.filter(standard=True)
    if not request.method == "POST":
        form = ListRegForm()
        user_form = UserRegForm(request.POST)
        return render_to_response(
            "create_survey.html",
            {"form": form, "user_form": user_form, "standard": standard_questions},
            context_instance=RequestContext(request),
        )
    form = ListRegForm(request.POST, request.FILES)
    user_form = UserRegForm(request.POST)
    print "post"
    if not form.is_valid() or not user_form.is_valid():
        print "something not valid"
        return render_to_response(
            "create_survey.html",
            {"form": form, "user_form": user_form, "standard": standard_questions},
            context_instance=RequestContext(request),
        )
    try:
        file = request.FILES["file"]
        store_in_s3(file)
        p = PhotoUrl(url="http://roommater.s3.amazonaws.com/" + str(file))
        p.save()
        picture = p.url
    except:
        picture = ""
    # create a new user and profile
    user = User.objects.create_user(request.POST["username"], request.POST["email"], request.POST["password"])
    newprofile = UserProfile(pic=picture, user=user, name=request.POST["name"], about=request.POST["about"])
    newprofile.save()
    # log the new user in
    username = request.POST["username"]
    password = request.POST["password"]
    user = authenticate(username=username, password=password)
    login(request, user)
    # submit the survey they just made
    room = Room(
        price=request.POST["price"],
        address=request.POST["address"],
        city=request.POST["city"],
        state=request.POST["state"],
        zip=request.POST["zip"],
        about=request.POST["room_about"],
        lat=geo_code(request.POST["address"], request.POST["city"], request.POST["state"], request.POST["zip"])[0],
        lng=geo_code(request.POST["address"], request.POST["city"], request.POST["state"], request.POST["zip"])[1],
    )
    room.save()
    #    print geo_code(request.POST["address"], request.POST["city"])[0]
    submit_create_survey(request, room)
    return redirect("/dash/")
示例#4
0
def register():
    form = UserRegForm(request.form)
    if request.method == 'POST' and form.validate():
        user = create_user("local_%s" % form.data['name'],
                           form.data["name"],
                           form.data['email'],
                           copper_coins=5000,
                           password=form.data['password'])
        cache.set(str(user.id), user)
        if login_user(user, remember=True):
            return redirect(request.args.get("next") or "/")
    #print form.data["name"], type(form.data["name"])
    return render_template("reg.html", form=form)
示例#5
0
def register(request):
	args = {}
	args.update(csrf(request))
	args['form'] = UserRegForm()
	if request.POST:
		newuser_form = UserRegForm(request.POST)
		if newuser_form.is_valid():
			newuser_form.save()
			newuser = auth.authenticate(username=newuser_form.cleaned_data['username'], first_name=newuser_form.cleaned_data['first_name'], last_name=newuser_form.cleaned_data['last_name'], email=newuser_form.cleaned_data['email'], password=newuser_form.cleaned_data['password2'])
			auth.login(request, newuser)
			return redirect('/auth/login/')
		else:
			args['form'] = newuser_form
	return render_to_response('register.html', args)
示例#6
0
def register():
    form = UserRegForm(request.form)
    if request.method == "POST" and form.validate():
        user = create_user(
            "local_%s" % form.data["name"],
            form.data["name"],
            form.data["email"],
            copper_coins=5000,
            password=form.data["password"],
        )
        cache.set(str(user.id), user)
        if login_user(user, remember=True):
            return redirect(request.args.get("next") or "/")
    # print form.data["name"], type(form.data["name"])
    return render_template("reg.html", form=form)
示例#7
0
def register():
    form = UserRegForm()
    if form.validate_on_submit():
        user = UserData(email=form.email.data,
                        f_name=form.f_name.data,
                        l_name=form.l_name.data,
                        phone=form.phone_no.data,
                        country=form.country.data,
                        password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation()
        send_email(user.email, 'Confirm Your account', 'confirm', user=user, token=token)
        flash('A confirmation has been sent to your mail')
        return redirect(url_for('login'))
    return render_template('registeration.html', form=form)
示例#8
0
def register(request):
    if request.user.is_authenticated():
        return redirect("/ewybory/home")
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = UserProfileForm(request.POST)
        form2 = UserRegForm(request.POST);
        # check whether it's valid:
        if form.is_valid() and form2.is_valid():
            usprof = form.save(commit=False)
            usr = form2.save();
            usprof.user=usr;
            usprof.save();
            return render(request, 'registerSuccess.html')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = UserProfileForm()
        form2 = UserRegForm();
    return render(request, 'register.html', {'regform': form, 'reg1form':form2})