Example #1
0
    def on_after_save(request, user):
        user.is_active = False
        user.set_password(request.POST['password'])

        # Email verification
        key = randstr(32)
        while User.objects.filter(verification_key=key).exists():
            key = randstr(32)
        user.verification_key = key

        send_mail(
            title=_('Welcome to MootiroMaps'),
            receivers=[user.email],
            message=_('''
Hello, {name}.

Before using our tool, please confirm your e-mail visiting the link below.
{verification_url}

Thanks,
the IT3S team.
''').format(name=user.name, verification_url=request.build_absolute_uri(
                                reverse('user_verification', args=(key,))))
        )

        user.save()
        redirect_url = reverse('user_check_inbox')
        return {'redirect': redirect_url}
Example #2
0
 def deposit(cls, data, expiration_date=None):
     '''
     Store data in a locker and return that locker's key. The locker remains
     until the expiration date or forever if no expiration date is provided.
     '''
     key = randstr(32)
     while Locker.objects.filter(key=key).exists():
         key = randstr(32)
     locker = Locker(key=key, data=data)
     if expiration_date:
         locker.expiration_date = expiration_date
     locker.save()
     return key
Example #3
0
def login_facebook(request):
    """Redirect user to facebook login and authorization page."""
    # Step 1: Getting authorization from the user
    csrf_token = randstr(10)
    redirect_uri = request.build_absolute_uri(reverse("facebook_authorized"))
    params = {
        "client_id": settings.FACEBOOK_APP_ID,  # app id from provider
        "redirect_uri": redirect_uri,  # where the user will be redirected to
        "scope": "email",  # comma separated list of permissions
        "state": csrf_token,  # unique string to prevent CSRF
    }
    request.session["state"] = csrf_token
    request.session["next"] = request.GET.get("next", reverse("root"))
    url = "https://www.facebook.com/dialog/oauth"
    url += "?" + encode_querystring(params)
    return redirect(url)
Example #4
0
def login_facebook(request):
    '''Redirect user to facebook login and authorization page.'''
    # Step 1: Getting authorization from the user
    csrf_token = randstr(10)
    redirect_uri = request.build_absolute_uri(reverse('facebook_authorized'))
    params = {
        'client_id': settings.FACEBOOK_APP_ID,  # app id from provider
        'redirect_uri': redirect_uri,  # where the user will be redirected to
        'scope': 'email',              # comma separated list of permissions
        'state': csrf_token,           # unique string to prevent CSRF
    }
    request.session['state'] = csrf_token
    request.session['next'] = request.GET.get('next', reverse('root'))
    url = 'https://www.facebook.com/dialog/oauth'
    url += '?' + encode_querystring(params)
    return redirect(url)
Example #5
0
def login_google(request):
    """Redirect user to google login and authorization page."""
    # Step 1: Getting authorization from the user
    csrf_token = randstr(10)
    redirect_uri = request.build_absolute_uri(reverse("google_authorized"))
    params = {
        "client_id": settings.GOOGLE_APP_ID,
        "redirect_uri": redirect_uri,  # where the user will be redirected to
        # below a space separated list of permissions
        "scope": "https://www.googleapis.com/auth/userinfo.profile " "https://www.googleapis.com/auth/userinfo.email",
        "state": csrf_token,  # unique string to prevent CSRF
        "response_type": "code",  # 'code' or 'token'
        # depends on the application type.
    }
    request.session["state"] = csrf_token
    request.session["next"] = request.GET.get("next", reverse("root"))
    url = "https://accounts.google.com/o/oauth2/auth"
    url += "?" + encode_querystring(params)
    return redirect(url)
Example #6
0
def login_google(request):
    '''Redirect user to google login and authorization page.'''
    # Step 1: Getting authorization from the user
    csrf_token = randstr(10)
    redirect_uri = request.build_absolute_uri(reverse('google_authorized'))
    params = {
        'client_id': settings.GOOGLE_APP_ID,
        'redirect_uri': redirect_uri,  # where the user will be redirected to
        # below a space separated list of permissions
        'scope': 'https://www.googleapis.com/auth/userinfo.profile '
                 'https://www.googleapis.com/auth/userinfo.email',
        'state': csrf_token,           # unique string to prevent CSRF
        'response_type': 'code',       # 'code' or 'token'
                                       # depends on the application type.
    }
    request.session['state'] = csrf_token
    request.session['next'] = request.GET.get('next', reverse('root'))
    url = 'https://accounts.google.com/o/oauth2/auth'
    url += '?' + encode_querystring(params)
    return redirect(url)