use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class OAuthDispatcherTest method parseUserInfos_google.
@Test
public void parseUserInfos_google() throws IOException {
URL jsonUrl = OAuthDispatcherTest.class.getResource("me_google.json");
String body = IOUtils.toString(jsonUrl, "UTF-8");
OAuthUser infos = new Google2Provider().parseInfos(body);
Assert.assertNotNull(infos);
Assert.assertEquals("101991806793974537467", infos.getId());
Assert.assertEquals("John", infos.getFirstName());
Assert.assertEquals("Smith", infos.getLastName());
Assert.assertEquals("fr", infos.getLang());
}
use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class OAuthDispatcherTest method oAuthUserInfos_toString.
@Test
public void oAuthUserInfos_toString() throws JSONException {
OAuthUser infos = new OAuthUser();
infos.setId("mySecretId");
infos.setEmail("mySecretEmail@openolat.com");
String toString = infos.toString();
Assert.assertTrue(toString.contains("mySecretId"));
Assert.assertTrue(toString.contains("mySecretEmail@openolat.com"));
}
use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class OAuthDispatcherTest method oAuthUserInfos_toString_NULL.
@Test
public void oAuthUserInfos_toString_NULL() throws JSONException {
OAuthUser infos = new OAuthUser();
String toString = infos.toString();
Assert.assertNotNull(toString);
}
use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class OAuthDispatcherTest method parseUserInfos_twitter.
@Test
public void parseUserInfos_twitter() throws IOException {
URL jsonUrl = OAuthDispatcherTest.class.getResource("verify_credentials.json");
String body = IOUtils.toString(jsonUrl, "UTF-8");
OAuthUser infos = new TwitterProvider().parseInfos(body);
Assert.assertNotNull(infos);
Assert.assertEquals("38895958", infos.getId());
Assert.assertEquals("Sean", infos.getFirstName());
Assert.assertEquals("Cook", infos.getLastName());
Assert.assertEquals("en", infos.getLang());
}
use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class OAuthRegistrationController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
OAuthUser oauthUser = registration.getOauthUser();
usernameEl = uifactory.addTextElement("username", "user.login", 128, "", formLayout);
usernameEl.setMandatory(true);
if (StringHelper.containsNonWhitespace(oauthUser.getId())) {
usernameEl.setValue(oauthUser.getId());
}
// Add all available user fields to this form
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
propFormItems.put(userPropertyHandler.getName(), fi);
if (fi instanceof TextElement) {
String value = oauthUser.getProperty(userPropertyHandler.getName());
if (StringHelper.containsNonWhitespace(value)) {
((TextElement) fi).setValue(value);
}
}
}
}
uifactory.addSpacerElement("lang", formLayout, true);
// second the user language
Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
langEl = uifactory.addDropdownSingleselect("user.language", formLayout, langKeys, langValues, null);
FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
uifactory.addFormSubmitButton("save", buttonLayout);
}
Aggregations