use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class WatchListStore method createWatchListObject.
/**
* Creates a WatchList XWiki Object in the user's profile's page.
*
* @param user XWiki User
* @param context Context of the request
* @return the watchlist object that has been created
* @throws XWikiException if the document cannot be saved
*/
public BaseObject createWatchListObject(String user, XWikiContext context) throws XWikiException {
XWikiDocument userDocument = context.getWiki().getDocument(user, context);
int nb = userDocument.createNewObject(WATCHLIST_CLASS, context);
BaseObject wObj = userDocument.getObject(WATCHLIST_CLASS, nb);
context.getWiki().saveDocument(userDocument, context.getMessageTool().get("watchlist.create.object"), true, context);
return wObj;
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class XWiki method getObjectFromRequest.
// This functions adds an object from an new object creation form
public BaseObject getObjectFromRequest(String className, XWikiContext context) throws XWikiException {
Map<String, String[]> map = Util.getObject(context.getRequest(), className);
BaseClass bclass = context.getWiki().getClass(className, context);
BaseObject newobject = (BaseObject) bclass.fromMap(map, context);
return newobject;
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class XWiki method addUserToGroup.
protected void addUserToGroup(String userName, String groupName, XWikiContext context) throws XWikiException {
XWikiDocument groupDoc = getDocument(groupName, context);
DocumentReference groupClassReference = getGroupClass(context).getDocumentReference();
BaseObject memberObject = groupDoc.newXObject(groupClassReference.removeParent(groupClassReference.getWikiReference()), context);
memberObject.setStringValue("member", userName);
this.saveDocument(groupDoc, localizePlainOrKey("core.comment.addedUserToGroup"), context);
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class XWiki method getServerURL.
public URL getServerURL(String database, XWikiContext context) throws MalformedURLException {
String serverurl = null;
// In virtual wiki path mode the server is the standard one
if ("1".equals(getConfiguration().getProperty("xwiki.virtual.usepath", "1"))) {
return null;
}
if (database != null) {
String db = context.getWikiId();
try {
context.setWikiId(getDatabase());
XWikiDocument doc = getDocument("XWiki.XWikiServer" + StringUtils.capitalize(database), context);
BaseObject serverobject = doc.getXObject(VIRTUAL_WIKI_DEFINITION_CLASS_REFERENCE);
if (serverobject != null) {
String server = serverobject.getStringValue("server");
if (server != null) {
String protocol = getConfiguration().getProperty("xwiki.url.protocol", null);
if (protocol == null) {
int iSecure = serverobject.getIntValue("secure", -1);
// Check the request object if the "secure" property is undefined.
boolean secure = iSecure == 1 || (iSecure < 0 && context.getRequest().isSecure());
protocol = secure ? "https" : "http";
}
long port = context.getURL().getPort();
if (port == 80 || port == 443) {
port = -1;
}
if (port != -1) {
serverurl = protocol + "://" + server + ":" + port + "/";
} else {
serverurl = protocol + "://" + server + "/";
}
}
}
} catch (Exception ex) {
} finally {
context.setWikiId(db);
}
}
if (serverurl != null) {
return new URL(serverurl);
} else {
return null;
}
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class XWiki method validateUser.
public int validateUser(boolean withConfirmEmail, XWikiContext context) throws XWikiException {
try {
XWikiRequest request = context.getRequest();
// Get the user document
String username = convertUsername(request.getParameter("xwikiname"), context);
if (username.indexOf('.') == -1) {
username = "XWiki." + username;
}
XWikiDocument userDocument = getDocument(username, context);
// Get the stored validation key
BaseObject userObject = userDocument.getObject("XWiki.XWikiUsers", 0);
String storedKey = userObject.getStringValue("validkey");
// Get the validation key from the URL
String validationKey = request.getParameter("validkey");
PropertyInterface validationKeyClass = getClass("XWiki.XWikiUsers", context).get("validkey");
if (validationKeyClass instanceof PasswordClass) {
validationKey = ((PasswordClass) validationKeyClass).getEquivalentPassword(storedKey, validationKey);
}
// Compare the two keys
if ((!storedKey.equals("") && (storedKey.equals(validationKey)))) {
userObject.setIntValue("active", 1);
saveDocument(userDocument, context);
if (withConfirmEmail) {
String email = userObject.getStringValue("email");
String password = userObject.getStringValue("password");
sendValidationEmail(username, password, email, request.getParameter("validkey"), "confirmation_email_content", context);
}
return 0;
} else {
return -1;
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_VALIDATE_USER, "Exception while validating user", e, null);
}
}
Aggregations