Exemplo n.º 1
0
def EditProfile(request, id):

    try:
        user = get_user(id)
    except:
        return render(request, 'error.html', {'code': '404'})
    if user == request.user:
        if request.method == 'POST':
            form = SignupForm(request.POST)
            if form.is_valid():
                data = form.cleaned_data
                user.display_name = data['display_name']
                user.bio = data['bio']
                user.email = data['email']
                user.url = data['url']
                user.save()
            return HttpResponseRedirect(reverse('profilePage', args=(id, )))
        form = SignupForm(
            initial={
                'username': user.username,
                'display_name': user.display_name,
                'bio': user.bio,
                'email': user.email,
                'url': user.url
            })
        return render(request, 'generic_form.html', {'form': form})
    return HttpResponseRedirect(reverse('profilePage', args=(id, )))
Exemplo n.º 2
0
def signup(request):
    signup_form = SignupForm(request.POST or None)
    user_profile_signup_form = UserProfileSignupForm(request.POST or None, request.FILES or None)

    if request.method == 'POST':
        if signup_form.is_valid() and user_profile_signup_form.is_valid():
            with transaction.atomic():
                user = signup_form.save(commit=False)
                user.username = user.email
                user.save()
                user_profile = user_profile_signup_form.save(commit=False)
                user_profile.user = user
                ui = UserInfo()
                ui.save()
                user_profile.info = ui
                user_profile.save()
                user = auth.authenticate(username=signup_form.cleaned_data['email'],
                                         password=signup_form.cleaned_data['password1'])
                auth.login(request, user)
                return HttpResponseRedirect('/')

    context = {
        'signup_form': signup_form,
        'user_profile_signup_form': user_profile_signup_form,
        'title': 'Signup'
    }
    return render(request, 'signup.html', context)
