Exemple #1
0
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
            })
Exemple #2
0
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))
Exemple #3
0
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)
Exemple #4
0
    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 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 registration_view(request):
    context = {}
    if request.method == 'GET':
        form = RegistrationForm()
        context['registration_form'] = form
        return render(request, 'account/register.html', context)
    else:
        if request.POST['password1'] == request.POST['password2']:
            phn = request.POST['phone_no'].replace(" ", "")
            try:
                user = Account.objects.create_user(
                    request.POST['email'],
                    password=request.POST['password1'],
                    username=request.POST['username'],
                    gender=request.POST['gender'],
                    phone_no=phn,
                    prof_img=None)
                user.save()
                login(request, user)
                return redirect('account:image')
            except IntegrityError:
                return render(request, 'account/register.html',
                              {'form': RegistrationForm()})
        else:
            return render(request, 'account/register.html',
                          {'form': RegistrationForm()})
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})
Exemple #8
0
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))
Exemple #9
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            return redirect('/account/login/')
    else:
        form = RegistrationForm
    args = {'form': form}
    return render(request, 'account/reg_forms.html', args)
Exemple #10
0
def register(request):
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        cd = form.cleaned_data
        user = form.save(commit=False)
        user.set_password(cd['password'])
        user.save()
        UserProfile.objects.create(user=user)
        return render(request, 'account/register_done.html',
                      {'new_user': user})

    ctx = {'form': form}
    return render(request, 'account/register.html', context=ctx)
Exemple #11
0
def account_register(request):
    if request.method == 'POST':
        form = RegistrationForm(data=request.POST)
        if form.is_valid():
            user = User(
                username=form.cleaned_data.get('username')
            )
            user.set_password(form.cleaned_data.get('password'))
            user.save()
            return HttpResponseRedirect(reverse('show_all_tasks'))
        return TemplateResponse(request, 'register.html', {'errors': form.errors})
    else:
        return TemplateResponse(request, 'register.html', {})
Exemple #12
0
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})
Exemple #13
0
    def test_valid_registration_form(self):
        acc = Account.objects.filter(username="******")
        if acc:
            acc.delete()

        data = {
            'username': "******",
            'email': "*****@*****.**",
            'password1': "Qazxcvb111@",
            'password2': "Qazxcvb111@"
        }

        form = RegistrationForm(data=data)
        self.assertTrue(form.is_valid())
Exemple #14
0
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})
Exemple #15
0
 def post(self, request, *args, **kwargs):
     print("Inside Post")
     context = {}
     company_form = RegistrationForm(request.POST)
     if company_form.is_valid():
         company_form.save()
         email = company_form.cleaned_data.get('email')
         raw_password = company_form.cleaned_data.get('password1')
         account = authenticate(email=email, password=raw_password)
         login(request, account)
         return redirect('user')
     else:
         context['registration_form'] = company_form
         return render(request, self.template_name, context)
Exemple #16
0
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)
Exemple #17
0
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))
Exemple #18
0
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)
Exemple #19
0
    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)
Exemple #20
0
    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)
Exemple #21
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=hashed_password).save()
        flash(f"Account created for {form.username.data}!", category="success")
        return redirect(url_for("home"))
    return render_template("account/register.html",
                           title="Register",
                           form=form)
Exemple #22
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        form1 = ProfileTypeForm(request.POST)
        if form.is_valid() and form1.is_valid():
            form.save()
            form1.save()
            return redirect('/account')
    else:
        #		form=RegistrationForm()
        form1 = ProfileTypeForm()
        args = {
            'form1': form1,
        }
        return render(request, 'account/reg_form.html', args)
Exemple #23
0
    def get(self, request):
        if request.user.is_authenticated:
            logout(request)

        return render(request,
                      self.template_name,
                      context={'form': RegistrationForm()})
Exemple #24
0
def LogoutView(request):
    logout(request)
    form = RegistrationForm()
    context = {
        'form':form
    }
    return render(request, 'index/index.html', context)
def signUp(request):
    signUp = 'libraryApp/sign_up.html'

    signUpForm = RegistrationForm()

    context = {"form": signUpForm}
    return render(request, signUp, context)
Exemple #26
0
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 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)
Exemple #28
0
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)
Exemple #29
0
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)
Exemple #30
0
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
        })
Exemple #31
0
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)
Exemple #32
0
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)
Exemple #33
0
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)
Exemple #34
0
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)
Exemple #35
0
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)
Exemple #36
0
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)
Exemple #37
0
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)
Exemple #38
0
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)
Exemple #39
0
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))
Exemple #40
0
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
        )
Exemple #41
0
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)
Exemple #42
0
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})