def register(request): if request.method == "POST": user_form = RegistrationForm(request.POST) userprofile_form = UserProfileForm(request.POST) print(user_form) print("user验证:", user_form.is_valid()) print(userprofile_form) print("profile验证:", userprofile_form.is_valid()) if user_form.is_valid() and userprofile_form.is_valid(): new_user = user_form.save(commit=False) new_user.set_password(user_form.cleaned_data['password']) new_user.save() new_userprofile = userprofile_form.save(commit=False) new_userprofile.user = new_user new_userprofile.save() return HttpResponse("成功") else: return render(request, "account/register2.html", { "form": user_form, "profile": userprofile_form }) else: user_form = RegistrationForm() userprofile_form = UserProfileForm() return render(request, "account/register2.html", { "form": user_form, "profile": userprofile_form })
def registration_view(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email') ident = form.cleaned_data.get('ident') first_name = form.cleaned_data.get('first_name') last_name = form.cleaned_data.get('last_name') raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password, first_name=first_name, ident=ident, last_name=last_name) login(request, account) return redirect('home') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'register.html', context)
def register(request): if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): new_user = form.save() user_profile = UserProfile.objects.get(pk=new_user.id) user_profile.address = form.cleaned_data["address"] user_profile.city = form.cleaned_data["city"] user_profile.phone = form.cleaned_data["phone"] user_profile.token = hashlib.sha224( '%s%s' % (new_user.username, timezone.now())).hexdigest() user_profile.expire = timezone.now() + timedelta(days=7) user_profile.save() #TODO: send confirmation email return HttpResponseRedirect("/account/register/success/?u=%s&m=%s" % (new_user.username, new_user.email)) else: form = RegistrationForm() return render_to_response( "account/register.html", { "form": form, }, context_instance=RequestContext(request))
def register(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get("email") username = form.cleaned_data.get("username") first_name = form.cleaned_data.get("first_name") last_name = form.cleaned_data.get("last_name") role = form.cleaned_data.get("role") raw_password = form.cleaned_data.get("password1") account = authenticate(email=email, username=username, first_name=first_name, last_name=last_name, role=role, password=raw_password) login(request, account) return redirect("home") else: context['register_form'] = form else: form = RegistrationForm() context['register_form'] = form return render(request, "registers/register.html", context)
def registration_view(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') first_name = form.cleaned_data.get('first_name') last_name = form.cleaned_data.get('last_name') room_number = form.cleaned_data.get('room_number') phone_number = form.cleaned_data.get('phone_number') account = authenticate(email=email, password=raw_password, first_name=first_name, last_name=last_name, phone_number=phone_number, room_number=room_number) login(request, account) return redirect('login') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', context)
def company_registration_view(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): user = form.save() user.refresh_from_db() user.is_employee = False register_id = request.POST['register_id'] user.last_name = None email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') user.register_id = register_id account = authenticate(email=email, password=raw_password) print(register_id) user.save() login(request, account) return redirect('jobs') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/company_register.html', context)
def registration_view(request): user = request.user context = {} if user.is_authenticated: return redirect('news_home') if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') email = form.cleaned_data.get('email') account = authenticate(username=username, password=raw_password) login(request, account) send_mail( 'Registration Complete', 'Congratulations ' + username + '! You have successfully registered for our coursework project application! This email serves only to let you know that Part A2 of the Advanced requirements works!', '*****@*****.**', [email]) return redirect('news_home') else: context['registration_form'] = form else: # if GET req. user visits the page for first rime, meaning they would like to register form = RegistrationForm() context['registration_form'] = form context['title'] = 'Register' return render(request, 'account/register.html', context)
def update_profile(request): form = RegistrationForm(request.POST or None, instance=request.user) if form.is_valid(): form.save() return redirect('account:profile') return render(request, 'account/update_profile.html', {'form': form})
def register_view(request, *args, **kwargs): user = request.user if user.is_authenticated: return HttpResponse("You are already authenticated as " + str(user.email)) context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email').lower() raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) login(request, account) destination = kwargs.get("next") if destination: return redirect(destination) return redirect('home') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', context)
def registration(request): context = {} if request.user.is_authenticated: return redirect('home') if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') raw_dob = form.cleaned_data.get('DoB') raw_email = form.cleaned_data.get('email') account = authenticate(username=username, password=raw_password, DoB = raw_dob) send_mail('Thank you for signing up!', 'Thank you for signing up to the Newsapp! I hope you enjoy your experience!', '*****@*****.**', [raw_email], fail_silently=False) login(request, account) return redirect('home') else: context['registration_form'] = form else: # GET request form = RegistrationForm() context['registration_form'] = form return render(request, 'accounts/register.html', context)
def register(request): if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): new_user = form.save() user_profile = UserProfile.objects.get(pk=new_user.id) user_profile.address = form.cleaned_data["address"] user_profile.city = form.cleaned_data["city"] user_profile.phone = form.cleaned_data["phone"] user_profile.token = hashlib.sha224( '%s%s' % (new_user.username, timezone.now())).hexdigest() user_profile.expire = timezone.now() + timedelta(days=7) user_profile.save() #TODO: send confirmation email return HttpResponseRedirect( "/account/register/success/?u=%s&m=%s" % (new_user.username, new_user.email)) else: form = RegistrationForm() return render_to_response("account/register.html", { "form": form, }, context_instance=RequestContext(request))
def reigster(request): #init password= qwertasdfg if request.method == "POST": user_form = RegistrationForm(request.POST) userprofile_form = UserProfileForm(request.POST) if user_form.is_valid(): # print(user_form.cleaned_data['username']) # print(user_form.cleaned_data['email']) print(user_form.cleaned_data['password']) print(user_form.cleaned_data['password2']) new_user = user_form.save(commit=False) new_user.set_password(user_form.cleaned_data['password']) new_user.save() new_profile = userprofile_form.save(commit=False) new_profile.user = new_user new_profile.save() UserInfo.objects.create(user=new_user) return HttpResponse("successfully") else: return HttpResponse("<h1>Sorry, you cannot register</h1>") if request.method == "GET": user_form = RegistrationForm() userprofile_form = UserProfileForm() return render(request, "account/register.html", { "form": user_form, "profile": userprofile_form })
def register_view(request, *args, **kwargs): user = request.user if user.is_authenticated: return HttpResponse(f'Вы уже вошли как {str(user.phone)}') context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() phone = form.cleaned_data.get('phone') raw_password = form.cleaned_data.get('password1') account = authenticate(phone=phone, password=raw_password) login(request, account) destination = kwargs.get('next') if destination: return redirect(destination) return redirect('home') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', context)
def post(self, request): form = RegistrationForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.is_valid = False user.save() token = user_tokenizer.make_token(user) user_id = urlsafe_base64_encode(force_bytes(user.id)) url = 'http://localhost:8000' + reverse('confirm_email', kwargs={ 'user_id': user_id, 'token': token }) message = get_template('accounts/register_email.html').render( {'confirm_url': url}) mail = EmailMessage('Django Blog app Email Confirmation', message, to=[user.email], from_email=settings.EMAIL_HOST_USER) mail.content_subtype = 'html' mail.send() context = { 'form': AuthenticationForm, 'message': 'A confirmation email has been sent to {}.' 'Please confirm to finish registering'.format(user.email) } return render(request, 'accounts/login.html', context) context = {'form': form} return render(request, 'accounts/register.html', context)
def registration_view(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) login(request, account) return redirect('core_index') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form #return render(request,'register.html',context) return render(request, 'register.html', context)
def index(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() status = 2 context = { 'status' : status, 'form': form } return render(request, 'index/index.html', context); else: status = 3 context = { 'form': form, 'status': status } return render(request, 'index/index.html', context) else: form = RegistrationForm() context = { 'form': form } return render(request, 'index/index.html', context)
def registration_view(request): """ Funktion der Registrierungs Ansicht. Hierbei wird nichts angezeigt, sondern nur die logout-Funktion ausgeführt und zur Login-Seite weitergeleitet Wenn HTTP Methode gleich GET: Leeres Registrierungs Formular anzeigen. Wenn HTTP Methode gleich POST: Wenn Daten valide sind, Nutzer authentifizieren, einloggen und auf den Home-Screen weiterleiten. """ context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.cleaned_data["email"] = form.cleaned_data.get('email').lower() form.save() login( request=request, account=authenticate( email=form.cleaned_data.get('email'), password=form.cleaned_data.get( 'password1' ) # da beide Passwort-Eingaben identisch, reicht der Wert der ersten )) return redirect('/home/') else: context['registration_form'] = form else: # GET request form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', {"form": form})
def register_view(request, *args, **kwargs): user = request.user if user.is_authenticated: return HttpResponse(f"Вы уже вошли как {user.email}.") context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email').lower() raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) login(request, account) destination = get_redirect_if_exists(request) if destination: return redirect(destination) return redirect('home') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', context)
def register(request): """ DataHub account registration form. GET returns an HttpResponse containing the account registration form. POST creates a name/email/password account and logs the new user in. Other links from the page lead to Python Social Auth options (Google, Facebook, Twitter, etc). """ # Redirect succesful logins to `next` if set. # Failing that `redirect_url`. # Failing that, LOGIN_REDIRECT_URL from settings.py. redirect_uri = post_or_get( request, 'next', fallback=post_or_get( request, 'redirect_url', fallback=settings.LOGIN_REDIRECT_URL)) redirect_absolute_uri = add_query_params_to_url( request.build_absolute_uri(redirect_uri), {'auth_user': request.user.get_username()}) if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'].lower() email = form.cleaned_data['email'].lower() password = form.cleaned_data['password'] User.objects.create_user(username, email, password) # A signal handler in signals.py listens for the pre_save signal # and throws an IntegrityError if the user's email address is not # unique. Username uniqueness is handled by the model. # # In the future, another pre_save signal handler will check if a # DataHub database exists for the user and create one if it # doesn't exist. If the database cannot be created, that handler # will throw an exception. user = datahub_authenticate(username, password) if user is not None and user.is_active: django_login(request, user) # Append auth_user to redirect_uri so apps like Kibitz can # pull the username out of the redirect. This should be # removed when Thrift is removed from DataHub. redirect_uri = add_query_params_to_url( redirect_uri, {'auth_user': request.user.get_username()}) return HttpResponseRedirect(redirect_uri) else: # Form isn't valid. Fall through and return it to the user with # errors. pass else: form = RegistrationForm() providers = provider_details() context = RequestContext(request, { 'request': request, 'user': request.user, 'form': form, 'providers': providers, 'next': redirect_uri, 'absolute_next': redirect_absolute_uri, }) return render_to_response('register.html', context_instance=context)
def register(request, pid=None): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): new_user = form.save() user = Profile.objects.get(email=form.cleaned_data['email']) if pid: partner = Profile.objects.get(id=pid) user.partner = partner user.save() send_outbound_generic_email( recipient=user, title="Welcome to Investaview", message="Welcome to the Investaview Community. We look forward to your contributions.", #add copy to direct them to complete filling out profile template="email/generic.html" ) if form.cleaned_data['next']: return HttpResponseRedirect(form.cleaned_data['next']) else: return HttpResponseRedirect(reverse('home')) else: form = RegistrationForm() return render_to_response('account/register.html', {'form': form, }, context_instance=RequestContext(request))
def register(request): ''' present a registration form, once completed by user, the system will send email containing confirmation link. The registration completes only if the user confirms the link. ''' page_url = 'account/register.html' if request.user.is_authenticated(): # They already logged in, don't let them register again return render_to_response(page_url, {'has_account':True}, context_instance=RequestContext(request)) if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user, profile = form.save() # Send email with confirmation link domain_name = "langtou.me" sender_email = "*****@*****.**" email_subject = "Your account at %s" % domain_name email_body = _("Howdy, %s,\n\nThank you so much for signing up at langtou.me. We focus on providing you an intuitive way to plan and share your trips, Have fun!\n\nTo activate your account, click this link within 48 hours:\n\nhttp://langtou.me/account/confirm/%s\n\nHappiness only real when shared.\n\nBest wishes,\nMyWay Team.") % (user.username, profile.activation_key) # print email_body send_mail(email_subject, email_body, sender_email, [user.email]) return render_to_response(page_url, {'created':True}, context_instance=RequestContext(request)) else: form = RegistrationForm() return render_to_response(page_url, {'form':form}, context_instance=RequestContext(request))
def registration_view(request): if request.user.is_authenticated: return redirect("home") context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): new_user = form.save(commit=False) form.save() email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') new_user.save() Profile.objects.create(user=new_user) account = authenticate(email=email, password=raw_password) login(request, account) messages.success(request, "Welcome to Drawild now it's time to be wild") return redirect(reverse('home')) else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', context)
def user(request): if request.method == "POST": user_form = RegistrationForm(request.POST) userinfo_form = UserInfoForm(request.POST) if user_form.is_valid() * userinfo_form.is_valid(): new_user = user_form.save(commit=False) new_user.set_password(user_form.cleaned_data['password']) new_user.save() new_profile = userinfo_form.save(commit=False) new_profile.user = new_user new_profile.save() UserInfo.objects.create(user=new_user) return HttpResponse("successfully") else: return HttpResponse("抱歉,注册失败") else: role_list = Role.objects.all() user_list = UserInfo.objects.all() user_form = RegistrationForm() userinfo_form = UserInfoForm() return render( request, "system/user.html", { "user_list": user_list, "form": user_form, "userinfo": userinfo_form, "role_list": role_list })
def register(request): if request.method == "POST": user_form_data = RegistrationForm(request.POST) user_profile_form_data = UserProfileForm(request.POST) if user_form_data.is_valid() & user_profile_form_data.is_valid(): new_form = user_form_data.save(commit=False) new_form.set_password(user_form_data.cleaned_data["password"]) new_form.save() new_profile = user_profile_form_data.save(commit=False) new_profile.user = new_form new_profile.save() UserInfo.objects.create(user=new_form) return HttpResponse( "successfully register ,you can <a href='{%url 'account:user_login'%}'>login now</a>" ) else: return HttpResponse("sorry") else: user_register_form = RegistrationForm() user_profile_form = UserProfileForm() return render( request, "account/register.html", { "user_register_form": user_register_form, "user_profile_form": user_profile_form })
def register_view(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.is_active = False user.save() current_site = get_current_site(request) domain = current_site.domain token = account_activation_token.make_token(user) # if settings.DEBUG: # link = f"localhost:8000/user/activate/{user.id}/{token}" # else: link = f"https://vriendly.herokuapp.com/user/activate/{user.id}/{token}" messages.info( request, mark_safe( f"<p>Hi, {user.first_name}.</p><p>Activate your account from link, please.</p><p><a href={link}>{link}</a></p>" )) return redirect('home') else: context['register_form'] = form else: form = RegistrationForm() context['register_form'] = form return render(request, 'account/register.html', context)
def registration_view(request): context = {} print("helre") if request.user.is_authenticated: return redirect("dashboard") if request.POST: form = RegistrationForm(request.POST) print(form) if form.is_valid(): form.save() # making wallet model email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) login(request, account) w = Wallet(user=request.user, amount=0) return redirect('dashboard') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form print("here") print(context) return render(request, 'register.html', context)
def registration_view(request): context = {} try: #Always return the first available preferences = UIPrefs.objects.all().first() except Exception as e: #Deleted preferences print(e) #If registration is closed, return to the homepage. if not preferences.open_registration: return redirect('home') if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password') account = form.save() messages.success(request, f'Enjoy using Open Check In') return redirect('home') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', context)
def registration(request): ''' This view renders the user registration form for users ''' if request.POST: reg_form = RegistrationForm(request.POST) if reg_form.is_valid(): reg_form.save() email = reg_form.cleaned_data.get('email') raw_password = reg_form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) new_account = Account.objects.get(email=email) notify.send( request.user, recipient=new_account, verb= "Can you please fill in your personal details as soon as possible." ) messages.success(request, "You have successfully registered a new user.") current_qtr = getCurrentQtr() new_ot_per_qtr = OvertimePerQtr(ot_per_qtr_off_id=new_account, ot_per_qtr_qtr_id=current_qtr) new_ot_per_qtr.save() return redirect('view_new_account', new_account.pk) else: reg_form = RegistrationForm() args = {'reg_form': reg_form} return render(request, 'register.html', args)
def signupView(request): if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('account:login') else: form = RegistrationForm() return render(request, 'account/signup.html', {'form': form})
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('/account') else: form = RegistrationForm() args = {'form': form} return render(request, 'account/reg_form.html', args)
def recipes_view(request, dish=None): context = {} if dish is None: resepti_lista = Ohje.objects.all() else: resepti_lista = Ohje.objects.filter(dish=dish) myFilter = OhjeFilter(request.GET, queryset=resepti_lista) resepti_lista = myFilter.qs resepti_lista = sorted(resepti_lista, key=attrgetter("date_published"), reverse=True) if request.POST: form = RegistrationForm(request.POST) login_form = AccountAuthenticationForm(request.POST) # if form.is_valid(): form.save() username = form.cleaned_data.get("username") raw_password = form.cleaned_data.get("password1") account = authenticate(username=username, password=raw_password) login(request, account) return redirect("recipe:recipes") elif login_form.is_valid(): username = request.POST["username"] password = request.POST["password"] user = authenticate(username=username, password=password) if user: login(request, user) return redirect("recipe:recipes") else: context["registration_form"] = form else: user = request.user kommentti_lista = Comment.objects.filter( recipe_commented__author__username=user.username) kommentti_lista = sorted(kommentti_lista, key=attrgetter("create_date"), reverse=True) context["kommentti_lista"] = kommentti_lista login_form = AccountAuthenticationForm() # form = RegistrationForm() context["registration_form"] = form context["login_form"] = login_form context["resepti_lista"] = resepti_lista context["myFilter"] = myFilter return render(request, "recipe/recipes.html", context)
def registration_view(request): ''' allows user to register using the registration form details are updated as account object ''' context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): if '/' in form.cleaned_data.get('username'): context['registration_form'] = form form.add_error('username', 'invalid punctuation in username') else: form.save() email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) username = form.cleaned_data.get('username') uid = Account.objects.get(username=username) read = Collection(UID=uid, collectionName='Read', description='Read') want_to_read = Collection(UID=uid, collectionName='Want to Read', description='Want to Read') currently_reading = Collection( UID=uid, collectionName='Currently Reading', description='Currently Reading') read.save() want_to_read.save() currently_reading.save() if len(Account.objects.all()) > 1: similar_users(request) login(request, account) return redirect('home') else: context['registration_form'] = form context['register_email'] = request.POST['email'] context['register_username'] = request.POST['username'] context['register_firstname'] = request.POST['firstname'] context['register_lastname'] = request.POST['lastname'] context['register_birthday'] = request.POST['birthday'] if request.POST['gender'] == 'Male': context['male_checked'] = 'checked' elif request.POST['gender'] == 'Female': context['female_checked'] = 'checked' elif request.POST['gender'] == 'Other': context['other_checked'] = 'checked' render(request, 'account/register.html', context) else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', context)
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('http://ec2-35-173-183-216.compute-1.amazonaws.com/') else: form = RegistrationForm() args = {'form': form} return render(request,'account/register.html',args)
def registration(request, register_success_url="login", template="account/registration.html"): form = RegistrationForm() if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] user = User.objects.create_user(username=email, email=email, password=password) user.first_name = first_name user.last_name = last_name user.save() salt = sha.new(str(random.random())).hexdigest()[:5] activation_key = sha.new(salt+user.username).hexdigest() key_expires = datetime.datetime.today() + datetime.timedelta(2) user_profile = UserProfile( user=user, activation_key=activation_key, key_expires=key_expires) user_profile.save() current_site = Site.objects.get_current() subject = "welcome to my blog" message = ('Please click the link below to' 'activate your user account \n''%s%s%s') % ( current_site, "/account/confirm/", activation_key) sender = EMAIL_HOST_USER recipients = [email] mail_sender(subject=subject, message=message, sender=sender, recipients=recipients) authenticate(email=email, password=password) return redirect(register_success_url) return render(request, template, {'form': form})
def account_registration(request): # if request.user.is_authenticated(): # return HttpResponseRedirect("/profile/") if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): password = form.cleaned_data["password"] logger.info( "Password is %s" % password ) username = form.cleaned_data["email"] if len(username)>30: username = username[:30] user,success = Account.create_user( email=form.cleaned_data["email"], username= username, password= password, generate_password=False ) acc = Account(user=user) acc.email = form.cleaned_data["email"] acc.name = form.cleaned_data["name"] acc.synched = False acc.ip_address = get_client_ip(request) acc.save() request.session[session_account_id_key] = acc.id return HttpResponseRedirect("/profile/") else: response_data = { "success":False, "errors": [(k, v[0]) for k, v in form.errors.items()] } return HttpResponse(json.dumps(response_data),mimetype="application/json") # return render_to_response("register.html",{"form":form},context_instance=RequestContext(request)) else: """user not submit""" form = RegistrationForm context = {"form":form} return render_to_response("register.html",context,context_instance=RequestContext(request))
def post(self, request, format=None): data = { 'username': request.data['username'], 'password': request.data['password'], 'email': request.data['email'], } form = RegistrationForm(data) if not form.is_valid(): # Concatenate all of the form validation errors. msg = " ".join(["".join(s) for s in form.errors.itervalues()]) raise ValidationError(msg) user = datahub_register_user(form) serializer = UserSerializer(user, many=False) return Response(serializer.data)
def register(request): form = RegistrationForm(request.POST or None) if form.is_valid(): newUser = { "username": form.cleaned_data["username"], "first_name": form.cleaned_data["first_name"], "last_name": form.cleaned_data["last_name"], "email": form.cleaned_data["email"], } user = User.objects.create(**newUser) user.set_password(form.cleaned_data["password2"]) user.save() return HttpResponseRedirect(request.POST.get('next', '/')) return render(request, "register.html", { 'form': form, })
def register_page(request): """ Affichage de la fenetre d enregistrement """ 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'], email=form.cleaned_data['email'] ) return HttpResponseRedirect('/register/success/') else: form = RegistrationForm() variables = RequestContext(request,{'form':form}) return render_to_response( 'register.html', variables )
def AccountRegistration(request): if request.user.is_authenticated(): return HttpResponseRedirect('/profile') if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user(username=form.cleaned_data['username'], email=form.cleaned_data['email'], password=form.cleaned_data['password']) user.save() account = user.gejest_profile() account.name = form.cleaned_data.get('real_name', None) account.save() return HttpResponseRedirect('/profile/') else: return render_to_response('register.html', {'form':form}, context_instance = RequestContext(request)) else: ''' pusty formularz ''' form = RegistrationForm() context ={'form': form} return render_to_response('register.html', context, context_instance = RequestContext(request))
def add_user(request, bid): if request.method not in ['GET', 'POST']: return HttpResponseNotAllowed(permitted_methods=['POST', 'GET']) branch = get_object_or_404(Branch, pk=bid) if request.method == 'GET': form = RegistrationForm() elif request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = get_user_model() user = user() user.username = form.cleaned_data.get('username') user.email = form.cleaned_data.get('email') user.password = make_password(form.cleaned_data.get('password')) user.branch = branch user.activate() #redirect somewhere return render(request, 'registration/register.html', {'form':form})
def register_user(request): if request.user.is_authenticated(): return redirect(HOME_URL) state = "Please register" reg_form = RegistrationForm(request.POST or None) pass_form = SetPasswordForm(request.user, request.POST or None) temp1 = reg_form.is_valid() # prevent short circuit temp2 = pass_form.is_valid() # prevent short circuit if temp1 and temp2: d = dict( reg_form.cleaned_data.items() + pass_form.cleaned_data.items() ) new_user = get_user_model().objects.create_user(d["username"], d["email"], d["new_password1"]) new_user.is_active = False activation_key = utils.generate_key(d["username"]) new_user.activation_key = activation_key keypair = utils.generate_key_pair(d["username"]) new_user.public_key = keypair["public"] new_user.private_key = keypair["private"] new_user.save() logger.info("New user '%s' registered." % new_user.username) c = { "key": activation_key, } return render(request, "account/post_register.html", c) c = { "state": state, "reg_form": reg_form, "pass_form": pass_form, } return render(request, "account/register.html", c)