Exemplo n.º 3
0
def login_view(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        signup_form = SignupForm(request.POST)
        if Author.objects.filter(
                username=form.data["username"]).first() == None:
            if signup_form.is_valid():

                data = signup_form.cleaned_data
                Author.objects.create_user(username=data["username"],
                                           email=data["email"],
                                           password=data["password"])
                return HttpResponseRedirect(
                    request.GET.get("next", reverse("login")))
        if form.is_valid():
            data = form.cleaned_data
            user = authenticate(request,
                                username=data["username"],
                                password=data["password"])
            if user:
                login(request, user)
                messages.info(request,
                              f"You are now logged in as {user.username}")
                return HttpResponseRedirect(
                    request.GET.get("next", reverse("homepage")))
            else:
                messages.error(request, "Invalid username or password")
        else:
            messages.error(request, "Invalid username or password")
    form = LoginForm()
    signup_form = SignupForm()
    return render(request, "login.html", {
        "form": form,
        "signup_form": signup_form
    })
Exemplo n.º 4
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if not form.is_valid():
            messages.add_message(
                request, messages.ERROR,
                'Error while creating user account. please check all fields and try again'
            )
            return render(request, 'authentication/signup.html',
                          {'form': form})
        else:
            screen_name = form.cleaned_data.get('screen_name')
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')

            get_user_model().objects.create_user(username=username,
                                                 email=email,
                                                 password=password,
                                                 screen_name=screen_name)
            user = authenticate(username=username, password=password)
            login(request, user)
            messages.add_message(request, messages.SUCCESS,
                                 "Your account is successfully created")
            return HttpResponseRedirect('/home/')

    else:
        form = SignupForm()
        return render(request, 'authentication/signup.html', {'form': form})
Exemplo n.º 5
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            mail_subject = 'Activate your blog account.'
            message = render_to_string(
                'authentication/acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )
    else:
        form = SignupForm()
    return render(request, 'authentication/signup.html', {'form': form})
Exemplo n.º 6
0
def signup_view(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            logout(request)
            user = form.save()
            login(request, user)

            return HttpResponseRedirect(reverse('homepage'))

    form = SignupForm()
    return render(request, 'generic_form.html', {'form': form})
Exemplo n.º 7
0
def signup_view(request):
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            new_user = MyUser.objects.create_user(
                username=data.get("username"), password=data.get("password"))
            login(request, new_user)
            return HttpResponseRedirect(reverse("homepage"))

    form = SignupForm()
    return render(request, "generic_form.html", {"form": form})
Exemplo n.º 8
0
def signup(request):
    html = 'signup_form.html'

    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = MyUser.objects.create_user(username=data['user_name'],
                                              password=data['password1'])
            login(request, user)
            return HttpResponseRedirect(reverse('homepage'))

    form = SignupForm()
    return render(request, html, {'form': form})
Exemplo n.º 9
0
def signup(request):
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = TwitterUser.objects.create_user(
                username=data['username'],
                display_name=data['display_name'],
                password=data['password1'],
            )
            user.save()
            login(request, user)
            return HttpResponseRedirect(reverse('homepage'))
    form = SignupForm()
    return render(request, 'SignupForm.html', {'form': form})
Exemplo n.º 10
0
def signup_view(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            new_tweeter = TwitterUser.objects.create_user(
                username=data.get('username'),
                displayname=data.get('displayname'),
                password=data.get('password'))
            if new_tweeter:
                login(request, new_tweeter)
                return HttpResponseRedirect(reverse('homepage'))

    form = SignupForm()
    return render(request, 'generic_form.html', {'form': form})
Exemplo n.º 11
0
 def post(self, request):
     form = SignupForm(request.POST)
     if form.is_valid():
         form.save()
         user = form.instance
         activate_url = self._get_activation_url(request, user)
         messages.success(request, SUCCESS_MESSAGES["account_created"])
         send_email(
             "Activate your account on Paytime",
             SUCCESS_MESSAGES["kindly_verify"].format(
                 user.get_full_name(), activate_url),
             "*****@*****.**",
             "*****@*****.**",
         )
         return redirect("signup")
     return render(request, "authentication/signup.html", {"form": form})
Exemplo n.º 12
0
def adduser(request):
    html = "signup.html"
    form = SignupForm()

    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            new_user = TwitterUser.objects.create_user(
                username=data['username'],
                password=data['password1'],
            )
        new_user.save()
        login(request, new_user)
        return HttpResponseRedirect(reverse('homepage'))
    form = SignupForm()
    return render(request, html, {'form': form})
Exemplo n.º 13
0
def signup_view(request):
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            new_user = TwitterUser.objects.create_user(
                username=data.get("username"),
                password=data.get("password"),
            )
            user = TwitterUser.objects.filter(id=new_user.id)
            new_user.following.set(user)
            if new_user:
                login(request, new_user)
                return HttpResponseRedirect(reverse("index"))

    form = SignupForm()
    return render(request, "generic_form.html", {"form": form})
Exemplo n.º 14
0
def signup_view(request):
    if request.method == "POST":
        form = SignupForm(request.POST, request.FILES)
        if form.is_valid():
            data = form.cleaned_data
            CustomUser.objects.create_user(
                username=data["username"],
                password=data["password"],
                bio=data["bio"],
                email=data["email"],
                platform_choice_field=data["platform_choice_field"],
                avatar=data.get("avatar"),
            )
            return HttpResponseRedirect(
                request.GET.get("next", reverse("homepage")))
    form = SignupForm()
    return render(request, "signup.html", {"form": form})
Exemplo n.º 15
0
 def post(self, req):
     form = SignupForm(req.POST)
     if form.is_valid():
         data = form.cleaned_data
         if NetUser.objects.filter(username=data['username']).exists():
             messages.warning(
                 req, f"Sorry, username {data['username']} already exists.")
             return redirect('/signup/')
         user = NetUser.objects.create_user(username=data['username'],
                                            email=data['email'],
                                            password=data['password'])
         user = authenticate(req,
                             username=data['username'],
                             password=data['password'])
         if user:
             login(req, user)
             return HttpResponseRedirect(req.GET.get('next', '/'))
     return HttpResponseRedirect(req.GET.get('next', '/'))
Exemplo n.º 16
0
    def post(self, request):
        """Reads the content of the filled in form and registers
        the user in the database if all the fields conform to a 
        valid user object, renders a new form with errors otherwise
        """
        form = SignupForm(request.POST)
        usergroup = request.POST.get('usergroup', 'players')

        if form.is_valid():
            group = Group.objects.get(name=usergroup)
            with transaction.atomic():
                new_user = self.register(form)
                group.user_set.add(new_user)
            return render(request, 'registration/registration_complete.html')
        else:
            return render(request,
                          'registration/registration_form.html',
                          context={'form': form})
Exemplo n.º 17
0
def signupView(request):
    if request.user.is_authenticated:
        return redirect('/')

    if request.method == 'POST':
        form = SignupForm(request.POST, request.FILES)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            verify_email(request, user)
            return HttpResponse(
                '<h1 align="center">Verify Your Email. Check Your Mailbox</h1>'
            )

    else:
        form = SignupForm()
    context = {'form': form}
    return render(request, 'authentication/signup.html', context)
Exemplo n.º 18
0
def signup(request):
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            email = form.cleaned_data.get('email')
            User.objects.create_user(username=username,
                                     password=password,
                                     email=email)
            user = authenticate(username=username, password=password)
            login(request, user=user)
            return redirect('/')
        else:
            return render(request, 'authentication\signup.html',
                          {'form': form})
    else:
        return render(request, 'authentication\signup.html',
                      {'form': SignupForm()})
Exemplo n.º 19
0
def Signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            User.objects.create_user(username=username,
                                     email=email,
                                     password=password)
            return redirect('edit-profile')
    else:
        form = SignupForm()

    context = {
        'form': form,
    }

    return render(request, 'signup.html', context)
Exemplo n.º 20
0
def signup(request):
	if request.method == 'POST':
		form = SignupForm(request.POST)
		if form.is_valid():
			email = request.POST.get('email', '')
			username = request.POST.get('username', '')
			password = request.POST.get('password1', '')
			u = User.objects.create_user(username=username, email=email, 
				password=password)
			u.save()
			user = CommonUser(user=u)
			user.save()
			return redirect('/auth/signin')
		else:
			return render_to_response('signup.html', {'form':form},
				context_instance=RequestContext(request))
	else:
		form = SignupForm()
		return render_to_response('signup.html', {'form':form},
			context_instance=RequestContext(request))
Exemplo n.º 21
0
Arquivo: views.py Projeto: platec/cola
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            email = request.POST.get('email', '')
            username = request.POST.get('username', '')
            password = request.POST.get('password1', '')
            u = User.objects.create_user(username=username,
                                         email=email,
                                         password=password)
            u.save()
            user = CommonUser(user=u)
            user.save()
            return redirect('/auth/signin')
        else:
            return render_to_response('signup.html', {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = SignupForm()
        return render_to_response('signup.html', {'form': form},
                                  context_instance=RequestContext(request))
Exemplo n.º 22
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            user.save()
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return redirect(reverse('auth:login'))
        else:
            return render(request, 'authentication/signup.html',
                          {'form': form})
    else:
        form = SignupForm()

        args = {'form': form}
        return render(request, 'authentication/signup.html', args)
Exemplo n.º 23
0
 def post(self, request):
     signup_form = request.POST
     form = SignupForm(signup_form)
     if form.is_valid():
         data = form.cleaned_data
         user = Author.objects.create_user(username=data["username"],
                                           email=data["email"],
                                           password=data["password"])
         if user:
             login(request, user)
             messages.info(
                 request, "Succefully Created, Welcome to Stuff Yo Face!!!")
             return HttpResponseRedirect(
                 request.GET.get("next", reverse("homepage")))
         else:
             messages.error(
                 request,
                 "Unfortunately, there was a problem , Try again..")
     else:
         messages.error(request,
                        "Unfortunately, there was a problem , Try again..")
         return HttpResponseRedirect(
             request.GET.get("next", reverse("homepage")))
Exemplo n.º 24
0
 def post(self, request):
     form = SignupForm(request.POST)
     if form.is_valid():
         data = form.cleaned_data
         try:
             custom_user = CustomUser.objects.create_user(
                 username=data['username'],
                 password=data['password'],
                 email=data['email'],
                 full_name=data['full_name'],
             )
         except:
             messages.error(request, "Username or email already taken.")
             return HttpResponseRedirect(reverse('signup'))
         custom_user.save()
         user = authenticate(request,
                             username=data['username'],
                             password=data['password'])
         if user:
             login(request, user)
             return HttpResponseRedirect(reverse('homepage'))
     messages.error(request, "Invalid fields. Please try again.")
     return HttpResponseRedirect(reverse('signup'))