How to always display google recaptcha in english language? - asp.net-mvc

I am using latest google recaptcha in my ASP.Net MVC project. By default, it takes up the language set in the browser.
However, I want it to be displayed always in english.
Here is what I have tried so far:
My Script for onload:
var onloadCallback = function () {
// Renders the HTML element with id 'example1' as a reCAPTCHA widget.
// The id of the reCAPTCHA widget is assigned to 'widgetId1'.
//widgetId1 = grecaptcha.render(document.getElementById('g-recaptcha'), {
// 'sitekey': '6Lc2Zf8SAAAAAOC9_6L7k5mCnxGao7vCv5_1KxrL'
//});
grecaptcha.render('g-recaptcha', {
'sitekey': '6LdRfv8SAAAAAOagkckxW72cHAQKrvNGLasbU6G2',
'callback': verifyCallback,
'theme': 'dark',
'lang': 'en'
});
};
Can we force recaptcha to be always displayed in a certain language?

I finally got the answer.
In the link to include the Google recaptcha, you can pass your language in form of query string:
<script src="https://www.google.com/recaptcha/api.js?hl=fr&onload=onloadCallback&render=explicit" async defer></script>

Related

Insert a liferay portlet into PrimeFaces dialog

I'm using liferay 6.1, jsf 2 and primeface 4.0. I've two different project running on a liferay tomcat. I want to insert a portlet of "Project 1" into primefaces dialog of "project 2".
I tried by using ui:insert, but it takes the source path of current project. How to proceed in this scenario?
with ui:insert, you can insert html code, not a whole portlet!
So you should either:
Create a common xhtml page that could be visible from both portlets. This would require that you have both portlets in the same plugin project
In the dialog, instead of inserting code, you can include a link to another page of your portal, where a "project2" portlet is placed
I'm managed to fixed that issue.
Liferay provides a generate URL functionality of each portlet. So I created a URL for target portlet.
then pass that url to liferay pop up.
Here is my code :
<script type="text/javascript" charset="utf-8">
var url;
function createRenderURL() {
AUI().ready('liferay-portlet-url', function(A) {
var renderURL = Liferay.PortletURL.createRenderURL();
renderURL.setName("Banner");
renderURL .setPortletMode("view");
renderURL .setWindowState("pop_up");
renderURL.setPortletId("addUser_WAR_UserManagementportlet");
url = renderURL.toString();
showPopup(url);
});
}
function showPopup(url){
console.log("En el showPopup ");
AUI().ready('aui-dialog', 'aui-io', function(A) {
alert(url);
window.myDialog = new A.Dialog({
title: 'Banner',
width: 640,
centered: true
}).plug(A.Plugin.IO, {
uri: url
}).render();
});
}
Hope it will help to another. Thanks.

How to get OAuth working on MVC4 mobile

I have been struggling to get OAuth to work on my MVC4 mobile application.
I basically
Created an MVC4 Mobile application
Created an MVC4 Web application
Copied the AccountController, AccountModel, InitializeSimpleMembershipAttribute and all account views into my MVC4 Mobile application
Enabled Google and Facebook OAuth providers
I also ensured RoleManager was initialized according to simplemembershipprovider-not-working, although I do not think that was important. ( I needed it for some role-based security I was testing)
Disabled ajax ( I think) by setting data-ajax="false":
using (Html.BeginForm("ExternalLogin", "Account",new RouteValueDictionary { { "ReturnUrl", ViewBag.ReturnUrl } }, FormMethod.Post, new Dictionary<string, object> { { "data-ajax", false } })) (This did not seem to have any effect on the page - so I may be doing something wrong here...)
I can get to the LogIn view /Account/Login, and when I click the google button, the debugger breaks into public ActionResult ExternalLogin(string provider, string returnUrl)
However - the public ActionResult ExternalLoginCallback(string returnUrl) is never hit.
Visually, I get the jquery mobile "page loading" animation - then I get "Error Loading Page"
I have two questions:
How can I get more information when I try to figure out what happens?
How can I get OAuth working on my MVC4 mobile site?
BTW: Both sites target .Net4.0
OK - so I figured out the answer - the cuplrit was indeed the ajax in jQuery mobile.
I modified my _layout.cshtml so that it can render a custom script after loading jQuery, but before loading jQuery mobile:
#Scripts.Render("~/bundles/jquery","~/scripts/RemoveHashFromWindowLocation")
#RenderSection("beforeJqueryMobile", required: false);
#Scripts.Render( "~/bundles/jquerymobile")
#RenderSection("scripts", required: false)
Then I modified my Login.cshtml so that it contains the section:
#section BeforeJqueryMobile {
#Scripts.Render("~/scripts/disable-ajax.js")
}
And finally, I added the following to my scripts folder:
disable-ajax.js:
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
RemoveHashFromWindowLocation.js: (Thanks to Facebook Oauth Login With Jquery Mobile #_=_)
if (window.location.hash == "#_=_")
window.location.hash = "";
Voila - OAuth working with jQuery mobile. :-)
The above answer from espenalb does work if your site loads directly to the login page, however if you have say a home page and then and a link to the login page(which uses the same layout), you will get an error loading page when you click one of the social login buttons.
To fix this add
<script>
$('#login-link').live("click", function () {
$.mobile.ajaxEnabled = false;
});
</script>
to the bottom of your mobile layout page, this will attach an event handler that will disable ajax to the login link.

jquery mobile page refresh

