コード例 #1
0
ファイル: views.py プロジェクト: WilliamRen/django-rest-auth
 def perform_create(self, serializer):
     user = serializer.save(self.request)
     create_token(self.token_model, user, serializer)
     complete_signup(self.request._request, user,
                     allauth_settings.EMAIL_VERIFICATION,
                     None)
     return user
コード例 #2
0
ファイル: views.py プロジェクト: ron8mcr/django-rest-auth
 def perform_create(self, serializer):
     user = serializer.save(self.request)
     Token.objects.get_or_create(user=user)
     complete_signup(self.request._request, user,
                     allauth_settings.EMAIL_VERIFICATION,
                     None)
     return user
コード例 #3
0
ファイル: views.py プロジェクト: opennut/stack-blog
def register(request):
	if request.user.is_authenticated():
		return HttpResponseRedirect(reverse("home"))
	else:
		if request.method == 'POST':
			form = RegisterForm(request.POST)
			
			x_user = User.objects.filter(email=request.POST["email"])
			if x_user.count() > 0:
				form.add_error('email', _('Este email ya existe'))
			else:
				if form.is_valid():
					current = form.save(commit=False)
					current.save()
					perfil = UserProfile()
					perfil.user = current
					perfil.save() 


					complete_signup(request, current,app_settings.EMAIL_VERIFICATION, "/")
					return HttpResponseRedirect(reverse("registered"))


		else:
			form = RegisterForm()
		return render(
			request, 
			'register.html',
				{
					"form": form
				}
			)
コード例 #4
0
ファイル: serializers.py プロジェクト: jsmesami/naovoce
    def save(self, request):
        self.cleaned_data = self.validated_data  # Needed by new_user()
        user = get_account_adapter().new_user(request)
        original_request = request._request

        get_account_adapter().save_user(request, user, self)
        setup_user_email(request, user, [])
        complete_signup(original_request, user, allauth_settings.EMAIL_VERIFICATION, None)

        return user
コード例 #5
0
ファイル: views.py プロジェクト: bss3/django-rest-auth
 def perform_create(self, serializer):
     user = serializer.save()
     if getattr(settings, 'REST_USE_JWT', False):
         self.token = jwt_encode(user)
     else:
         create_token(self.token_model, user, serializer)
     complete_signup(self.request._request, user,
                     allauth_settings.EMAIL_VERIFICATION,
                     None)
     return user
コード例 #6
0
ファイル: profile.py プロジェクト: shekit/imly
def modal_signup(request, **kwargs):
    
    if request.method == "POST":
        signup_form = SignupForm(request.POST)
        if signup_form.is_valid():
            user = signup_form.save(request)
            next = request.POST.get("next","/food/")
            complete_signup(request, user, "/food/")
            return HttpResponse(next)
        redirect_field_name, redirect_field_value = "next", request.referer
        response = render(request, "signup_error.html", locals())
        response.status_code = 400
        return response
コード例 #7
0
ファイル: helpers.py プロジェクト: ThisIsJohnBrown/writingoal
def complete_social_signup(request, sociallogin):
    if app_settings.AVATAR_SUPPORT:
        _copy_avatar(request, sociallogin.account.user, sociallogin.account)
    print 'REDIRECT URL = %s' % sociallogin.get_redirect_url()
    return complete_signup(request, 
                           sociallogin.account.user, 
                           '/connections/social/created/')
コード例 #8
0
ファイル: helpers.py プロジェクト: artminster/django-allauth
def complete_social_signup(request, sociallogin):
    if app_settings.AVATAR_SUPPORT:
        signals.user_signed_up.send(sender=user.__class__, request=request, user=user)
        _copy_avatar(request, sociallogin.account.user, sociallogin.account)
    return complete_signup(request,
                           sociallogin.account.user,
                           sociallogin.get_redirect_url(request))
コード例 #9
0
ファイル: views.py プロジェクト: newbie-gk/django-rest-auth
 def form_valid(self, form):
     self.user = form.save(self.request)
     if isinstance(self.request, HttpRequest):
         request = self.request
     else:
         request = self.request._request
     return complete_signup(request, self.user, app_settings.EMAIL_VERIFICATION, self.get_success_url())
コード例 #10
0
ファイル: views.py プロジェクト: hzlf/openbroadcast
def signup(request, **kwargs):
    
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "ajaxaccount/signup.html")
    redirect_field_name = kwargs.pop("redirect_field_name", "next")
    success_url = kwargs.pop("success_url", None)
    
    extra = None
    if 'extra' in request.GET:
        extra = request.GET.get('extra')
    
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)
    
    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            user = form.save(request=request)
            return complete_signup(request, user, success_url)
    else:
        form = form_class()
    ctx = {"form": form,
           "login_url": passthrough_login_redirect_url(request,
                                                       reverse("account_login")),
           "redirect_field_name": redirect_field_name,
           "extra": extra,
           "redirect_field_value": request.REQUEST.get(redirect_field_name) }
    return render_to_response(template_name, RequestContext(request, ctx))
コード例 #11
0
ファイル: login.py プロジェクト: alonslotky/universal_tutors
def allauth_signup(request, **kwargs):
    
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    redirect_field_name = kwargs.pop("redirect_field_name", "next")
    success_url = kwargs.pop("success_url", None)
    extra_ctx = kwargs.pop("extra_ctx", {})
    
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)
    
    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            user = form.save(request=request)
            profile = user.profile
            for p in request.FILES.getlist('profile_image'):
                profile.profile_image.save(p.name, p)
                profile.save()
            return complete_signup(request, user, success_url)
    else:
        form = form_class()
    ctx = {"form": form,
           "login_url": passthrough_login_redirect_url(request,
                                                       reverse("account_login")),
           "redirect_field_name": redirect_field_name,
           "redirect_field_value": request.REQUEST.get(redirect_field_name) }
    ctx.update(extra_ctx)
    return render_to_response(template_name, RequestContext(request, ctx))
コード例 #12
0
ファイル: views.py プロジェクト: misterMuyiwa/soc-media-aggr
def signup(request, **kwargs):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse(connections))
    signup = request.session.get('socialaccount_signup')
    if not signup:
        return HttpResponseRedirect(reverse(login))
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", 
                               'socialaccount/signup.html')
    data = signup['data']
    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            user = form.save(request=request)
            user.last_name = data.get('last_name', '')
            user.first_name = data.get('first_name', '')
            user.save()
            account = signup['account']
            account.user = user
            account.save()
            return complete_signup(request, user, 
                                   get_login_redirect_url(request))
    else:
        form = form_class(initial=data)
    dictionary = dict(site=Site.objects.get_current(),
                      account=signup['account'],
                      form=form)
    return render_to_response(template_name, 
                              dictionary, 
                              RequestContext(request))
コード例 #13
0
ファイル: helpers.py プロジェクト: Enigmatical/django-allauth
def complete_social_signup(request, sociallogin):
    if app_settings.AVATAR_SUPPORT:
        _copy_avatar(request, sociallogin.account.user, sociallogin.account)
    return complete_signup(request, 
                           sociallogin.account.user, 
                           sociallogin.get_redirect_url(request),
                           signal_kwargs={'sociallogin': sociallogin})
コード例 #14
0
ファイル: views.py プロジェクト: lucassimon/pywatch.com.br
 def form_valid(self, form):
     user = form.save(self.request)
     return complete_signup(
         self.request,
         user,
         app_settings.EMAIL_VERIFICATION,
         self.get_success_url()
     )
コード例 #15
0
ファイル: helpers.py プロジェクト: sohan/django-allauth
def complete_social_signup(request, sociallogin):
    if app_settings.AVATAR_SUPPORT:
        _copy_avatar(request, sociallogin.account.user, sociallogin.account)
    return complete_signup(request, 
                           sociallogin.account.user, 
                           sociallogin.get_redirect_url(), 
                           provider=sociallogin.account.provider,
                           distinct_id=sociallogin.get_distinct_id())
コード例 #16
0
ファイル: views.py プロジェクト: Peder1987/buzzhire
    def form_valid(self, form):
        """Adapted from BaseSignupView to save the freelancer too.
        """

        user = form.save(self.request)
        # Save freelancer form too
        self.bound_forms['freelancer'].save(user)
        return complete_signup(self.request, user,
                               app_settings.EMAIL_VERIFICATION,
                               self.get_success_url())
コード例 #17
0
ファイル: helpers.py プロジェクト: dipapaspyros/opencolibri
def complete_social_signup(request, sociallogin):
    profile = sociallogin.account.user.profile
    setattr(profile, "%sUrl" % sociallogin.account.provider, sociallogin.account.get_profile_url())
    profile.save()
    if True:
        _copy_avatar(request, sociallogin.account.user, sociallogin.account)
    return complete_signup(request,
                           sociallogin.account.user,
                           sociallogin.get_redirect_url(request),
                           signal_kwargs={'sociallogin': sociallogin})
コード例 #18
0
ファイル: views.py プロジェクト: kahihia/buzzhire-1
    def form_valid(self, form):
        """Adapted from BaseSignupView to save the freelancer too.
        """

        user = form.save(self.request)
        # Save freelancer form too
        self.bound_forms['freelancer'].save(user)
        return complete_signup(self.request, user,
                               app_settings.EMAIL_VERIFICATION,
                               self.get_success_url())
コード例 #19
0
ファイル: views.py プロジェクト: SakuradaJun/django-rest-auth
 def form_valid(self, form):
     self.user = form.save(self.request)
     self.token, created = self.token_model.objects.get_or_create(
         user=self.user)
     if isinstance(self.request, HttpRequest):
         request = self.request
     else:
         request = self.request._request
     return complete_signup(request, self.user,
                            app_settings.EMAIL_VERIFICATION,
                            self.get_success_url())
コード例 #20
0
    def create(self, validated_data):
        user = self._new_user(validated_data['email'])

        respond = complete_signup(
            self._request, user, allauth_settings.EmailVerificationMethod.NONE,
            '#')
        assert respond.status_code == status.HTTP_302_FOUND

        token = get_login_token_with_auth_info(user, AuthAction.REGISTRATION,
                                               AuthProvider.EMAIL)
        return dict(token=token, user=user)
コード例 #21
0
ファイル: views.py プロジェクト: mariodev/django-rest-auth
 def form_valid(self, form):
     self.user = form.save(self.request)
     self.token, created = self.token_model.objects.get_or_create(
         user=self.user)
     if isinstance(self.request, HttpRequest):
         request = self.request
     else:
         request = self.request._request
     return complete_signup(request, self.user,
                            app_settings.EMAIL_VERIFICATION,
                            self.get_success_url())
コード例 #22
0
ファイル: views.py プロジェクト: JonNatanael/TPO
 def form_valid(self, form):
     user = form.save(self.request)
     try:
         user.referral = User.objects.get(id=self.request.session['referral'])
     except KeyError:
         pass
     except ValueError:
         pass
     except ObjectDoesNotExist:
         pass
     user.save()
     return complete_signup(self.request, user, self.get_success_url())
コード例 #23
0
 def form_valid(self, form):
     # By assigning the User to a property on the view, we allow subclasses
     # of SignupView to access the newly created User instance
     self.user = form.save(self.request)
     send_mail(
         "New user signed up!",
         "https://intranet.eshc.coop/admin to assign a reference number",
         "*****@*****.**", ["*****@*****.**"],
         fail_silently=True)
     return complete_signup(self.request, self.user,
                            app_settings.EMAIL_VERIFICATION,
                            self.get_success_url())
コード例 #24
0
 def form_valid(self, form):
     # no email verification required
     self.user = form.save(self.request)
     try:
         return complete_signup(
             self.request,
             self.user,
             "none",
             self.get_success_url(),
         )
     except ImmediateHttpResponse as e:
         return e.response
コード例 #25
0
ファイル: views.py プロジェクト: kahihia/buzzhire-1
    def form_valid(self, form):
        """Adapted from BaseSignupView to save the client and log them in.
        """
        user = form.save(self.request)

        # Save extra forms too
        client = self.bound_forms['client'].save(user=user)

        # Complete sign up and log them in
        return complete_signup(self.request, user,
                               app_settings.EMAIL_VERIFICATION,
                               self.get_success_url())
コード例 #26
0
ファイル: views.py プロジェクト: mfrlin/TPO
 def form_valid(self, form):
     user = form.save(self.request)
     try:
         user.referral = User.objects.get(
             id=self.request.session['referral'])
     except KeyError:
         pass
     except ValueError:
         pass
     except ObjectDoesNotExist:
         pass
     user.save()
     return complete_signup(self.request, user, self.get_success_url())
コード例 #27
0
ファイル: views.py プロジェクト: larry852/redzza
    def createUser(self, request):
        try:
            created = False
            email = request.data.get('email', None)
            username = utils.generateRandomUsername(request.data.get('first_name', None))
            first_name = request.data.get('first_name', None)
            last_name = request.data.get('last_name', None)
            password = request.data.get('password', None)

            if email and username and first_name and last_name and password:
                if Profile.searchEmail(email) is False:
                    if utils.validateStructureEmail(email):
                        user, created = Profile.createUser(email, username, first_name, last_name, password)
                        if created:
                            idPlace = Place.searchName("Sin definir").id
                            Profile.create(idPlace, user)
                            login(request, user)
                            token = Token.objects.create(user=user)
                            userSerialized = json.loads(serializers.serialize('json', [user], fields=('username', 'first_name', 'last_name', 'email', 'is_active', 'last_login', 'date_joined')))
                            complete_signup(request._request, user, allauth_settings.EMAIL_VERIFICATION, None)
                            userSerialized[0]['fields']['is_verified'] = EmailAddress.objects.get(user=user).verified
                            return Response({'success': True, 'msg': 'user-created', 'token': token.key, 'user': userSerialized}, status=status.HTTP_201_CREATED)
                        else:
                            return Response({'success': False, 'err': 'User not created'}, status=status.HTTP_422_UNPROCESSABLE_ENTITY)
                    else:
                        return Response({'success': False, 'err': 'Invalid Email'}, status=status.HTTP_422_UNPROCESSABLE_ENTITY)
                else:
                    return Response({'success': False, 'err': 'email-exists'}, status=status.HTTP_422_UNPROCESSABLE_ENTITY)
            else:
                return Response({'success': False, 'err': 'Incomplete data'}, status=status.HTTP_400_BAD_REQUEST)
        except Exception as e:
            if hasattr(e, 'message'):
                err = e.message
            else:
                err = e
            if created:
                user.delete()
            return Response({'success': False, 'err': str(err)}, status=status.HTTP_422_UNPROCESSABLE_ENTITY)
コード例 #28
0
ファイル: views.py プロジェクト: Meganmccarty/entsocwash
 def form_valid(self, form):
     """
     Override the base allauth SignupView method so that the user is only saved once
     """
     # self.user defined in post method
     try:
         return complete_signup(
             self.request,
             self.user,
             settings.ACCOUNT_EMAIL_VERIFICATION,
             self.get_success_url(),
         )
     except ImmediateHttpResponse as e:
         return e.response
コード例 #29
0
ファイル: api.py プロジェクト: pavanv/commondrive
    def signup(self, request, **kwargs):
        self.method_check(request, allowed=['post'])

        data = self.deserialize(
            request, request.body,
            format=request.META.get('CONTENT_TYPE', 'application/json'))

        try:
            form = SignupForm(data)
            if not form.is_valid():
                return self.create_response(request, {
                    'success': False,
                    'reason': 'form',
                    'error_type': 'dict',
                    'error': form.errors,
                }, HttpBadRequest)
            user = form.save(request)
            response = complete_signup(request, user,
                                       app_settings.EMAIL_VERIFICATION,
                                       success_url='/')
            if response.status_code not in [200, 201, 301, 302]:
                return self.create_response(request, {
                    'success': False,
                    'reason': 'status',
                    'error_type': 'str',
                    'error': 'Got bad status code {}'.format(response.status_code),
                })

            # Set session expiry
            request.session.set_expiry(settings.SESSION_COOKIE_AGE)

            return self.create_response(request, {
                'success': True,
                'id': user.id,
                'resource_uri': self.get_resource_uri(user),
            }, HttpCreated)
        except ValidationError as e:
            return self.create_response(request, {
                'success': False,
                'reason': 'invalid',
                'error_type': 'list',
                'error': e.messages,
            }, HttpBadRequest)
        except Exception as e:
            return self.create_response(request, {
                'success': False,
                'reason': 'exception',
                'error_type': 'str',
                'error': '{}'.format(e),
            }, HttpBadRequest)
コード例 #30
0
    def form_valid(self, form):
        self.user = form.save(self.request)

        #インスタンスの作成
        blank = ""
        logger.debug("ここの部門:{}".format(form.cleaned_data['department_pro']))
        logger.debug("hello : {}".format(
            CustomUser.objects.get(email=form.cleaned_data['email'])))
        new_profile = EProfile.objects.create(
            user_id=CustomUser.objects.get(
                email=form.cleaned_data['email']).id,
            last_name_k=blank,
            first_name_k=blank,
            last_name=form.cleaned_data['last_name'],
            first_name=form.cleaned_data['first_name'],
            gender=0,
            nationality=blank,
            phone=blank,
            postal_code=blank,
            address1=blank,
            address2=blank,
            residence_card=blank,
            health_insurance=blank,
            department_pro_id=EDepartment.objects.get(
                department=form.cleaned_data['department_pro']).dep_id,
            emergency_contact_1_name=blank,
            emergency_contact_1_relationship=blank,
            emergency_contact_1_phone=blank,
            emergency_contact_2_name=blank,
            emergency_contact_2_relationship=blank,
            emergency_contact_2_phone=blank,
            emergency_contact_3_name=blank,
            emergency_contact_3_relationship=blank,
            emergency_contact_3_phone=blank,
            create_date=timezone.now(),
            create_id=self.request.user.id,  #ログインしているユーザーID
            update_date=timezone.now(),
            update_id=self.request.user.id,
            delete=0,
        )

        # By assigning the User to a property on the view, we allow subclasses
        # of SignupView to access the newly created User instance
        try:
            return complete_signup(self.request, self.user,
                                   app_settings.EMAIL_VERIFICATION,
                                   self.get_success_url())
        except ImmediateHttpResponse as e:
            return e.response
コード例 #31
0
ファイル: helpers.py プロジェクト: cinqi/django-allauth
def complete_social_signup(request, sociallogin):
    log.debug('socialaccount.helpers.complete_social_signup')
    log.debug("complete_social_signup")
    if app_settings.AVATAR_SUPPORT:
        _copy_avatar(request, sociallogin.account.user, sociallogin.account)
    if app_settings.INVITE_MODE:
        log.debug("Checking whether this user had an invitation code")
        if sociallogin.account.user.invitations_used.count() == 0:
            log.debug("No invitation - deactivating user")
            sociallogin.account.user.is_active = False
            sociallogin.account.user.save()
    log.debug("Social signup complete")   
    return complete_signup(request, 
                           sociallogin.account.user, 
                           sociallogin.get_redirect_url())
コード例 #32
0
    def perform_create(self, serializer):
        user = serializer.save(self.request)
        if getattr(settings, 'REST_USE_JWT', False):
            self.token = jwt_encode(user)
        else:
            create_token(self.token_model, user, serializer)

        complete_signup(self.request._request, user,
                        allauth_settings.EMAIL_VERIFICATION, None)

        # Actualizo el usuario en UserCompany ahora el usuario está vinculado a
        # una empresa y un perfil
        try:
            my_user = UserCompany.objects.get(email=user.email)
            print('my_user', my_user)
            my_user.user = AuthUser.objects.get(email=user.email)
            #print ('my_user.user', my_user.user)
            my_user.save()
            my_user = AuthUser.objects.filter(
                email=user.email).values_list('id')
            print(my_user)
        except:
            pass
        return user
コード例 #33
0
 def form_valid(self, form):
     # By assigning the User to a property on the view, we allow subclasses
     # of SignupView to access the newly created User instance
     self.user = form.save(self.request)
     try:
         db_logger.info(
             f'Account successfully created by user - {form.cleaned_data["username"]}'
         )
         return complete_signup(
             self.request,
             self.user,
             app_settings.EMAIL_VERIFICATION,
             self.get_success_url(),
         )
     except ImmediateHttpResponse as e:
         return e.response
コード例 #34
0
ファイル: helpers.py プロジェクト: snswa/django-allauth
def _process_signup(request, data, account):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = data.get("email")
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                email_address = get_email_address(email)
                if email_address:
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif account_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        request.session["socialaccount_signup"] = dict(data=data, account=account)
        ret = HttpResponseRedirect(reverse("socialaccount_signup"))
    else:
        # FIXME: There is some duplication of logic inhere
        # (create user, send email, in active etc..)
        username = generate_unique_username(data.get("username", email or "user"))
        u = User(
            username=username,
            email=email or "",
            last_name=data.get("last_name", ""),
            first_name=data.get("first_name", ""),
        )
        u.set_unusable_password()
        u.is_active = not account_settings.EMAIL_VERIFICATION
        u.save()
        account.user = u
        account.save()
        send_email_confirmation(u, request=request)
        ret = complete_signup(request, u, get_login_redirect_url(request))
    return ret
コード例 #35
0
ファイル: views.py プロジェクト: jerinzam/djangoProject
 def form_valid(self, form):
     # import ipdb; ipdb.set_trace();
     # set_user_role(self.user, roles.manager)
     self.user = form.save(self.request)
     set_user_role(self.user, roles.owner)
     self.token, created = self.token_model.objects.get_or_create(
         user=self.user
     )
     org = Organization(owner=self.user)
     org.save()
     if isinstance(self.request, HttpRequest):
         request = self.request
     else:
         request = self.request._request
     return complete_signup(request, self.user,
                            app_settings.EMAIL_VERIFICATION,
                            self.get_success_url())
コード例 #36
0
    def form_valid(self, form):
        cd = form.cleaned_data
        # data = {}

        # # inv = Invite.objects.get(email=cd.get('email'))
        # data['password'] = cd.get('password')

        # user = AccountAdapter.save_client_user(AccountAdapter, self.request, inv, data, True)

        # agent = Agent.objects.get(pk=inv.inviter_id)
        # coa = ClientsOfAgents()
        # coa.agent = agent
        # coa.client = user
        # coa.save()

        return complete_signup(self.request, user,
                               settings.ACCOUNT_EMAIL_VERIFICATION,
                               self.get_success_url())
コード例 #37
0
ファイル: views.py プロジェクト: HackerWithData/BackEnd
 def form_valid(self, form):
     # By assigning the User to a property on the view, we allow subclasses
     # of SignupView to access the newly created User instance
     # print(self.request.POST)
     # self.request.POST['hoome_id'] = generate_random_hoome_id()
     # TODO: there is a better way to add hoome_id
     self.user = form.save(self.request)
     self.user.hoome_id = generate_random_hoome_id()
     self.user.username = self.user.hoome_id
     self.user.save()
     try:
         response = complete_signup(self.request, self.user,
                                    app_settings.EMAIL_VERIFICATION,
                                    self.get_success_url())
         # print(response)
         return response
     except ImmediateHttpResponse as e:
         # print(e.response)
         return e.response
コード例 #38
0
ファイル: views.py プロジェクト: Socialsquare/biosensor
def signup(request):
    form = TeacherSignupForm()
    if request.method == 'POST':
        form = TeacherSignupForm(request.POST)
        if form.is_valid():
            new_user = form.save(request)  # allauth creates a new user
            teacher = Teacher.objects.create(
                    user=new_user,
                    school=form.cleaned_data['school'],
                    subjects=form.cleaned_data['subjects'])
            teacher.save()
            return complete_signup(
                request,
                new_user,
                settings.ACCOUNT_EMAIL_VERIFICATION,
                reverse('account_email_verification_sent')
            )
    context = {
        'form': form
    }
    return render(request, 'teachers/signup.html', context)
コード例 #39
0
ファイル: views.py プロジェクト: yrik/democoder
def auth(request):
    login_form = LoginForm()
    signup_form_user = SignUpUserForm(prefix="user", request=request)

    redirect_url = "/"
    redirect_url = request.GET.get("next", redirect_url)

    if request.method == "POST" and "login_form" in request.POST:
        login_form = LoginForm(request.POST)

        if login_form.is_valid():
            return login_form.login(request, redirect_url=redirect_url)

    if request.method == "POST" and "signup_user_form" in request.POST:
        signup_form_user = SignUpUserForm(request.POST, prefix="user", request=request)

        if signup_form_user.is_valid():
            user = signup_form_user.save(request)
            return complete_signup(request, user, False, redirect_url)

    return render(request, "auth.html", {"login_form": login_form, "signup_form_user": signup_form_user})
