def register(request): registered = False response = {} if request.method == "POST": method = request.POST['method'] user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) mobile_id = request.POST['mobile_id'] print profile_form if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) user.set_password(user.password) user.is_active = True user.save() profile = profile_form.save(commit=False) profile.user = user profile.mobile_id = mobile_id profile.lastLoginDate = datetime.now() profile.ipaddress = get_client_ip(request) profile.save() registered = True response['success'] = 1 else: print user_form.errors, profile_form.errors response['success'] = 0 return JsonResponse(response)
def register(request): registered = False if request.method == "POST": user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) print profile_form print request.FILES['picture'] if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) user.set_password(user.password) user.is_active = True user.save() profile = profile_form.save(commit=False) profile.user = user profile.lastLoginDate = datetime.now() profile.ipaddress = get_client_ip(request) if request.FILES['picture']: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors messages.info(request, str(user_form.errors) + str(profile_form.errors)) else: user_form = UserForm() profile_form = UserProfileForm() return render(request,'site/register.html',{'title':'Sign Up','current_page':'register',\ 'user_form':user_form,'profile_form':profile_form,'registered':registered})
def register(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() new_user = authenticate(username=request.POST['username'], password=request.POST['password']) login(request, new_user) registered = True return HttpResponseRedirect('/') else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response( 'authentication/register.html', {'user_form': user_form, 'profile_form': profile_form}, context)
def register(request): registered = False if request.method == "POST": user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) print profile_form print request.FILES['picture'] if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) user.set_password(user.password) user.is_active=True user.save() profile = profile_form.save(commit=False) profile.user = user profile.lastLoginDate = datetime.now() profile.ipaddress=get_client_ip(request) if request.FILES['picture']: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors messages.info(request,str(user_form.errors)+str(profile_form.errors)) else: user_form = UserForm() profile_form = UserProfileForm() return render(request,'site/register.html',{'title':'Sign Up','current_page':'register',\ 'user_form':user_form,'profile_form':profile_form,'registered':registered})
def register(request): template = 'authentication/register.html' registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() registered = True #messages.success(request, "Usuario registrado") return HttpResponseRedirect(reverse('log:login')) else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileForm() data = { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered } return render(request, template, data)
def edit_profile(request): template_name = "edit_profile.html" if request.method == 'POST': userProfileForm = UserProfileForm(request.POST, instance=request.user.userprofile) print(userProfileForm.errors) if userProfileForm.is_valid(): userProfileForm.save() return redirect('/authentication/profile') else: userProfileForm = UserProfileForm(instance=request.user.userprofile) args = {'userProfileForm': userProfileForm} return render(request, 'edit_profile.html', args)
def register(request): if request.user.is_authenticated(): return redirect("/") else: # 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': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() # 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 # 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() # Update our variable to tell the template registration was successful. registered = True # 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, profile_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render(request, 'authentication/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )
def update(request, id): """ Update User data """ user = get_object_or_404(User, pk=id) user_form = UserForm(data=request.POST or None, instance=user) profile_form = UserProfileForm(data=request.POST or None, files=request.FILES or None, instance=user.userprofile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() messages.success(request, 'Usuario actualizado!') context = { 'user_form': user_form, 'profile_form': profile_form, 'menu': 'users' } return render(request, 'users/update.html', context)
def user_profile(request, pk=None): user = request.user if pk is None else User.objects.get(pk=pk) table = PlaceTable(Place.objects.filter(user=user.id)) table.paginate(page=request.GET.get("page", 1), per_page=25) RequestConfig(request).configure(table) if request.method == 'GET': context = { 'profile_user': user, 'profile': user.userprofile, 'establishments': user.establishment_set.all(), 'places': user.place_set.all(), 'form': UserProfileForm(), 'table': table, } return render(request, 'accounts/user_profile.html', context) else: form = UserProfileForm(request.POST, request.FILES, instance=user.userprofile) if form.is_valid(): form.save() return redirect('current user profile') return redirect('current user profile')
def signup(request): print "please signup here..." if request.method == "POST": print "yes" print request.POST, "asdasd" form = UserProfileForm(request.POST) if form.is_valid(): print "valid..." new = form.save(commit=False) new.save() else: print form.errors return render(request, "signup.html")
def signup(request): if request.method == 'POST': form = UserProfileForm(request.POST) if not form.is_valid(): print form.errors messages.add_message( request, messages.ERROR, 'There was some problems while creating your account. Please review some fields before submiting again.' ) return render(request, 'signup.html', {'form': form}) else: new_user = form.save(commit=False) new_user.adminuserid = 0 new_user.save() messages.add_message(request, messages.SUCCESS, 'Your account were successfully created.') return HttpResponseRedirect('/authentication/signup/') else: return render(request, 'signup.html', {'form': UserProfileForm()})
def register(request): if request.method == 'POST': form = ExtendedUserCreationForm(request.POST) profile_form = UserProfileForm(request.POST) if form.is_valid() and profile_form.is_valid(): user = form.save() profile = profile_form.save(commit=False) profile.user = user profile.save() username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = authenticate(username=username, password=password) sign_in(request, user) return redirect('home:index') else: form = ExtendedUserCreationForm() profile_form = UserProfileForm() context = {'form': form, 'profile_form': profile_form} return render(request, 'auth/register.html', context)
def register(request): registered = False if request.method == "POST": user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) user.set_password(user.password) user.last_login = datetime.now() user.is_active = True user.save() profile = profile_form.save(commit=False) print user profile.user = user profile.signUpDate = datetime.now() profile.ip_address = get_client_ip(request) print profile.ip_address if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print 'user' + str(user_form.errors) print 'profile' + str(profile_form.errors) messages.info(request, str(user_form.errors) + str(profile_form.errors)) else: user_form = UserForm() profile_form = UserProfileForm() return render( request, 'auth/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })