Beispiel #1
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if not form.is_valid():
            return render(request, 'authentication/signup.html',
                          {'form': form})

        else:
            user = form.save(commit=False)
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            user.set_password(password)
            user.is_active = False
            user.save()

            current_site = get_current_site(request)
            subject = 'Activate Your Onlinebookshare Account'
            message = render_to_string('authentication/account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
            send_mail(subject, message, '*****@*****.**', [email])

            return redirect('account_activation_sent')

    else:
        return render(request, 'authentication/signup.html',
                      {'form': SignUpForm()})
def userSignUp(request):
    context = {}
    if request.method == "POST":
        formData = SignUpForm(request.POST)
        if formData.is_valid():
            username = formData.cleaned_data['username']
            first_name = formData.cleaned_data['name']
            email = formData.cleaned_data['email']
            password = formData.cleaned_data['password']
            contact_no = formData.cleaned_data['contact_no']
            address = formData.cleaned_data['address']
            try:
                User.objects.get(username=username, password=password)
                messages.warning(request, "User already Registered")
                return redirect('/authentication/authenticate.do/')
            except ObjectDoesNotExist:
                user = User.objects.create_user(username=username,
                                                email=email,
                                                first_name=first_name,
                                                password=password)
                user_add = Address(address=address,
                                   contact_no=contact_no,
                                   user_id=user)
                user_add.save()
                messages.success(request, "Signed Up Successfully")
                return redirect('/authentication/authenticate.do/')
        else:
            context['form'] = formData
            return render(request, 'authentication/signup.html', context)
    else:
        context['form'] = SignUpForm(None)
        return render(request, 'authentication/signup.html', context)
Beispiel #3
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if not form.is_valid():
            ## Lin,Leo - provide a context with error message to the user
            ## of why form validation failed!
            return render(request, 'authentication/signup.html',
                          {'form': form})

        else:
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            User.objects.create_user(username=username,
                                     password=password,
                                     email=email)
            user = authenticate(username=username, password=password)
            login(request, user)
            ## Lin,Leo - once the user has successfully signed-in, we
            ## redirect them to their own portal
            return redirect(
                'home')  ## - TODO: redirect user to their own portal

    else:
        return render(request, 'authentication/signup.html',
                      {'form': SignUpForm()})
Beispiel #4
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)

        if not form.is_valid():
            return render(request, 'authentication/signup.html',
                          {'form': form})

        else:
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            email = form.cleaned_data.get('email')
            birthday = form.cleaned_data.get('birthday')
            randomId = form.cleaned_data.get('randomId')

            User.objects.create_user(username=username,
                                     password=password,
                                     email=email,
                                     randomId=randomId,
                                     birthday=birthday)
            #import pdb; pdb.set_trace()
            user = authenticate(username=username, password=password)
            login(request, user)
            welcome_post = '{0} has joined the network.'.format(
                user.username, user.username)

            return redirect('list')

    else:
        return render(request, 'authentication/signup.html',
                      {'form': SignUpForm()})
 def test_when_missing_required_fields(self):
     """To check the response when a required fields is missing"""
     for field in ('email', 'password1', 'password2'):
         with self.subTest(field=field):
             my_data = self.data.copy()
             my_data[field] = ''
             form = SignUpForm(my_data)
             self.assertFalse(form.is_valid())