I want to refresh a page without using data-ajax="false" in anchor tag and i want to show the loading spinner while linking the pages in jquerymobile.pls help me.
reloadPage (boolean, default: false)
Forces a reload of a page, even if it is already in the DOM of the
page container. Used only when the 'to' argument of changePage() is a
URL.
Source: http://jquerymobile.com/demos/1.1.0-rc.1/docs/api/methods.html
So basically you can use $.mobile.changePage() to change pages and you can pass it the preloadPage : true option when you want to reload a URL.
Here is a quick example of how to use $.mobile.changePage() for links that have the reload class:
$(document).delegate('a.reload', 'click', function () {
$.mobile.changePage('myPage.html', { reloadPage : true });
return false;
});
The default loader in jquery mobile appears while linking to pages, by adding the following code:
$("a").click(function() {
$.mobile.showPageLoadingMsg();
//Other things you want to do
});

How to fix regional settings for jQuery datepicker so it works in Firefox and IE7?

I am using jQuery' s datepicker and asp.net MVC4. The datepicker works in Firefox but in IE7 i get the message through the asp.net's validation that the field is not a date.
This is the code for the datepicker
if (!Modernizr.inputtypes.date) {
$(function() {
$.datepicker.setDefaults($.datepicker.regional['en-GB']);
$(".datefield").datepicker();
});
}
This is my globalization setting in Web.config
<globalization uiCulture="en-GB" culture="en-GB" />
E.g. in Firefox the date is shown as "19/03/2012" string and accepted by the asp.net's validation setup (client and server side). In IE7 the same date string is not accepted on the client. If i change it to "03/19/2012" the client accepts the date but then the server throws an exception - "InvalidOperationException. Nullable object must have a value."
My viewModel uses a null-able DateTime that i cast to a non null-able DateTime in the controllers post action. This works in Firefox but in IE7 the value for the date from the viewModel is null. What is the problem?
The following line does nothing:
$.datepicker.setDefaults($.datepicker.regional['en-GB']);
if you don't include the corresponding language file which is not included by default in the ASP.NET MVC 4 template.
You may try setting the format explicitly:
$.datepicker.setDefaults({ dateFormat: 'dd/mm/yy' });
But this only concerns how the date should be formatted after selecting it in the datepicker. It has nothing to do with validation.
The client side validation is performed by the jquery.validate plugin which in turn uses either the browser currently configured culture (which might explain the discrepancies you are observing between FF and IE, for example one might be configured to use en-GB and the other en-US) or ISO dates.
You could override this custom validation and make it use your custom format to ensure that this will work cross browser:
if (!Modernizr.inputtypes.date) {
$(function () {
$.datepicker.setDefaults({ dateFormat: 'dd/mm/yy' });
$('.datefield').datepicker();
});
jQuery.validator.addMethod(
'date',
function (value, element, params) {
if (this.optional(element)) {
return true;
};
var result = false;
try {
$.datepicker.parseDate('dd/mm/yy', value);
result = true;
} catch (err) {
result = false;
}
return result;
},
''
);
}
Jquery localization files are available at :
http://nuget.org/packages/jQuery.UI.i18n
simply run :
Install-Package jQuery.UI.i18n and add a script reference to "Scripts/jquery-ui-i18n.js"
from package manager console, then this will work:
$.datepicker.setDefaults($.datepicker.regional['en-GB']);

using SignalR with document onload instead of jquery onload

I have used the signalR chat app (as laid out in this tutorial http://sergiotapia.com/2011/09/signalr-with-mvc3-chat-app-build-asynchronous-real-time-persistant-connection-websites/) in a standalone test site and it all works great.
I'm now trying to incorporate it into my larger project.
Now unfortunately my larger project has a body onload function defined, so i don't use the standard jquery $(function () {}); syntax for executing stuff on page load. This hasn't been too much of an issue so far, most jquery plugins and scripts get executed in the function called by my body onload and its fine.
But for some reason, my signalR code just isn't executing.
Its the exact same code as laid out above, only its called on my body load.
The page loads, does a post to /signalr/negotiate (which returns the url and clientID)
In my sample app which works, it then does a continuous post to /signalr/connect
In my other app, it simply does a single get to the page im currently on.
Its not making the post to connect.
Is there a way to manually call this?
Here is the source of the page not working.
Please note that the reason im not referencing JQuery itself is because its loaded in my master page. JQuery is present.
<script src="/public/javascript/jquery.signalR.min.js">
<script src="/public/javascript/json2.js">
<script type="text/javascript" src="/signalr/hubs">
<div>
<input type="text" id="msg" />
<input type="button" id="broadcast" />
<ul id="messages"></ul>
</div>
<script type="text/javascript">
function ExecuteOnLoad() {
// Proxy created on the fly
var chat = $.connection.chat;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
$("#broadcast").click(function () {
// Call the chat method on the server
chat.send($('#msg').val());
});
// Start the connection
$.connection.hub.start();
}
</script>
EDIT : here is the chat hub
public class Chat : SignalR.Hubs.Hub
{
public void Send(string message)
{
//Call the addMessage method on all clients.
Clients.addMessage(message);
}
}
DOUBLE EDIT : ok, i've made a standard html page in my mvc project and wired up the onload event again and everything works fine. the problem seems to be that polling doesn't seem to working when i call
$.connection.hub.start();
instead its doing a get to the current url and returning the page again in the get request.
The problem had nothing to do with the question I asked.
I thought it might have to do with the onload function, but it did not.
The problem was because my page had a reference to the Jquery.Validate plugin.
The version I was using was 1.7, I updated to 1.9 of the plugin and it worked fine.

Resources