def signup(request): """Sign up view.""" if request.method == 'POST': username = request.POST['username'] passwd = request.POST['passwd'] passwd_confirmation = request.POST['passwd_confirmation'] if passwd != passwd_confirmation: return render(request, 'users/signup.html', {'error': 'Password confirmation does not match'}) try: user = User.objects.create_user(username=username, password=passwd) except IntegrityError: return render(request, 'users/signup.html', {'error': 'Username is already in user'}) user.first_name = request.POST['first_name'] user.last_name = request.POST['last_name'] user.email = request.POST['email'] user.save() profile = Profile(user=user) profile.save() return redirect('login') return render(request, 'users/signup.html')
def fetch_user_info_callback(openid, userinfo): exist = Bind.objects.filter(wx_openid=openid) if not exist: logging.info("new user. openid: %s userinfo: %s" % (openid, userinfo)) sex = 'O' if 'sex' in userinfo: if userinfo['sex'] == 1: sex = 'M' else: sex = 'F' profile = Profile(uuid=gen_uuid(), nick=userinfo['nickname'], sex=sex, portrait=userinfo['headimgurl'], real_name='', company_name='', title='', vip='1', desc='', nation=userinfo['country'], province=userinfo['province'], city=userinfo['city'], district='') profile.save() bind = Bind(user_id=profile.id, phone_number='', phone_number_verify_time='1972-01-01', wx_openid=openid, wx_openid_verify_time=datetime.datetime.now(), qq_openid='', qq_openid_verify_time='1972-01-01', weibo_openid='', weibo_openid_verify_time='1972-01-01', email='', email_verify_time='1972-01-01') bind.save() profileext = ProfileExt(user_id=profile.id, education='', blood_type='', birthday='1972-01-01', certificate_no='') profileext.save() else: logging.debug('exist userinfo: %s' % openid)
def save(self): data = self.cleaned_data data.pop('password_confirmation') user = User.objects.create_user( **data ) #el **data me ayuda para n otener que escribir todos los datos com opor ejemplo "email=data['email']", ed ecir que los dos arteriscos me ayudan par enviar todo el diccinario profile = Profile(user=user) profile.save()
def setUp(self): self.user = User.objects.create_user("testuser", "secret") self.new_profile = Profile( profile_pics= "https://cdn.statically.io/img/wallpaperaccess.com/full/819472.jpg", owner=self.user) self.new_profile.save() self.new_image = Image( pic= "https://cdn.statically.io/img/wallpaperaccess.com/full/819472.jpg", caption="image", profile=self.new_profile)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): description = form.cleaned_data.get("description") place = form.cleaned_data.get("place") language = form.cleaned_data.get("language") proficiency = form.cleaned_data.get("proficiency") user = form.save(commit=False) if User.objects.filter(email=user.email).exists(): return HttpResponseBadRequest("Somebody has already registered with this email") elif User.objects.filter(username=user.username).exists(): return HttpResponseBadRequest("Somebody has already used this username") user.is_active = False user.save() profile = Profile( user=user, description=description, place=place, ) profile.save() user_language = UserLanguage( user=profile, language=Language.objects.get(name=language), proficiency=proficiency, ) user_language.save() subject = 'Activate Your Servare Account' message = render_to_string( 'user/account_activation_email.html', { 'user': user, 'domain': request.META['HTTP_HOST'], 'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode("utf-8"), 'token': account_activation_token.make_token(user), }) notify_user(to_email=user.email, message=message, subject=subject) return redirect('account_activation_sent') else: form = SignUpForm() return render(request, 'user/signup.html', {'form':form})
def get_user_profile_by_user_id(user_id, need_default): profiles = Profile.objects.filter(id=user_id)[:1] if profiles: return profiles[0] if need_default: return Profile(id=user_id, uuid='', nick='', sex='O', real_name='', portrait='', company_name='', title='', vip=False, desc='', nation='', province='', city='', district='') else: return None
def matric_edit_view(request): try: profile = request.user except Profile.DoesNotExist: profile = Profile(user=request.user) if request.method == 'POST': form = Profile(request.POST, instance=profile) if m_form.is_valid(): m_form.save() return redirect('account_login') messages.error(request, 'Error your matric number has to ba in the form 140211***') else: m_form = MatricUpdateForm(instance=request.user) context= {'m_form':m_form,} return render(request,'university/edit_matric.html',context)
def user_register(request): # Redirect the user to the dashboard if already signed in if request.user.is_authenticated: return redirect('user:dashboard') if request.method == 'POST': user_form = UserRegistrationForm(request.POST) profile_form = ProfileRegistrationForm(data=request.POST, files=request.FILES) if user_form.is_valid() and profile_form.is_valid(): # Create a new user object but avoid saving it yet new_user = user_form.save(commit=False) # Set the chosen password new_user.set_password(user_form.cleaned_data['password']) # Save the User object new_user.save() # Create the user profile profile = Profile() profile_cleaned = profile_form.cleaned_data setattr(profile, 'user', new_user) setattr(profile, 'gender', profile_cleaned['gender']) setattr(profile, 'date_of_birth', profile_cleaned['date_of_birth']) profile.save() user = authenticate(username=user_form.cleaned_data['username'], password=user_form.cleaned_data['password']) if user is not None: if user.is_active: login(request, user) return redirect('user:dashboard') else: return HttpResponse('Disabled account') #return render(request, 'account/register_done.html', {'new_user': new_user}) else: user_form = UserRegistrationForm() profile_form = ProfileRegistrationForm() return render(request, 'user_auth/register/register.html', { 'user_form': user_form, 'profile_form': profile_form })
def signup(request): username = request.POST.get('username', '') password = request.POST.get('password', '') rpassword = request.POST.get('rpassword', '') email = request.POST.get('email', '') if password == rpassword: print(username) user = User.objects.create_user(username=username, password=password, email=email) profile = Profile(user=user) user.save() profile.save() user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect('/') else: return render_to_response("register.html", {'success': False})
def search_results(request): if 'searchItem' in request.GET and request.GET["searchItem"]: search_term = request.GET.get("searchItem") searched_user = Profile.search_by_username(search_term) message = f"{search_term}" context = {'message': message, 'searched_user': searched_user} return render(request, 'search.html', context) else: message = "You haven't searched for any term" return render(request, 'index.html', {"message": message})
def to_dict(self): cart = CartHistory.mark(self.u_id, self.o_id) return { 'oid': self.o_id, 'goods': cart['good'], 'date': self.o_date.strftime('%Y-%m-%d %H:%M:%S'), 'message': self.o_message, 'total_price': self.o_total_price, 'user': Profile.search(self.u_id), 'status': self.o_status }
def setUp(self): self.new_user = User.objects.create_user("testuser", "secret") self.new_profile = Profile( profile_pics= 'https://ucarecdn.com/620ac26e-19f7-4c0a-86d1-2b4e4b195fa8/-/crop/610x452/15,0/-/preview/', bio="this is a test bio", owner=self.new_user) self.new_profile.save() self.new_image = Image( pic= 'https://ucarecdn.com/620ac26e-19f7-4c0a-86d1-2b4e4b195fa8/-/crop/610x452/15,0/-/preview/', caption="this is a test image", profile='', profile_details=self.new_user) self.new_image.save() self.new_comment = Comment(image=self.new_image, comment_owner=self.new_profile, comment="this is a comment on a post")