Beispiel #6
0
def signup_view(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            new_twitter_user = TwitterUser.objects.create_user(username=data.get('username'),  password=data.get('password'), tagname=data.get('tagname'), bio=data.get('bio'))
            login(request, new_twitter_user)
            return HttpResponseRedirect(reverse('homepage'))
    form = SignUpForm()
    return render(request, 'signupform.html', {'form': form})
Beispiel #7
0
def signUp(request):
    form = SignUpForm()
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            # Comprobar que no haya usuario con el mismo correo
            if User.objects.filter(
                    email=form.cleaned_data['email']).count() > 0:
                form.add_error('email', 'El email indicado ya está en uso')
                return render(request, 'signUp.html', {'form': form})
            # Comprobar que no haya usuario con mismo username
            if User.objects.filter(
                    username=form.cleaned_data['username']).count() > 0:
                form.add_error('username',
                               'El nombre de usuario indicado ya está en uso')
                return render(request, 'signUp.html', {'form': form})
            user = User.objects.create_user(form.cleaned_data['username'],
                                            form.cleaned_data['email'],
                                            form.cleaned_data['password'])
            user.first_name = form.cleaned_data['nombre']
            user.last_name = form.cleaned_data['apellidos']
            user.save()
            perfil = Perfil(user=user)
            perfil.save()
            for dieta in form.cleaned_data['dieta']:
                perfil.dietas.add(get_object_or_404(Dieta, nombre=dieta))
            return redirect('/authentication/login')
    return render(request, 'signUp.html', {'form': form})
    def test_password_safe_input(self):
        """
        To check the safety of the system
        password1 must equals password2

        """
        self.form = SignUpForm()
        input_type = self.form['password1'].field.widget.input_type
        self.assertEqual(input_type, 'password')
        input_type = self.form['password2'].field.widget.input_type
        self.assertEqual(input_type, 'password')
Beispiel #9
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"))
            login(request, new_user)
            return HttpResponseRedirect(reverse("homepage"))
    form = SignUpForm()
    return render(request, "generic_form.html", {"form": form})
Beispiel #10
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if not form.is_valid():
            messages.add_message(
                request, messages.ERROR, 'There was some problems while creating your account. Please review some fields before submiting again.')
            return render(request, 'auth/signup.html', {'form': form})
        else:
            return HttpResponse('is valid')
    else:
        return render(request, 'auth/signup.html', {'form': SignUpForm()})
Beispiel #11
0
 def post(self, request):
     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('home'))