コード例 #40
0
ファイル: views.py プロジェクト: kahihia/CraftyCarrot
    def post(self, request):
        serializer = RegisterInputSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        signup_data = dict(serializer.validated_data)
        confirmation_query_args = signup_data.pop('confirmation_query_args',
                                                  {})
        email = signup_data.pop('email')
        signup_data['email'] = signup_data['email2'] = email
        if not settings.SET_PASSWORD_ON_EMAIL_CONFIRMATION:
            password = signup_data.pop('password')
            signup_data['password1'] = signup_data['password2'] = password

        email_verification = allauth_settings.EMAIL_VERIFICATION
        with transaction.atomic(), clear_messages(request):
            form = SignupForm(data=signup_data)
            if settings.SET_PASSWORD_ON_EMAIL_CONFIRMATION:
                form.fields.pop('password1', None)
                form.fields.pop('password2', None)

            form_valid_or_raise(form, {
                'password1': 'password',
                'password2': None,
                'email2': None
            })

            user = form.save(request=request)
            if email_verification != allauth_settings.EmailVerificationMethod.NONE and confirmation_query_args:
                user.extra_confirmation_data[
                    AccountAdapter.
                    CONFIRMATION_QUERY_ARGS] = confirmation_query_args
                user.save()

            response = complete_signup(request,
                                       user,
                                       email_verification,
                                       success_url=None)
            token = handle_login_response(response, user, allow_disabled=True)
            response_serializer = TokenResponseSerializer({'token': token})
            return Response(response_serializer.data)
コード例 #41
0
 def form_valid(self, form):
     # By assigning the User to a property on the view, we allow subclasses
     # of SignupView to access the newly created User instance
     self.user = form.save(self.request)
     try:
         sg = sendgrid.SendGridAPIClient(apikey=settings.SENDGRID_API_KEY)
         from_email = Email("*****@*****.**")
         to_email = Email("*****@*****.**")
         subject = "New user signed up!"
         content = Content(
             "text/plain",
             "http://eshc.herokuapp.com/admin to assign a reference number")
         mail = Mail(from_email, subject, to_email, content)
         response = sg.client.mail.send.post(request_body=mail.get())
         print(response.status_code)
         print(response.body)
         print(response.headers)
         return complete_signup(self.request, self.user,
                                app_settings.EMAIL_VERIFICATION,
                                self.get_success_url())
     except ImmediateHttpResponse as e:
         return e.response
コード例 #42
0
ファイル: views.py プロジェクト: maximzxc/school_project2
def register(request):
    signup_form_user = SignUpUserForm(prefix="user", request=request)

    redirect_url = reverse('note-list', args=[])
    redirect_url = request.GET.get('next') or redirect_url

    if request.method == 'POST' and 'signup_user_form' in request.POST:
        signup_form_user = SignUpUserForm(
            request.POST,
            prefix="user",
            request=request)

        if signup_form_user.is_valid():
            user = signup_form_user.save(request)
            return complete_signup(
                request,
                user,
                EMAIL_VERIFICATION,
                redirect_url)

    return render(request, "register.html", {
        "signup_form_user": signup_form_user,
    })
コード例 #43
0
ファイル: views.py プロジェクト: Socialsquare/biosensor
def signup(request):
    form = StudentSignUpForm()

    if request.method == 'POST':
        form = StudentSignUpForm(request.POST)

        if form.is_valid():
            new_user = form.save(request)
            student = Student.objects.create(
                user=new_user,
                school_class=form.cleaned_data['school_class']
            )
            student.save()
            return complete_signup(
                request,
                new_user,
                settings.ACCOUNT_EMAIL_VERIFICATION,
                reverse('account_email_verification_sent')
            )

    context = {
        'form': form
    }
    return render(request, 'students/signup.html', context)
コード例 #44
0
ファイル: views.py プロジェクト: matheusnhoalves/SG.github.io
    def perform_create(self, serializer):
        user = serializer.save(self.request)

        complete_signup(self.request._request, user, None, None)
        return user
