Given a User object, how can I list all social associations (for creating a disconnect URL)? - django-socialauth

I've inherited a project using Django Social Auth. Given a User object, how can I determine which if any social associations are active?
My goal is simply to build a form letting the user disconnect from any backend:
Your login: XXXX
Macebook: [disconnect]
Tweeter: [disconnect]
I know I need to build the right URL ('disconnect/(backend)/(association_id)'), but I can't figure out how to iterate over the proper list of the User's associations.
For a related question see How can i get a specific provider from Django social-auth in a template?

The example application shows how to do it. Here's a snippet:
{# assuming that social_accounts = user.social_auth.all() #}
{% for social in social_accounts %}
Disconnect {{ social.provider }}
{% endfor %}

Related

How to remove "search" in Request::url()?

I am setting-up a nested resource to manange User's Posts based on this tutorial: https://backpackforlaravel.com/articles/tutorials/nested-resources-in-backpack-crud.
Problem is that the URL generated by the Request::url() in the button adds "search" like so:
See Posts
// outputs the URL
// http://awesome.app/admin/user/search/99/post
Notice the "search" term in the URL. That should be there. So how to properly remove it?
i had the same problem
{{ str_replace('search/','',Request::url().'/'.$entry->getKey()) }}
fixed it for me

How to configure "accept Terms and Conditions" on Keycloak registration page

I use Keycloak 1.7.0-Final. The user must agree with Term and Conditions at registration.
I enabled "Terms and Conditions" in Authentication > Required actions, But nothing is shown on the registration page.
Also, I cannot find where to configure specific Terms and Condition files for each language.
Could you help?
Thank you.
By default existing users cannot have this page. You need to configure "Terms and Conditions" as "Default Action", then this will be applied by default for all new users.
For existing users, you need to put it manually unser "Users" > "Required actions".
Dont forget to customize the terms page under //themes/base/login/terms.ftl
You will see terms and conditions once the user has filled in the registration form and submits registration. You will have to override the terms.ftl (build your own theme) page if you want it customized and add your own messages locale - see Keycloak Docs - Themes ...
Enable terms and conditions
Regularly you must enable "Terms and Conditions" in Authentication > Required Actions as Enabled and Default Action. By default, this will show a dedicated page after the registration form page, using the template terms.ftl.
Using a checkbox for accepting terms and conditions in the registration page
For this purpose you must specify terms and conditions as Enabled, but not a Default Action. Otherwise you will see the dedicated page using terms.ftl. The problem here is that Keycloak has not a way to enable a checkbox to accept the terms and conditions in the registration page.
Nonetheless, doing a little of reverse engineering I found that when you accept the conditions the user will have an attribute called terms_and_conditions:
In order to reproduce this, you just need to create a custom attribute, named terms_and_conditions, with a numeric value, that seems to be the current time (Date.now()). Being that said, you need an HTML like:
<form>
<!-- other inputs -->
<div>
<input
type="checkbox"
id="terms"
name="user.attributes.terms_and_conditions"
value="<generated value, e.g. 1668029792010>" />
<label for="terms">I accept the terms and conditions</label>
</div>
<div>
<button type="submit">Create user</button>
</div>
</form>
This approach should also be valid if you create that user using the API.
i18n
If your are using a checkbox in the registration page, you can use the standard internationalisation strategy: using the messages properties files. It would probably have a link that reference the content of the "terms and conditions" in the current language. To get the lang code to construct the URL use ${locale.currentLanguageTag}.
Show a page for each language
On the other hand, if you want to use the typical Keycloak strategy using terms.ftl, then you must use the same layout as always and the text will change using the internationalisation.
But if the content of the terms and conditions is very long, then it should be better to create pages for each language, e.g. terms-en.ftl, terms-fr.ftl, etc. These ftl files will only contain the content in the corresponding language and they will be loaded using a code like:
<#include "terms-fr.ftl" />
e.g.
<#if (locale.currentLanguageTag!"en") == "en">
<#include "terms-en.ftl" />
<#else>
<#include "terms-es.ftl" />
</#if>
I hope this helps
You can use Keycloakify to create a theme.
Here is the section related to customizing Terms and conditions.

Yii2, Facebook and Twig

I'm trying to build a rather simple site, and my biggest hurdle is getting facebook login working.
I'm trying to use the authclient extension to log in with facebook. I've set everything up according to docs.. but I don't know how to initiate the process of logging in.
I've built a fb connect based on the sdk before and I'd really rather not...
Now my next question, how do I access template functions in twig and plugins through a twig template?
Such as this:
<?= yii\authclient\widgets\AuthChoice::widget([
'baseAuthUrl' => ['site/auth']
]); ?>
I've used cakephp before on a pretty big project, but I'm completely new to yii.
The twig integration isn't really the smoothest yet. You can register a namespace, and then there should be a *_begin and *_end function for twig, i.e.
{{ use('philippfrenzel/yii2masonry/Yii2masonry') }}
{{ yii2masonry_begin({
'clientOptions': {
'columnWidth' : 50,
'itemSelector' : '.item',
}
}) }}
Important is to note the json style of options, and the capitalization of the namespace and twig function.
Hope that helps :)

