Ejemplo n.º 1
0
def signup(request):
	if request.method == 'POST':
		form = SignupForm(request.POST)
		print(form.data)
		print(form.is_valid())
		if form.is_valid():
			form.save()

			username = form.data['username']
			email = form.data['email']
			print(username,email)
			salt = hashlib.sha1(str(random.random()).encode('utf-8')).hexdigest()[:5]
			activation_key = hashlib.sha1((salt+email).encode('utf-8')).hexdigest()
			key_expires = datetime.datetime.today() + datetime.timedelta(1)

			# Create and save user profile
			user = User.objects.get(email=email)
			new_profile = UserProfile(user=user, activation_key=activation_key,
				key_expires=key_expires)
			new_profile.save()

			# Send email with activation key
			email_subject = 'Account confirmation'
			email_body = "Hi %s, thanks for signing up. To activate your account, click this link within \
			48hours http://127.0.0.1:8000/confirm/%s" % (username, activation_key)
			send_mail(email_subject, email_body, '*****@*****.**',
				[email], fail_silently = False)
			return render(request, 'sign_up_success.html')
		else:
			return render(request, 'confirm_expired.html')
	else:
		return render(request, 'sign_up.html')
Ejemplo n.º 2
0
def SignUp(request):
    signupform = SignupForm()
    mydict = {'signupform': signupform}
    if request.method == 'POST':
        signupform = SignupForm(request.POST)
        user = signupform.save()
        user.set_password(user.password)
        user.save()
        mydict.update({'mag': 'Registered Successfully'})
    return render(request, 'blog/signup.html', context=mydict)
Ejemplo n.º 3
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('main_page')

    else:
        form = SignupForm
        return render(request, 'signup.html', {'form': form})
Ejemplo n.º 4
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = SignupForm()
    if form.validate_on_submit():
        password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(form.username.data, form.email.data, password)
        db.session.add(user)
        db.session.commit()
        flash(f'Congratulations {form.username.data} You Can Login Now !',
              'success')
        return redirect(url_for('login'))
    return render_template('signup.html', title='Sign Up', form=form)
Ejemplo n.º 5
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = SignupForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()

        flash(
            f'You have successfully created an account for {form.username.data}! You can now log in to your account', 'success')
        return redirect(url_for('signin'))
    return render_template('signup.html', form=form)
Ejemplo n.º 6
0
def signup_view(request):
    form = SignupForm()
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            group = Group.objects.get(name='author')
            user.groups.add(group)
            form = SignupForm()
    return render(request, 'blog/signup.html', {'form': form})
Ejemplo n.º 7
0
def main_page(request):
    if 'user_id' in request.session:
        user_obj = User.objects.get(id=request.session['user_id'])
        blog_obj = post.objects.filter(user_id=request.session['user_id'])
        context = {'user': user_obj, 'blogs': blog_obj}
        return render(request, 'home.html', context)
    else:
        form = SignupForm()
        return render(request, 'index.html', {'form': form})
Ejemplo n.º 8
0
def signupview(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('post_list')
    else:
        form = SignupForm()
        return render(request, 'registration/signup.html', {'form': form})
Ejemplo n.º 9
0
def signup(request):
    path = request.get_full_path()
    if request.method == 'POST':
        form = SignupForm(data=request.POST, auto_id="%s")

        if form.is_valid():

            UserModel = get_user_model()
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = UserModel.objects.create_user(username=username,
                                                 password=password)
            user.save()
            auth_user = authenticate(username=username, password=password)
            login(request, auth_user)

            return redirect("/")
    else:
        form = SignupForm(auto_id="%s")
    return render(request, 'signup.html', locals())
def signup(request):
    if request.method=='POST':
        #form=UserCreationForm(request.POST)
        form =SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('login')

    else:
        form = SignupForm()
        #form=UserCreationForm()
    return render(request,'registration/signup.html',{'form':form})
Ejemplo n.º 11
0
def SignupForm_view(request):
    form = SignupForm()
    if request.method == "POST":
        form = SignupForm(request.POST)
    if form.is_valid():
        user = form.save()
        user.set_password(user.password)
        user.save()
        return HttpResponseRedirect('/accounts/login')
    return render(request, 'blog/signup_form.html', {'form': form})
Ejemplo n.º 12
0
def sign_up(request):
    if request.method == 'POST':
        s = SignupForm(request.POST)
        if s.is_valid():
            messages.success(request, 'Your are login')
            user = s.save()
            group = Group.objects.get(name='Author')
            user.groups.add(group)
    else:
        s = SignupForm()

    return render(request, 'blog/signup.html', {'form': s})
Ejemplo n.º 13
0
def signup_user(request):
    if request.method == 'POST':
        signup_form = SignupForm(request.POST)
        if signup_form.is_valid():
            user = signup_form.save(commit=False)
            #make hashers password
            user.password = make_password(signup_form.cleaned_data['password'])
            user.save()
            return redirect(reverse('homepage'))
    else:
        signup_form = SignupForm()
    context = {"signup_form": signup_form}
    return render(request, 'blog/signup.html', context)
Ejemplo n.º 14
0
def signUp(request):
    path = request.get_full_path()
    print(path)
    if request.method == 'POST':
        form = SignupForm(data=request.POST)
        if form.is_valid():
            email = form.getEmail()
            print(email)
            return redirect(request,
                            'welcome.html', {'email': email},
                            status='200')
    else:
        form = SignupForm()
    return render(request, 'signUp.html', locals())
Ejemplo n.º 15
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            user.profile.bio = form.cleaned_data['bio']
            user.save()
            #log_user_in
            username = form.cleaned_data['username']
            raw_password = form.cleaned_data['password1']
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('post_list')
    else:
        form = SignupForm()
    return render(request, 'registration/signup.html', {'form': form})
Ejemplo n.º 16
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        print(form.data)
        print(form.is_valid())
        if form.is_valid():
            form.save()

            username = form.data['username']
            email = form.data['email']
            print(username, email)
            salt = hashlib.sha1(str(
                random.random()).encode('utf-8')).hexdigest()[:5]
            activation_key = hashlib.sha1(
                (salt + email).encode('utf-8')).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(1)

            # Create and save user profile
            user = User.objects.get(email=email)
            new_profile = UserProfile(user=user,
                                      activation_key=activation_key,
                                      key_expires=key_expires)
            new_profile.save()

            # Send email with activation key
            email_subject = 'Account confirmation'
            email_body = "Hi %s, thanks for signing up. To activate your account, click this link within \
			48hours http://127.0.0.1:8000/confirm/%s" % (username, activation_key)
            send_mail(email_subject,
                      email_body,
                      '*****@*****.**', [email],
                      fail_silently=False)
            return render(request, 'sign_up_success.html')
        else:
            return render(request, 'confirm_expired.html')
    else:
        return render(request, 'sign_up.html')