def register(request): error = False message = "" if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid() and form.cleaned_data['password'] == form.cleaned_data['password_confirm']: complete = True username = form.cleaned_data['username'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] user = User.objects.filter(email=email) user2 = User.objects.filter(username=username) if user: message = "Email address already in use" error = True elif user2: message = "Username already in use" error = True else: user3 = User.objects.create_user(username, email, password) return redirect("home.views.home_page") else: error = True message = "Fields incomplete." else: form = RegistrationForm() return render(request, "home/register.html", locals())
def registration(request): print "Registering" # Like before, get the request's context. context = RequestContext(request) # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': print "POST request" user_form = RegistrationForm(request.POST) # If the two forms are valid... if user_form.is_valid(): print "Is valid" # Save the user's form data to the database. user = user_form.save() print "Saved form" # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.is_active = False print "Saving user" user.save() #Create And Send User Activation Email. confirmation_code = ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for x in range(33)) print "adding confirmation code to user" p = UserProfile(user=user, confirmation_code=confirmation_code) p.save() title = "Textile Fabric Consultants, Inc. Account Activation" content = "Someone has recently registered at Textilefabric.com. We hope it was you. If so, please follow the link below. If not please disregard this email.\n" +"theftp.dyndns.org:8000/login/activate/" + str(p.confirmation_code) + "/" + user.username send_mail(title, content, '*****@*****.**', [user.email], fail_silently=False) #Update our variable to tell the template registration was successful. registered = True print "sent email" # Invalid form or forms - mistakes or something else? # Print problems to the terminal. # They'll also be shown to the user. else: print user_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. form = RegistrationForm(request.POST) form_html = render_crispy_form(form) result = {'success': registered, 'form_html': form_html} return result
def test_valid_data(self): form_data = { 'username': '******', 'email': '*****@*****.**', 'password1': 'test', 'password2': 'test', 'city': 'test', 'state': 'test', 'zip_code': 'test' } form = RegistrationForm(data=form_data) self.assertTrue(form.is_valid())
def register(request): if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user( username=form.cleaned_data["username"], password=form.cleaned_data["password1"] ) user.userprofile.city = form.cleaned_data["city"] user.userprofile.state = form.cleaned_data["state"] user.userprofile.street = form.cleaned_data["street"] user.userprofile.zip_code = form.cleaned_data["zip_code"] user.userprofile.save() return HttpResponseRedirect("/register/success/") else: form = RegistrationForm() variables = RequestContext(request, {"form": form}) return render_to_response("registration/register.html", variables)
def register_user_view(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() messages.success(request, 'You have successfully registered. Please login.') return render(request, 'login/login.html') args ={} args.update(csrf(request)) args['form'] = RegistrationForm() print args return render(request, 'login/register.html', args)
def index(request): context = RequestContext(request) # get the blog posts that are published posts = Post.objects.filter(published=True) # now return the rendered template return render_to_response('blog/index.html', { 'posts': posts, 'regform': RegistrationForm(), 'loginform': LoginForm() }, context)
def register(request): if request.method == 'POST': form = RegistrationForm(data=request.POST) if form.is_valid(): form.save() return redirect('..') # return render(request, 'rsvp/home.html',{}) # HttpResponseRedirect('/rsvp/') else: form = RegistrationForm() args = {'form': form} return render(request, 'login/reg_form.html', args) else: form = RegistrationForm() args = {'form': form} return render(request, 'login/reg_form.html', args)
def signup_view(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('/login/loginpage') else: form = RegistrationForm() return render(request,'login/signup.html',{'form':form})
def register(request, template_name): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): # create new user new_user = User.objects.create_user( username=form.cleaned_data['username'], password=form.cleaned_data['password1'], email='useless') # new_user.is_active = False # new_user.save() # # Build the activation key for their account # salt = sha.new(str(random.random())).hexdigest()[:5] # activation_key = sha.new(salt+new_user.username).hexdigest() # # Create and save their profile # new_profile = Challenger(user=new_user, # activation_key=activation_key) # new_profile.save() # Send an email with the confirmation link # email_subject = 'Your new account confirmation' # email_body = "Hello, %s, and thanks for signing up for an ssmpg 2015 account!\n\nTo activate your account, click this link: \n\nhttp://localhost:8000/login/confirm/%s" % ( new_user.username, new_profile.activation_key ) # send_mail(email_subject, # email_body, # '*****@*****.**', # [new_user.email]) # return render_to_response( # 'login/success.html', # RequestContext( request, { 'confirm': True } ) # ) return render(request, 'login/confirm.html', {'success': True}) else: form = RegistrationForm() return render(request, template_name, {'form': form})
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save(request) return redirect("/home") else: form = RegistrationForm() args = {'form': form} return render(request, 'account/register.html', args)
def register(): form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data, location=form.location.data, admin=form.admin.data) user.set_password(form.password.data) user.calculateLatLng() loginDB.session.add(user) loginDB.session.commit() flash("Congratulations, you are a new registered user!") response = redirect(urlsConfig.URLS['newsfeed_url']) response.set_cookie("currentSessionCookie", str(user.id)) return response return render_template("register.html", title="Register", registerForm=form)
def register(request): if request.method == 'POST': form_1 = RegistrationForm(request.POST) form_2 = UserProfileForm(request.POST) if form_1.is_valid() and form_2.is_valid(): new_user = form_1.save(commit=False) new_user.set_password(form_1.cleaned_data['password1']) new_user.save() UserProfile.objects.create(user=new_user, USN=form_2.cleaned_data['USN'], year=form_2.cleaned_data['year'], sem=form_2.cleaned_data['sem'], phone=form_2.cleaned_data['phone']) #subject = 'Thank you for registering with Book-Share' #message = 'Dear User,\n\n Hope you take the best advantage of UVCE Book-share platform . Have a nice time !\n\n Thank You' #from_email = settings.EMAIL_HOST_USER #to_list = [save_1.email] #send_mail(subject,message,from_email,to_list,fail_silently=True) messages.success(request, 'Thank you for registering ! Login Here ') return redirect('/login/') else: form_1 = RegistrationForm() form_2 = UserProfileForm() args = {'form_1': form_1, 'form_2': form_2} return render(request, 'account/register.html', args)
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) profile_form = UserProfileForm(request.POST) if form.is_valid() and profile_form.is_valid(): user = User.objects.create_user( username=form.cleaned_data['username'], password=form.cleaned_data['password'], email=form.cleaned_data['email'], first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], ) # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user #print profile_form.phone # Did the user provide a profile picture? # If so, we need to get it from the input form and put it in the UserProfile model. if 'picture' in request.FILES: profile.picture = request.FILES['picture'] # Now we save the UserProfile model instance. profile.save() return HttpResponseRedirect('/register/success/') else: form = RegistrationForm() profile_form = UserProfileForm() variables = RequestContext(request, { 'form': form, 'profile_form': profile_form }) return render_to_response( 'registration/register.html', variables, )
def webstore(request, id): context = RequestContext(request) #if request.method == 'GET': ids = StoreCategory.objects.get(categoryName=id) items = StoreItem.objects.filter(category_id=ids.id).all() item_categories = StoreCategory.objects.all() return render_to_response( 'store/shop-homepage.html', { 'items': items, 'item_categories': item_categories, 'regform': RegistrationForm(), 'loginform': LoginForm() }, context)
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user( username=form.cleaned_data['username'], password=form.cleaned_data['password1'], ) user.userprofile.city = form.cleaned_data['city'] user.userprofile.state = form.cleaned_data['state'] user.userprofile.street = form.cleaned_data['street'] user.userprofile.zip_code = form.cleaned_data['zip_code'] user.userprofile.save() return HttpResponseRedirect('/register/success/') else: form = RegistrationForm() variables = RequestContext(request, {'form': form}) return render_to_response( 'registration/register.html', variables, )
def register(request): if request.method == 'POST': regForm = RegistrationForm(request.POST) if regForm.is_valid(): try: username = regForm.cleaned_data['email'] email = username first_name = regForm.cleaned_data['first_name'] last_name = regForm.cleaned_data['last_name'] org_name = regForm.cleaned_data['org_name'] org_id = regForm.cleaned_data['org_id'] password = regForm.cleaned_data['password'] user = User.objects.create_user(username = username,password = password) user.first_name = first_name user.last_name = last_name user.email = email #user.users = 'organisation' #user.set_password = password org_det = OrganizationDetails() org_det.org_name = org_name org_det.org_id = org_id org_det.user = user group = Group.objects.get(name='gov_official') if "@gov.in" not in email: group = Group.objects.get(name='private_organization') user.save() user.groups.add(group) org_det.save() login(request,user) return redirect('/') except: return render(request,'login/register.html',{"error_message":"Organization or email already exists!"}) return render(request,'login/register.html')
def signup(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect(reverse('index-home')) else: args = {'form': form} return render(request, 'login/signup.html', args) else: form = RegistrationForm() args = {'form': form} return render(request, 'login/signup.html', args)
def register(request): ''' registers users ''' # redirect user to home if user is already signed in if request.user.is_authenticated: extra_context = { 'extra_context': { 'message': 'True', 'message_title': 'Warning: ', 'message_text': 'You are already logged in' } } return render(request, 'shop/home.html', extra_context) # if request is post if request.method == 'POST': # get the post form form = RegistrationForm(request.POST) # check to see if the form is valid if form.is_valid(): # if it is valid, save and redirect to home form.save() # TODO: Keep logged in after registered? extra_context = { 'extra_context': { "page": "home", 'message': 'True', 'message_title': 'Register: ', 'message_text': 'You have successfully created an account' } } return render(request, 'shop/home.html', extra_context) else: # form is not valid and return form with error args = {'form': form} return render(request, 'login/register.html', args) # if request is not post, user probably wants the webpage with a empty form else: # give user clean register form form = RegistrationForm() args = {'form': form} return render(request, 'login/register.html', args)
def register_user_view(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() messages.success( request, 'You have successfully registered. Please login.') return render(request, 'login/login.html') args = {} args.update(csrf(request)) args['form'] = RegistrationForm() print args return render(request, 'login/register.html', args)
def register(request): # TODO: change redirects to render with messages if request.user.is_authenticated: extra_context = { 'extra_context': { 'message': 'True', 'message_title': 'Warning: ', 'message_text': 'You are already logged in' } } return render(request, 'login/home.html', extra_context) if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('home') else: form = RegistrationForm() args = {'form': form} return render(request, 'login/register.html', args)
def registration(request): if not request.user.is_authenticated: if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = form.save() # user = authenticate(request, # username=form.cleaned_data['user_name'], # password=form.cleaned_data['password1'], # ) # if user is not None: login(request, user) return redirect('mychar:edit') else: form = RegistrationForm() return render(request, 'login/register.html', { 'form': form, }) else: return redirect('home:index')
def home(request): context = RequestContext(request) return render_to_response('store/shop-homepage.html', {'regform': RegistrationForm(),'loginform': LoginForm()},context )
def webstore(request,id): context = RequestContext(request) #if request.method == 'GET': ids = StoreCategory.objects.get(categoryName=id) items = StoreItem.objects.filter(category_id=ids.id).all() item_categories = StoreCategory.objects.all(); if not 'cartList' in request.session: # if there is no cart, make one then get its details print "making a new cart" request.session['cartList'] = [] initialcart = buildCartDetail(request.session['cartList']) subtotal = getSubtotal(initialcart) return render_to_response('store/shop-homepage.html', {'initialcart':initialcart, 'subtotal':subtotal, 'items': items, 'item_categories': item_categories, 'regform': RegistrationForm(),'loginform': LoginForm()},context)
def about(request): context = RequestContext(request) return render_to_response('about.html', { 'regform': RegistrationForm(), 'loginform': LoginForm() }, context)
def register(request): form = RegistrationForm() context = {'form': form} return render(request, 'registration/register.html', context)