Exemplo n.º 1
0
def fb_register_user(request):
    from film20.account.views import get_next, new_user_registered_redirect
    from film20.account.forms import SSORegistrationForm
    reg_data = request.session.get('facebook_reg_data')
    if not reg_data:
        return HttpResponse("No reg data", status=400)
    user_details = reg_data['user_details']
    access_token = reg_data['access_token']

    fb_user = FBUser.create_or_update(user_details)
    user_details['avatar_url'] = fb_user.picture_url('large')

    uid = user_details['uid']
    next = get_next(request)
    if request.POST:
        form = SSORegistrationForm(request.POST, request=request)
        if form.is_valid():
            user = form.save()
            assoc = FBAssociation(user=user,
                                  fb_uid=uid,
                                  is_new=True,
                                  is_from_facebook=True,
                                  access_token=access_token)
            assoc.save()
            try:
                Avatar.create_from_url(user, user_details['avatar_url'])
            except Exception, e:
                logger.debug(e)
            user = authenticate(fb_uid=uid)
            login(request, user)
            return new_user_registered_redirect(request, next)
Exemplo n.º 2
0
def oauth_new_user(request, name):
    from film20.utils.utils import direct_to_template

    logger.info("registering new %s user", name)
    
    reg_data = request.session.get('oauth_reg_data')
    access_token = reg_data['access_token']
    user_info = reg_data['user_info']
    next = reg_data['next'] or '/'
    service = OAuthService.get_by_name(name)
    
    if request.POST:
        form = SSORegistrationForm(request.POST, request=request)
        if form.is_valid():
            user = form.save()
            service.set_access_token(user, access_token, user_info['user_id'])
            try:
                Avatar.create_from_url(user, user_info['avatar_url'])
            except Exception, e:
                logger.warning(e)
            user = authenticate(service=service, user_id=user_info['user_id'])
            if user:
                auth_login_and_stats(request, user)
                logger.info("%s user (%s) authenticated and logged in, redirecting to %r", name, user, next)
                return new_user_registered_redirect(request, next)
            logger.error("Can't login to new created user %s" % user)
            assert False, "Can't login to new created user %s" % user
        else:
            logger.warning("invalid sso form: %s", form.errors)
Exemplo n.º 3
0
def fb_register_user(request):
    from film20.account.views import get_next, new_user_registered_redirect
    from film20.account.forms import SSORegistrationForm
    reg_data = request.session.get('facebook_reg_data')
    if not reg_data:
        return HttpResponse("No reg data", status=400)
    user_details = reg_data['user_details']
    access_token = reg_data['access_token']

    fb_user = FBUser.create_or_update(user_details)
    user_details['avatar_url'] = fb_user.picture_url('large')
    
    uid = user_details['uid']
    next = get_next(request)
    if request.POST:
        form = SSORegistrationForm(request.POST, request=request)
        if form.is_valid():
            user = form.save()
            assoc = FBAssociation(user=user, fb_uid=uid, is_new=True, is_from_facebook=True, access_token=access_token)
            assoc.save()
            try:
                Avatar.create_from_url(user, user_details['avatar_url'])
            except Exception, e:
                logger.debug(e)
            user = authenticate(fb_uid=uid)
            login(request, user)
            return new_user_registered_redirect(request, next)
Exemplo n.º 4
0
def fb_register_user(request, details):
    from film20.account.views import get_next, new_user_registered_redirect
    from film20.account.forms import SSORegistrationForm
    user_details = pickle.loads(base64.decodestring(details))
    uid = user_details['uid']
    next = get_next(request)
    if request.POST:
        form = SSORegistrationForm(request.POST, request=request)
        if form.is_valid():
            user = form.save()
            assoc = FBAssociation(user=user, fb_uid=uid, is_new=True, is_from_facebook=True)
            assoc.save()
            try:
                Avatar.create_from_url(user, user_details['avatar_url'])
            except Exception, e:
                logger.debug(e)
            user = authenticate(user_id=user.id, fb_uid=uid)
            login(request, user)
            return new_user_registered_redirect(request, next)
Exemplo n.º 5
0
def edit_avatar(request):
    profile = request.user.get_profile()
    if request.method == "POST":
        form = AvatarForm(request.POST, request.FILES)
        if form.is_valid():
            image = form.cleaned_data.get('photo') or form.cleaned_data.get(
                'url')
            avatar = Avatar(user=request.user, image=image, valid=False)
            avatar.image.save("%s.jpg" % request.user.username, image)
            image = Image.open(avatar.image.path)
            image.thumbnail((480, 480), Image.ANTIALIAS)
            image.convert("RGB").save(avatar.image.path, "JPEG")
            avatar.save()

            return HttpResponseRedirect(reverse('crop_avatar'))
    else:
        form = AvatarForm()

    ctx = dict(form=form, )

    return render(request, "usersettings/edit_avatar.html", ctx)
Exemplo n.º 6
0
def edit_avatar(request):
    profile = request.user.get_profile()
    if request.method == "POST":
        form = AvatarForm(request.POST, request.FILES)
        if form.is_valid():
            image = form.cleaned_data.get( 'photo' ) or form.cleaned_data.get( 'url' )
            avatar = Avatar( user=request.user, image=image, valid=False )
            avatar.image.save( "%s.jpg" % request.user.username, image )
            image = Image.open( avatar.image.path )
            image.thumbnail( ( 480, 480 ), Image.ANTIALIAS )
            image.convert( "RGB" ).save( avatar.image.path, "JPEG" )
            avatar.save()
            
            return HttpResponseRedirect( reverse( 'crop_avatar' ) )
    else:
        form = AvatarForm()


    ctx = dict(
        form=form,
    )

    return render( request, "usersettings/edit_avatar.html", ctx )