コード例 #45
0
ファイル: helpers.py プロジェクト: m-thielen/django-allauth
def complete_social_signup(request, sociallogin):
    if app_settings.AVATAR_SUPPORT:
        _copy_avatar(request, sociallogin.account.user, sociallogin.account)
    return complete_signup(request, sociallogin.account.user,
                           sociallogin.get_redirect_url())
コード例 #46
0
def complete_social_signup(request, sociallogin):
    return complete_signup(request,
                           sociallogin.user,
                           app_settings.EMAIL_VERIFICATION,
                           sociallogin.get_redirect_url(request),
                           signal_kwargs={'sociallogin': sociallogin})
コード例 #47
0
ファイル: helpers.py プロジェクト: chidg/django-allauth
def complete_social_signup(request, sociallogin):
    return complete_signup(request,
                           sociallogin.user,
                           app_settings.EMAIL_VERIFICATION,
                           sociallogin.get_redirect_url(request),
                           signal_kwargs={'sociallogin': sociallogin})
コード例 #48
0
 def perform_create(self, serializer):
     user = serializer.save(self.request)
     complete_signup(self.request._request, user,
                     allauth_settings.EMAIL_VERIFICATION, None)
     return user
コード例 #49
0
    def signup(self, request, **kwargs):
        self.method_check(request, allowed=['post'])

        data = self.deserialize(request,
                                request.body,
                                format=request.META.get(
                                    'CONTENT_TYPE', 'application/json'))

        try:
            form = SignupForm(data)
            if not form.is_valid():
                return self.create_response(
                    request, {
                        'success': False,
                        'reason': 'form',
                        'error_type': 'dict',
                        'error': form.errors,
                    }, HttpBadRequest)
            user = form.save(request)
            response = complete_signup(request,
                                       user,
                                       app_settings.EMAIL_VERIFICATION,
                                       success_url='/')
            if response.status_code not in [200, 201, 301, 302]:
                return self.create_response(
                    request, {
                        'success':
                        False,
                        'reason':
                        'status',
                        'error_type':
                        'str',
                        'error':
                        'Got bad status code {}'.format(response.status_code),
                    })

            # Set session expiry
            request.session.set_expiry(settings.SESSION_COOKIE_AGE)

            return self.create_response(
                request, {
                    'success': True,
                    'id': user.id,
                    'resource_uri': self.get_resource_uri(user),
                }, HttpCreated)
        except ValidationError as e:
            return self.create_response(
                request, {
                    'success': False,
                    'reason': 'invalid',
                    'error_type': 'list',
                    'error': e.messages,
                }, HttpBadRequest)
        except Exception as e:
            return self.create_response(
                request, {
                    'success': False,
                    'reason': 'exception',
                    'error_type': 'str',
                    'error': '{}'.format(e),
                }, HttpBadRequest)
コード例 #50
0
 def form_valid(self, form):
     self.user = form.save(self.request)
     return complete_signup(self.request, self.user,
                            app_settings.EMAIL_VERIFICATION,
                            self.get_success_url())
コード例 #51
0
ファイル: views.py プロジェクト: rossbernet/django-tutorial
    def perform_create(self, serializer):
        user = serializer.save()
        setup_user_email(self.request, user, [])

        complete_signup(self.request._request, user, 'optional', None)
コード例 #52
0
ファイル: login.py プロジェクト: alonslotky/universal_tutors
 def done(self, form_list, **kwargs):
     user = self.save_tutor(form_list)
     success_url = reverse('edit_tutor_profile')
     return complete_signup(self.request, user, success_url)
コード例 #53
0
ファイル: helpers.py プロジェクト: mattharley/django-allauth
def complete_social_signup(request, user, account):
    success_url = get_login_redirect_url(request)
    if app_settings.AVATAR_SUPPORT:
        _copy_avatar(request, user, account)
    return complete_signup(request, user, success_url)
コード例 #54
0
ファイル: helpers.py プロジェクト: ppp0/openbroadcast
def complete_social_signup(request, user, account):
    success_url = get_login_redirect_url(request)
    if app_settings.AVATAR_SUPPORT:
        _copy_avatar(request, user, account)
    return complete_signup(request, user, success_url)
コード例 #55
0
 def perform_create(self, serializer):
     user = serializer.save()
     self.token = jwt_encode(user)
     complete_signup(self.request._request, user, False, None)
     return user