Beispiel #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_task.delay(
            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,))))
        )
        send_explanations_mail(user)

        user.save()
        redirect_url = reverse('user_check_inbox')
        return {'redirect': redirect_url}
    def on_after_save(request, user):
        user.is_active = False
        user.set_password(request.POST['password'])

        user.save()

        user.send_confirmation_mail(request)
        send_explanations_mail(user)

        redirect_url = reverse('user_check_inbox')
        return {'redirect': redirect_url}
Beispiel #3
0
    def on_after_save(request, user):
        user.is_active = False
        user.set_password(request.POST['password'])

        user.save()

        user.send_confirmation_mail(request)
        send_explanations_mail(user)

        redirect_url = reverse('user_check_inbox')
        return {'redirect': redirect_url}
Beispiel #4
0
def google_authorized(request):
    """
    Connect google account information to the current logged user or one with
    same email. If no user is matched, creates a new one.
    """
    csrf_token = request.GET.get("state", None)
    if not csrf_token or csrf_token != request.session["state"]:
        return HttpResponse(status=403)  # csrf attack! get that bastard!

    error = request.GET.get("error", None)
    if error:
        error_description = request.GET.get("error_description", None)
        return dict(login_error="google", error_msg=error_description)

    # Step 2: Exchange the authorization code for an access_token
    redirect_uri = request.build_absolute_uri(reverse("google_authorized"))
    params = {
        "client_id": settings.GOOGLE_APP_ID,
        "client_secret": settings.GOOGLE_APP_SECRET,
        "code": request.GET.get("code"),  # code to exchange access_token
        "redirect_uri": redirect_uri,  # must be the same as in step 1
        "grant_type": "authorization_code",  # just to fulfill the OAuth2 spec
    }
    url = "https://accounts.google.com/o/oauth2/token"
    resp = requests.post(url, data=params)  # google requires POST, not GET
    access_data = simplejson.loads(resp.text)
    access_token = access_data["access_token"]

    # Step 3: Accessing the API
    params = {
        # 'scope': 'https://www.googleapis.com/auth/userinfo.email',
        "access_token": access_data["access_token"]
    }
    url = "https://www.googleapis.com/oauth2/v1/userinfo/"
    url += "?" + encode_querystring(params)
    data = simplejson.loads(requests.get(url).text)

    if request.user.is_authenticated():
        # if a user is already logged, then just connect social auth account
        credential, created = SocialAuth.objects.get_or_create(email=data["email"], provider=PROVIDERS["google"])
        if created:
            credential.user = request.user
        else:
            # merge users information
            pass
    else:
        user, created = get_or_create_user_by_credentials(data["email"], PROVIDERS["google"], access_data=access_data)
        if created:
            user.name = data["name"]
            user.save()
            send_explanations_mail(user)
        auth_login(request, user)

    return redirect(request.session["next"] or reverse("root"))
Beispiel #5
0
def facebook_authorized(request):
    '''
    Connect facebook account information to the current logged user or one with
    same email. If no user is matched, creates a new one.
    '''
    csrf_token = request.GET.get('state', None)
    if not csrf_token or csrf_token != request.session['state']:
        return HttpResponse(status=403)  # csrf attack! get that bastard!

    error = request.GET.get('error', None)
    if error:
        error_description = request.GET.get('error_description', None)
        return dict(login_error='facebook', error_msg=error_description)

    # Step 2: Exchange the authorization code for an access_token
    redirect_uri = request.build_absolute_uri(reverse('facebook_authorized'))
    params = {
        'client_id': settings.FACEBOOK_APP_ID,
        'client_secret': settings.FACEBOOK_APP_SECRET,
        'code': request.GET.get('code'),  # code to exchange for access_token
        'redirect_uri': redirect_uri,     # must be the same as in step1
    }
    url = 'https://graph.facebook.com/oauth/access_token'
    url += '?' + encode_querystring(params)
    access_data = decode_querystring(requests.get(url).text)

    # Step 3: Accessing the API
    params = {
        'fields': 'email,name',
        'access_token': access_data['access_token'],
    }
    url = 'https://graph.facebook.com/me'
    url += '?' + encode_querystring(params)
    data = simplejson.loads(requests.get(url).text)

    if request.user.is_authenticated():
        # if a user is already logged, then just connect social auth account
        credential, created = SocialAuth.objects.get_or_create(
            email=data['email'], provider=PROVIDERS['facebook'])
        if created:
            credential.user = request.user
        else:
            # merge users information
            pass
    else:
        user, created = get_or_create_user_by_credentials(data['email'],
                            PROVIDERS['facebook'], access_data=access_data)
        if created:
            user.name = data['name']
            user.save()
            send_explanations_mail(user)
        auth_login(request, user)

    return redirect(request.session['next'] or reverse('root'))
Beispiel #6
0
 def on_after_save(request, project):
     send_explanations_mail(project.creator, 'project')
     # Add the project creator as contributor
     project.contributors.add(project.creator)
     return {'redirect': project.view_url}
def test_email(request):
    user = request.user
    user.send_confirmation_mail(request)
    send_explanations_mail(user)
    return {'testing': '...'}
Beispiel #8
0
 def on_after_save(request, project):
     send_explanations_mail(project.creator, 'project')
     # Add the project creator as contributor
     project.contributors.add(project.creator)
     versionate(request.user, project)
     return {'redirect': project.view_url}