Beispiel #12
0
def signupview(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = TweetUser.objects.create_user(username=data["username"],
                                                 password=data['password'],
                                                 email=data['email'],
                                                 bio=data['bio'])
            Notifications.objects.create(user=user, notification_count=0)
            return HttpResponseRedirect(reverse('login'))
    form = SignUpForm
    return render(request, 'signup.html', {'form': form})
Beispiel #13
0
def signupview(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'],
                password=data['password'],
            )
            return HttpResponseRedirect(reverse('homepage'))

    form = SignUpForm()
    return render(request, 'generic_form.htm', {'form': form})
Beispiel #14
0
    def post(self, request):
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']

            user = authenticate(request, username=username, password=password)
            if user:
                login(request, user)
            return redirect('index')
        context = {'form': form}
        return render(request, 'authentication/signupform.html', context)
Beispiel #15
0
 def post(self, request):
     form = SignUpForm(request.POST)
     if form.errors:
         messages.add_message(request, messages.INFO, 'Password invalid')
     if form.is_valid():
         data = form.cleaned_data
         new_user = RedditUser.objects.create_user(
             username=data['username'],
             email=data['email'],
             password=data['password']
         )
         new_user.save()
         login(request, new_user)
         return HttpResponseRedirect(reverse('homepage'))
Beispiel #16
0
def signupview(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = authenticate(request,
                                username=data['username'],
                                password=data['password'])
            if user:
                login(request, user)
                return HttpResponseRedirect(
                    request.GET.get('next', reverse('homepage')))
    form = SignUpForm()
    return render(request, 'generic_form.html', {'form': form})
Beispiel #17
0
def signup_view(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'],
                password=data['password'],
                displayname=data['displayname'])
            if user:
                login(request, user)
                return HttpResponseRedirect(reverse('loginpage'))
    form = SignUpForm()
    return render(request, 'signup.html', {"form": form})
Beispiel #18
0
def signup_view(request):
    context = {}
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user_info = TwitterUser.objects.create_user(
                first_name=data['first_name'],
                last_name=data['last_name'],
                username=data['username'],
                email=data['email'],
                password=data['password'],
            )
            return HttpResponseRedirect(reverse('twitteruser:home_view'))
    form = SignUpForm()
    context.update({'form': form, 'heading_two': 'Sign Up'})
    return render(request, 'forms/generic.html', context)
Beispiel #19
0
def signup(request):
    html = 'generic_form.htm'

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = CustomUser.objects.create_user(
                username=data['username'],
                password=data['password'],
                display_name=data['display_name'],
                homepage=data['homepage'],
                age=data['age'])
            return HttpResponseRedirect(reverse('home'))

    form = SignUpForm()
    return render(request, html, {'form': form})
Beispiel #20
0
def signup_view(request):
    if request.method == "POST":
        form = SignUpForm(request.POST, request.FILES)
        if form.is_valid():
            data = form.cleaned_data
            new_user = InstaUser.objects.create_user(
                username=data.get("username"),
                password=data.get("password"),
                bio=data.get("bio"),
                website=data.get("website"),
                profile_image=data.get("profile_image"))
            login(request, new_user)
            return HttpResponseRedirect(reverse("homepage"))
        else:
            return HttpResponse(form.errors.values())
    form = SignUpForm()
    return render(request, 'generic_form.html', {"form": form})
Beispiel #21
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if not form.is_valid():
            messages.add_message(request, messages.ERROR, 'There was some problems while creating your account. Please review some fields before submiting again.')
            return render(request, 'auth/signup.html', { 'form': form })
        else:
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            User.objects.create_user(username=username, password=password, email=email)
            user = authenticate(username=username, password=password)
            login(request, user)
            messages.add_message(request, messages.SUCCESS, 'Your account were successfully created.')
            return HttpResponseRedirect('/' + username + '/')
    else:
        return render(request, 'auth/signup.html', { 'form': SignUpForm() })
def user_management(request):

    msg = None
    success = False

    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)

            msg = 'User created'
            success = True

            #return redirect("/login/")

        else:
            msg = 'Form is not valid'
    else:
        form = SignUpForm()

    context = {}
    context['segment'] = 'user-management.html'
    context['page_name'] = 'User Management'
    context['users'] = User.objects.all()
    context['form'] = form
    context['msg'] = msg
    context['success'] = success

    html_template = loader.get_template('user-management.html')
    return HttpResponse(html_template.render(context, request))
Beispiel #23
0
def registerView(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('/')
    else:
        form = SignUpForm()

    if (request.user.is_authenticated):
        user = User.objects.get(username=request.user.username)
        context = {
            'form': form,
            'user': user,
        }
    else:
        context = {
            'form': form,
        }

    return render(request, 'register.html', context=context)
Beispiel #24
0
 def get(self, request):
     form = SignUpForm()
     subreddit_filter = subreddit_search(request)
     context = {
         'form': form,
         'subreddit_filter': subreddit_filter,
         'search_subreddits': search_subreddits
     }
     return render(request, 'authentication/signupform.html', context)
Beispiel #25
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 = User.objects.create_user(username=username,
                                            password=password,
                                            email=email)
            user.refresh_from_db()
            user.profile.role = form.cleaned_data.get('role')
            user.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('/account/login/')
    else:
        form = SignUpForm()
    return render(request, 'authentication/signup.html', {'form': form})
Beispiel #26
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if not form.is_valid():
            return render(request, 'authentication/signup.html',
                          {'form': form})

        else:
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            User.objects.create_user(username=username,
                                     password=password,
                                     email=email)
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('/signupdetailed')

    else:
        return render(request, 'authentication/signup.html',
                      {'form': SignUpForm()})
Beispiel #27
0
def signup(request):
    """Render sign up view."""
    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)
            subject = _('Activá tu cuenta de NFL prode')
            message = render_to_string('authentication/account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
                'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)

            return redirect('account_activation_sent')

    else:
        form = SignUpForm()

    return render(request, 'authentication/signup.html', {'form': form, 'view': 'signup'})
Beispiel #28
0
class TestSignUpForm(TestCase):
    """To test the authentication form"""
    data = {
        'email': '*****@*****.**',
        'password1': 'some password',
        'password2': 'some password',
    }

    def test_valid_form(self):
        """To test if all the required fields are there"""
        self.form = SignUpForm(self.data)
        self.assertTrue(self.form.is_valid())

    def test_if_invalid_email(self):
        """To test when an incorrect email is given"""
        self.new_data = self.data.copy()
        self.new_data['email'] = 'no arobase email'
        self.form = SignUpForm(self.new_data)
        self.assertFalse(self.form.is_valid())

    def test_when_missing_required_fields(self):
        """To check the response when a required fields is missing"""
        for field in ('email', 'password1', 'password2'):
            with self.subTest(field=field):
                my_data = self.data.copy()
                my_data[field] = ''
                form = SignUpForm(my_data)
                self.assertFalse(form.is_valid())

    def test_password_safe_input(self):
        """
        To check the safety of the system
        password1 must equals password2

        """
        self.form = SignUpForm()
        input_type = self.form['password1'].field.widget.input_type
        self.assertEqual(input_type, 'password')
        input_type = self.form['password2'].field.widget.input_type
        self.assertEqual(input_type, 'password')
Beispiel #29
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(data=request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            # Setting as False to prevent login without confirming email
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = 'Verify your DjangoLogin Account'
            message = render_to_string(
                'authentication/account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
            print("Mail Done!")
            return redirect(to='authentication:account_activation_sent')
        else:
            return render(request,
                          template_name='authentication/signup.html',
                          context={'form': form})
    else:
        form = SignUpForm()
        return render(request,
                      template_name='authentication/signup.html',
                      context={'form': form})
Beispiel #30
0
def register(request):

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('authentication:login')
    else:
        form = SignUpForm()

    return render(request, 'register.html', {'form': form})
Beispiel #31
0
def edit_profile(request, username):
    me = MyUser.objects.filter(username=username).first()
    if request.method == "POST":
        form = SignUpForm(request.POST, instance=me)
        if form.is_valid():
            data = form.cleaned_data
            me.username = data['username']
            me.set_password(data['password'])
            me.email = data['email']
            me.first_name = data['first_name']
            me.last_name = data['last_name']
            me.save()
            user = authenticate(request,
                                username=data['username'],
                                password=data['password'])
            if user:
                login(request, user)
                return HttpResponseRedirect(
                    request.GET.get('next', reverse('homepage')))

    form = SignUpForm(instance=me)
    return render(request, "generic_form.html", {'form': form, 'my_user': me})
Beispiel #32
0
def signup(request):
    user_agent = get_user_agent(request)
    error_message = None
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            new_password = form.cleaned_data['new_password']
            confirm_new_password = form.cleaned_data['confirm_new_password']

            try:
                user = User.objects.get(username=username)
                error_message = 'Username already exists'
                context = {
                    'form': form,
                    'error_message': error_message,
                    'mobile': user_agent.is_mobile,
                }
                return render(request, 'signup.html', context)
            except User.DoesNotExist:
                pass

            try:
                user = User.objects.get(email=email)
                error_message = 'Email is already registered'
                context = {
                    'form': form,
                    'error_message': error_message,
                    'mobile': user_agent.is_mobile,
                }
                return render(request, 'signup.html', context)
            except User.DoesNotExist:
                pass

            if not new_password == confirm_new_password:
                error_message = 'Passwords does not match'
                context = {
                    'form': form,
                    'error_message': error_message,
                    'mobile': user_agent.is_mobile,
                }
                return render(request, 'signup.html', context)

            if str(email).endswith('@stud.ntnu.no') or str(email).endswith('@ntnu.no') or str(email).endswith('@ntnu.edu'):

                user = User.objects.create(username=username,
                                           email=email,
                                           first_name=first_name,
                                           last_name=last_name,)
                user.set_password(new_password)
                user.is_active = False
                user.save()

                auth_object = UserAuthentication.objects.create(user=user)
                auth_object.save()
                email_subject = 'Account @ hackerspace NTNU'
                message = 'Congratulations! Your user is created. Activate your user account trough this link'
                email_message = render_to_string('signup_mail.html', {'request': request, 'message': message, 'hash_key': auth_object.key.hex})
                thread = Thread(target=send_password_email, args=(email_subject, email_message, email))
                thread.start()

                return HttpResponseRedirect(reverse('signup_done'))

            else:
                error_message = 'You need to use an NTNU email'
                context = {
                    'form': form,
                    'error_message': error_message,
                    'mobile': user_agent.is_mobile,
                }
                return render(request, 'signup.html',  context)

    else:
        form = SignUpForm()

    context = {
        'form': form,
        'error_message': error_message,
        'mobile': user_agent.is_mobile,
    }
    return render(request, 'signup.html', context)