def signup(request): """ A view that: renders the signup page. Validates the SignUpForm data. Creates a new User object with 'is_active' status as 'False' if the SignUpForm POST data is valid. Sends an email confirmation email to a newly created user. An activation link is created by using: The desired protocol. the current domain name. a base64 encoded unique user id. Django's default token generator. A user cannot sign in until the email is not confirmed. Parameters ---------- request : HttpRequest object An HttpRequest object that contains metadata about a request. Returns ------- HttpResponseRedirect A request to the signup_done page when the user submits valid POST data and a new User object is created. HttpResponse A new SignUpForm instance when the user accesses the signup page. A SignUpForm instance with errors when the user enters invalid data. Raises ------ ValidationError If the form data is not correct or as per guidelines. """ if request.method == "POST": form = SignUpForm(request.POST) i_agree = request.POST.get("i_agree", False) if form.is_valid() and i_agree: user = form.save(commit=False) user.is_active = False user.save() current_site = get_current_site(request) mail_subject = 'Confirm your email.' message = render_to_string( 'Accounts/new_account_activation_email.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': default_token_generator.make_token(user), 'protocol': 'http', }) email_id = form.cleaned_data.get('email') email = EmailMessage(mail_subject, message, to=[email_id]) email.send() return redirect('Accounts:signup_done') return render(request, 'Accounts/signup.html', { 'form': form, 'i_agree': i_agree }) else: form = SignUpForm() return render(request, 'Accounts/signup.html', {'form': form})
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): store_id = request.POST.get('store_id') store_pw = request.POST.get('pass_wrd') store_owner = User.objects.filter(username=store_id).first() if store_owner is None or not store_owner.check_password(store_pw): print 'Error' return render(request, 'Accounts/signup.html', { 'form': form, 'Error': 'Store owner credentials failed !' }) print 'No Error' user = form.save() user.refresh_from_db( ) # load the profile instance created by the signal user.profile.full_name = form.cleaned_data.get('full_name') user.profile.mob_number = form.cleaned_data.get('mob_number') user.profile.email_id = form.cleaned_data.get('email_id') user.email = user.profile.email_id user.profile.store_id = store_id user.save() raw_password = form.cleaned_data.get('password1') user = authenticate(username=user.username, password=raw_password) login(request, user) return redirect('/DashBoard/') else: return render(request, 'Accounts/signup.html', {'form': form}) else: form = SignUpForm() return render(request, 'Accounts/signup.html', {'form': form})
def adminsignup(request): productkeyErrors = '' if request.method == 'POST': pk = request.POST['productkey'] form = SignUpForm(request.POST) if form.is_valid(): if (len(pk) > 0): try: url = 'https://billdesk-auth.000webhostapp.com' post_fields = {'pk': pk} response = urllib2.Request( url, urllib.urlencode(post_fields).encode()) j = json.loads(urllib2.urlopen(response).read()) state = j['state'] except: state = -1 else: state = 0 if state == -1: productkeyErrors = 'Error in verifying Product Key, Try Again' elif state == 0: productkeyErrors = 'Wrong Product Key' elif state == 1: productkeyErrors = 'Key already registered' if state != 2: return render(request, 'Accounts/adminsignup.html', { 'form': form, 'productkeyErrors': productkeyErrors }) user = form.save() user.refresh_from_db( ) # load the profile instance created by the signal user.profile.full_name = form.cleaned_data.get('full_name') user.profile.mob_number = form.cleaned_data.get('mob_number') user.profile.email_id = form.cleaned_data.get('email_id') user.profile.Authority_Admin = 'checked' user.profile.Authority_Billing = 'checked' user.profile.Authority_Inventory = 'checked' user.profile.Authority_Customer = 'checked' user.profile.store_id = user.username user.save() c_store_db(user.username) P_Val = Prod_Val(product_key=pk, Profile=user.profile, con_detail=user.profile.mob_number) P_Val.save() raw_password = form.cleaned_data.get('password1') user = authenticate(username=user.username, password=raw_password) login(request, user) return redirect('/DashBoard/') else: form = SignUpForm() return render(request, 'Accounts/adminsignup.html', { 'form': form, 'productkeyErrors': productkeyErrors })
def signup(request): print(request.POST) if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save() # user.refresh_from_db() # load the profile instance created by the signal profil = Profil(user=user, role="MA", batiment=Batiment.objects.get(pk=1), appartement=Appartement.objects.get(pk=1)) profil.save() return redirect('accounts:login') else: form = SignUpForm() return render(request, 'registration/register.html', locals())
def SignUp(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) login(request, user) return render(request, 'Chat/loginsuccessful.html') # return redirect(User) else: return render(request, 'Chat/SignUp.html', {'form': form}) else: form = SignUpForm() return render(request, 'Chat/SignUp.html', {'form': form})
def index(request): if request.method == 'POST': form = SignUpForm(request.POST) # 入力内容に問題がなければ if form.is_valid(): user = form.save() # ユーザ情報保存 auth_login(request, user) # ログイン return redirect('index') # TODO:リダイレクト先を変える else: form = SignUpForm() context = { 'users': request.user, 'form': form, } return render(request, 'index.html', context)
def register(request): if request.user.is_authenticated(): return redirect('mainpage') else: if request.method == 'POST': registration = SignUpForm(request.POST) if registration.is_valid(): registration.save() username = registration.cleaned_data.get('username') raw_password = registration.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) login(request, user) userprofile = UserProfile(request.user.id) userprofile.save() return redirect('mainpage') else: registration = SignUpForm() return render(request, 'register.html', {'registration': registration})
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save() user.refresh_from_db( ) # load the profile instance created by the signal user.profile.full_name = form.cleaned_data.get('full_name') user.profile.mob_number = form.cleaned_data.get('mob_number') user.profile.email_id = form.cleaned_data.get('email_id') user.email = user.profile.email_id user.save() raw_password = form.cleaned_data.get('password1') user = authenticate(username=user.username, password=raw_password) login(request, user) return redirect('/dashboard/') else: return render(request, 'Accounts/signup.html', {'form': form}) else: form = SignUpForm() return render(request, 'Accounts/signup.html', {'form': form})