After update some info, return to specific paginated page - Laravel 4

I have this case:
A page in laravel 4 with paginate (10 items per page), and for instance, if I'm on page 2, I want to edit some item. I click in the item and I go to the specific form to update. After update, i want to redirect the application to the specific paginated page that I was on before, i.e. page 2. I tried to use URL::Previous(); but, if for instance, my validation of the form fire up, the previous page will be the page of the form, and not the paginated page, and then i will be stuck :/
Any ideas?
(Sorry for my english)
Maybe you could store the page number in the session and then use it when you want to redirect.
$url = 'url?page=' . Session::get('page_number');
return Redirect::to($url);
This is probably not the best way to do it but it should work.
add to you form:
{{ Form::hidden('redirects_to', URL::previous()) }}
in controller you can return like this:
return Redirect::to(Input::get('redirects_to'));
note this only apply with larave 4
I use this in my form:
<input type="hidden" name="last_url" value="{{ URL::previous() }}">
I use this in the Controller:
return redirect()->to($request->last_url)->with('success','Post Updated Successfully');

Instagram feed not returning any data

I'm using Instafeed.js for a client's site:
http://instafeedjs.com/
I've included the script, got my access token & userID. I obtained these by scrolling down to the 'Getting images from your User Account' section of the aforementioned page, and clicking the link at bottom: Don't know your user id or token? Click here to get one.
My code:
$(document).ready(function() {
var userFeed = new Instafeed({
get: 'user',
userId: clientsID,
accessToken: 'MY_ACCESS_TOKEN',
template: '<img src="{{image}}" />',
target: 'instafeed',
limit: 6
});
userFeed.run();
});
I've created an empty div with the 'instafeed' id. The div is being populated with 6 empty a tags, each with an empty image tag. I don't have any console errors.
In the instructions on this site, I'm told to
"make sure your token is set to basic authorization, which only allows
GET requests. If you aren't sure what scope your token has, check
under your account page."
On my account page, I have an 'Instafeed.js' application set up, but the only option I have is to revoke access. I cannot edit or see any other options, so I'm not sure if this could be related to the problem.
Any help would be greatly appreciated!
All tokens issues by the API are given the basic scope, unless the scope was specified in the authentication request.
From the Instagram API Docs:
Currently, all apps have basic read access by default. If all you want to do is access data then you do not need to specify a scope (the “basic” scope will be granted automatically).
You can verify which scope the token has by visiting the Manage Applications page. Each application will display what kind of access level it has. A basic permission set should say something like "Access your basic information":
So you shouldn't need to do anything to set the token's permissions, that's all handled when the token is created. If you used the helper link on instafeedjs.com to get that token, then all the permission levels should already be taken care of for you.
In case someone else runs into this issue, my problem was actually a conflict with Shopify's template engine. When I removed the template option everything worked fine, thanks to Steven here who actually responded to my email! This dude is killer.
In Shopify, if you drop the configuration script into a new "asset" labeled instafeed_config.js and then call it with
{{ "instafeed_config.js" | asset_url | script_tag }}
after loading
{{ "instafeed.min.js" | asset_url | script_tag }}
then you are able to use the Template feature.
You can adjust the template section.
Change the following:
img src="{{image}}"
To:
img src="http:{{image}}"