def signup(request): if request.method == 'POST': user_form = MyUserForm(data=request.POST) user_profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and user_profile_form.is_valid(): user = user_form.save() profile = user_profile_form.save(commit=False) profile.confirmation_key = hashlib.sha1(user.email + str(datetime.datetime.now())).hexdigest() profile.user = user profile.save() messages.add_message(request, messages.INFO, 'Prvi korak registracije je ispunjen. Da biste zavrsili registraciju morate aktivirati nalog sa aktivacionim linkom koji je poslat na Vasu email adresu.') UserProfile.objects.send_confirmation(request, user) user_form = MyUserForm() # Cisti formu nakon uspesnog registrovanja user_profile_form = UserProfileForm() # Cisti formu nakon uspesnog registrovanja else: print user_form.errors, user_profile_form.errors else: user_form = MyUserForm() user_profile_form = UserProfileForm() return render(request, 'account/signup.html', {'user_form': user_form, 'user_profile_form': user_profile_form})
def edit_profile(request, username, permission=False): """ Funkcija za izmenu profilnih podataka. """ if permission == False: return HttpResponse('kurcina') else: profile = get_profile(username) url_redirection = '/accounts/profile/' + username + '/' if request.method == 'POST': form = UserProfileForm(request.POST, request.FILES, instance=profile) if form.is_valid(): form.save() img_path = join(settings.MEDIA_ROOT, str(get_profile(username).profile_image)) print("PATH %s " % img_path) img = Image.open(img_path) print("SIZE %s " % str(img.size)) img.thumbnail((160, 160)) img.save(img_path, 'JPEG') return HttpResponseRedirect(url_redirection) else: return HttpResponse('VALIDACIJA PROBLEM') else: form = UserProfileForm(instance=profile) return render(request, 'userprofile/edit_profile.html', {'form': form})
def account_settings(request): if request.method == "POST": user_form = UserProfileForm(data=request.POST, instance=request.user) if user_form.is_valid(): user_form.save() pw_form = PasswordChangeForm(user=request.user) user_form = UserProfileForm(instance=request.user) return render(request, 'userauth/account-settings.html', {'pw_form': pw_form, 'user_form': user_form, 'user': request.user})
def post(self, request, *args, **kwargs): user = request.user user_profile = user.profile userProfileForm = UserProfileForm(request.POST, request.FILES, instance=user_profile) if userProfileForm.is_valid(): user_profile = userProfileForm.save() user.email = userProfileForm.cleaned_data['email'] user.save() return redirect('management:index') return render(request, 'userauth/update_profile.html', {'userProfileForm': userProfileForm})
def get(self, request, *args, **kwargs): user = request.user profile = user.profile userProfileForm = UserProfileForm(instance=profile, initial={'email': user.email}) return render(request, 'userauth/update_profile.html', {'userProfileForm': userProfileForm})
def user_edit(request): context = {} context['active_edit_profile'] = True profile = get_object_or_404(UserProfile, user_id=request.user.id) if request.method == "POST": form = UserProfileForm(request.POST, instance=profile) context['profile_form'] = form if form.is_valid(): profile = form.save(commit=False) profile.save() messages.add_message( request, messages.SUCCESS, 'Your profile details have been successfully updated.') else: profile_form = UserProfileForm(request.POST or None) return render(request, 'userauth/edit.html', {'profile_form': profile_form})
def register(request): """ Function for User registration as Users need to make them identify to the application before they can post and share content with other users/admin or buy advertisements. """ registered = False val = 0 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() and user_form.cleaned_data['password'] == user_form.cleaned_data['password_confirm']: user = user_form.save(commit=False) profile = profile_form.save(commit=False) if User.objects.filter(email = user.email).count()>=1 or user.email == "": val = 1 else: user.set_password(user.password) user.save() profile.user = user profile.save() registered = True else: print user_form.errors , profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request,'userauth/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered, 'val': val,})
def register(request): context = RequestContext(request) registered = False if request.method == 'POST': # Condition 1 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() registered = True else: print user_form.errors, profile_form.errors else: # Condition 2 user_form = UserForm() profile_form = UserProfileForm() return render_to_response('register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
def user_edit(request, pk): if UserProfile.objects.filter(user=request.user).count() == 1: print 11 Edit = 0 user = request.user userprofile = get_object_or_404(UserProfile, user=user) if request.method == "POST": print 22 user_form = UserForm(data=request.POST, instance=user) profile_form = UserProfileForm(data=request.POST, instance=userprofile) if user_form.is_valid() and profile_form.is_valid( ) and user_form.cleaned_data['password'] == user_form.cleaned_data[ 'password_confirm']: Edit = 1 user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() login(request, user) else: user_form = UserForm(instance=user) profile_form = UserProfileForm(instance=userprofile) print 33 return render(request, 'userauth/register_edit.html', { 'user_form': user_form, 'profile_form': profile_form, 'Edit': Edit }) else: Edit = 2 user = request.user if request.method == "POST": user_form = UserForm(data=request.POST, instance=user) if user_form.is_valid() and user_form.cleaned_data[ 'password'] == user_form.cleaned_data['password_confirm']: Edit = 3 user = user_form.save() user.set_password(user.password) user.save() login(request, user) else: user_form = UserForm(instance=user) return render(request, 'userauth/register_edit.html', { 'user_form': user_form, 'Edit': Edit })
def signup(request): user_form = UserCreateForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() password = user.password user.set_password(password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() login(request, user) return redirect('books:index') else: user_form = UserCreateForm() profile_form = UserProfileForm() return render(request, 'userauth/signup.html', { 'user_form': user_form, 'profile_form': profile_form })
def register(request): registered = False val = 0 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( ) and user_form.cleaned_data['password'] == user_form.cleaned_data[ 'password_confirm']: user = user_form.save(commit=False) profile = profile_form.save(commit=False) if User.objects.filter( email=user.email).count() >= 1 or user.email == "": val = 1 else: user.set_password(user.password) user.save() profile.user = user profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render( request, 'userauth/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered, 'val': val, })