use of org.javlo.user.IUserInfo in project javlo by Javlo.
the class UserInfoLink method prepareView.
@Override
public void prepareView(ContentContext ctx) throws Exception {
StringWriter writer = new StringWriter();
PrintWriter out = new PrintWriter(writer);
GlobalContext globalContext = GlobalContext.getInstance(ctx.getRequest());
List<String> selectedUser = getUserIds();
IUserFactory userFact = AdminUserFactory.createUserFactory(globalContext, ctx.getRequest().getSession());
List<IUserInfo> users = userFact.getUserInfoList();
List<IUserInfo> finalUsers = new LinkedList<IUserInfo>();
for (IUserInfo user : users) {
String userName = user.getLogin();
out.println("<span class=\"line-inline\">");
String checked = "";
String inputName = getId(userName);
if (selectedUser.contains(user.getLogin())) {
finalUsers.add(user);
}
out.println("<input type=\"checkbox\" name=\"" + inputName + "\" id=\"" + getId(userName) + "\"" + checked + " />");
out.println("<label for=\"" + getId(userName) + "\">" + userName + "</label>");
out.println("</span>");
}
ctx.getRequest().setAttribute("users", finalUsers);
out.close();
}
use of org.javlo.user.IUserInfo in project javlo by Javlo.
the class UserLogin method performRegister.
public static String performRegister(RequestService rs, ContentContext ctx, HttpSession session, MessageRepository messageRepository, I18nAccess i18nAccess) throws Exception {
String login;
String email;
UserLogin comp = (UserLogin) ComponentHelper.getComponentFromRequest(ctx);
if (ctx.getGlobalContext().getSpecialConfig().isCreateAccountWithToken()) {
String token = rs.getParameter("createToken");
if (token == null) {
return "no token";
} else {
login = ctx.getGlobalContext().getEmailFromToken(token);
if (login == null) {
return i18nAccess.getText("user.message.password-bad-token");
}
email = login;
}
} else {
login = rs.getParameter("login", rs.getParameter("email", "").trim()).trim();
email = rs.getParameter("email", null);
if (!StringHelper.isEmpty(comp.getFieldValue(UserLogin.VALIDATION)) && !StringHelper.isTrue(rs.getParameter("valid"))) {
return i18nAccess.getViewText("registration.error.check", "Please check : ") + '"' + comp.getFieldValue(UserLogin.VALIDATION) + '"';
}
}
IUserFactory userFactory = UserFactory.createUserFactory(ctx.getGlobalContext(), session);
String password = rs.getParameter("password", "").trim();
String password2 = rs.getParameter("passwordbis", "").trim();
ctx.getRequest().setAttribute("userInfoMap", new RequestParameterMap(ctx.getRequest()));
if (email != null && !PatternHelper.MAIL_PATTERN.matcher(email).matches()) {
return i18nAccess.getViewText("registration.error.email", "Please enter a valid email.");
} else if (userFactory.getUser(login) != null) {
return i18nAccess.getViewText("registration.error.login_allreadyexist", "user already exists.");
}
if (userFactory.getUserByEmail(email) != null) {
return i18nAccess.getViewText("registration.error.email_alreadyexist", "email already exists.");
} else if (!password.equals(password2)) {
return i18nAccess.getViewText("registration.error.password_notsame", "2 passwords must be the same.");
} else if (password.length() < 3) {
return i18nAccess.getViewText("registration.error.password_size", "password must be at least 3 characters.");
} else if (StringHelper.isEmpty(login)) {
return i18nAccess.getViewText("registration.error.need-login", "please fill login field");
}
IUserInfo userInfo = userFactory.createUserInfos();
userInfo.setLogin(login);
userInfo.setSite(ctx.getGlobalContext().getContextKey());
if (email != null) {
userInfo.setEmail(email);
} else {
if (PatternHelper.MAIL_PATTERN.matcher(login).matches()) {
userInfo.setEmail(login);
}
}
userInfo.setPassword(SecurityHelper.encryptPassword(password));
userInfo.setRoles(StringHelper.stringToSet(comp.getFieldValue(ROLES)));
userFactory.addUserInfo(userInfo);
userFactory.store();
userInfo = userFactory.login(ctx.getRequest(), login, password).getUserInfo();
if (StringHelper.isMail(comp.getFieldValue(EMAIL))) {
String subject = i18nAccess.getText("user.mail.create.subjet") + ctx.getGlobalContext().getGlobalTitle();
Map data = new HashMap();
data.put("email", login);
if (!StringHelper.isEmpty(userInfo.getFirstName())) {
data.put(i18nAccess.getText("user.firstname"), userInfo.getFirstName());
}
if (!StringHelper.isEmpty(userInfo.getLastName())) {
data.put(i18nAccess.getText("user.lastanme"), userInfo.getLastName());
}
if (!StringHelper.isEmpty(comp.getFieldValue(ROLES))) {
data.put("roles", comp.getFieldValue(ROLES));
}
Map<String, String> params = new HashMap<String, String>();
params.put("webaction1", "changemode");
params.put("webaction2", "edit");
params.put("module", "users");
params.put("mode", "view");
params.put("cuser", userInfo.getEncryptLogin());
ContentContext absCtx = ctx.getContextForAbsoluteURL();
absCtx.setRenderMode(ContentContext.EDIT_MODE);
String adminMailContent = XHTMLHelper.createAdminMail(subject, null, data, URLHelper.createURL(absCtx, params), "go on page >>", null);
MailService mailService = MailService.getInstance(new MailConfig(ctx.getGlobalContext(), ctx.getGlobalContext().getStaticConfig(), null));
InternetAddress fromEmail = new InternetAddress(ctx.getGlobalContext().getAdministratorEmail());
InternetAddress toEmail = new InternetAddress(comp.getFieldValue(EMAIL));
mailService.sendMail(null, fromEmail, toEmail, null, null, subject, adminMailContent, true, null, ctx.getGlobalContext().getDKIMBean());
}
if (!StringHelper.isEmpty(comp.getFieldValue(MSG))) {
messageRepository.setGlobalMessage(new GenericMessage(comp.getFieldValue(MSG), GenericMessage.INFO));
}
return null;
}
use of org.javlo.user.IUserInfo in project javlo by Javlo.
the class UserLogin method performUpdate.
public static String performUpdate(RequestService rs, GlobalContext globalContext, ContentContext ctx, HttpSession session, MessageRepository messageRepository, I18nAccess i18nAccess) throws Exception {
IUserFactory userFactory;
userFactory = UserFactory.createUserFactory(globalContext, ctx.getRequest().getSession());
User user = ctx.getCurrentUser();
IUserInfo userInfo = user.getUserInfo();
String email = rs.getParameter("email", "");
if (!userInfo.getLogin().equals(email)) {
if (userFactory.getUser(email) != null) {
return i18nAccess.getViewText("registration.error.login_allreadyexist", "user already exists : ") + email;
} else {
user.setLogin(email);
userInfo.setLogin(email);
}
}
Set<String> newRoles = userInfo.getRoles();
if (!StringHelper.isEmpty(getFieldName(OPTIN))) {
if (rs.getParameter("optin") != null) {
newRoles.add(getFieldName(OPTIN));
} else {
newRoles.remove(getFieldName(OPTIN));
}
}
if (!StringHelper.isEmpty(getFieldName(OPTOUT))) {
if (rs.getParameter("optout") != null) {
newRoles.add(getFieldName(OPTOUT));
} else {
newRoles.remove(getFieldName(OPTOUT));
}
}
for (FileItem fileItem : rs.getAllFileItem()) {
if (StringHelper.isImage(fileItem.getName())) {
File image = new File(URLHelper.mergePath(globalContext.getUserFolder(ctx.getCurrentUser()), fileItem.getName()));
if (!image.exists()) {
image.getParentFile().mkdirs();
image.createNewFile();
InputStream in = null;
try {
in = fileItem.getInputStream();
ResourceHelper.writeStreamToFile(in, image);
} finally {
ResourceHelper.closeResource(in);
}
}
}
}
userInfo.setRoles(newRoles);
/* save password */
String pwd = userInfo.getPassword();
IContentVisualComponent comp = ComponentHelper.getComponentFromRequest(ctx);
if (comp == null) {
return "component not found.";
}
List<String> fields = comp.extractFieldsFromRenderer(ctx);
if (fields != null && fields.size() > 0) {
Map<String, String> allValues = new HashMap<String, String>();
for (String field : fields) {
allValues.put(field, StringHelper.neverNull(rs.getParameter(field)));
BeanHelper.copy(allValues, userInfo, false);
}
} else {
BeanHelper.copy(new RequestParameterMap(ctx.getRequest()), userInfo, false);
}
/* restore password */
userInfo.setPassword(pwd);
userFactory.updateUserInfo(userInfo);
user.setUserInfo(userInfo);
messageRepository.setGlobalMessage(new GenericMessage(i18nAccess.getViewText("registration.message.update", "User info is updated."), GenericMessage.INFO));
return null;
}
use of org.javlo.user.IUserInfo in project javlo by Javlo.
the class UserRegistration method performResetPasswordWithEmail.
public static String performResetPasswordWithEmail(RequestService rs, GlobalContext globalContext, ContentContext ctx, MessageRepository messageRepository, I18nAccess i18nAccess) throws AddressException {
UserFactory userFactory = (UserFactory) UserFactory.createUserFactory(globalContext, ctx.getRequest().getSession());
String email = rs.getParameter("email", "").trim();
String passwordRetrieveKey = null;
if (StringHelper.isMail(email)) {
for (IUserInfo user : userFactory.getUserInfoList()) {
if (user.getEmail().equals(email)) {
passwordRetrieveKey = userFactory.createPasswordChangeKey(user);
Map<String, String> params = new HashMap<String, String>();
params.put("pwkey", passwordRetrieveKey);
String url = URLHelper.createURL(ctx.getContextForAbsoluteURL(), params);
String subject = i18nAccess.getViewText("user.mail.reset-password-subject");
InternetAddress from = new InternetAddress(globalContext.getAdministratorEmail());
InternetAddress to = new InternetAddress(email);
NetHelper.sendMail(globalContext, from, to, null, null, subject + ' ' + globalContext.getGlobalTitle(), url);
messageRepository.setGlobalMessage(new GenericMessage(i18nAccess.getViewText("user.message.change-password-link"), GenericMessage.INFO));
return null;
}
}
return i18nAccess.getViewText("user.message.error.change-mail-not-found");
} else {
return i18nAccess.getViewText("form.error.email");
}
}
use of org.javlo.user.IUserInfo in project javlo by Javlo.
the class ConvertUserForComansys method perform.
@Override
public String perform(ContentContext ctx, Map<String, Object> params) throws Exception {
String fileName = "users_to_comansys.xlsx";
File exportedFile = new File(URLHelper.mergePath(ctx.getGlobalContext().getStaticFolder(), EXPORT_FOLDER, fileName));
// response.setContentType(ResourceHelper.getFileExtensionToMineType(StringHelper.getFileExtension(fileName)));
// response.setHeader("Cache-Control", "no-cache");
// response.setHeader("Accept-Ranges", "bytes");
// response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
IUserFactory uf = UserFactory.createUserFactory(ctx.getGlobalContext(), ctx.getRequest().getSession());
List<IUserInfo> users = uf.getUserInfoList();
Cell[][] arrays = XLSTools.createArray(29, users.size() + 1);
int i = 0;
arrays[0][i].setValue("Title");
i++;
arrays[0][i].setValue("Job title (Job Position)");
i++;
int gender = i;
arrays[0][i].setValue("Gender");
i++;
int lastname = i;
arrays[0][i].setValue("Lastname (*)");
i++;
int firstname = i;
arrays[0][i].setValue("Firstname (*)");
i++;
arrays[0][i].setValue("Category of contact (*)");
i++;
arrays[0][i].setValue("Sector of activity (*)");
i++;
arrays[0][i].setValue("Preferred Language");
i++;
arrays[0][i].setValue("Address (Street)");
i++;
arrays[0][i].setValue("Post code (Zip)");
i++;
arrays[0][i].setValue("City (EN)");
i++;
arrays[0][i].setValue("City (OR)");
i++;
arrays[0][i].setValue("State / Region (Local)");
i++;
arrays[0][i].setValue("Country (EN) (*)");
i++;
arrays[0][i].setValue("Country (OR)");
i++;
int email = i;
arrays[0][i].setValue("Email (*)");
i++;
arrays[0][i].setValue("Email 1");
i++;
arrays[0][i].setValue("Email 2");
i++;
arrays[0][i].setValue("Website");
i++;
arrays[0][i].setValue("Phone");
i++;
arrays[0][i].setValue("Private phone");
i++;
arrays[0][i].setValue("Mobile");
i++;
arrays[0][i].setValue("Fax");
i++;
arrays[0][i].setValue("Social media contact");
i++;
arrays[0][i].setValue("Keywords");
i++;
arrays[0][i].setValue("Name of Organisation");
i++;
int tags = i;
arrays[0][i].setValue("Tags");
i++;
int notes = i;
arrays[0][i].setValue("Internal Notes");
i++;
arrays[0][i].setValue("Birthdate");
i++;
int j = 1;
for (IUserInfo user : users) {
arrays[j][gender].setValue(user.getGender());
arrays[j][lastname].setValue(user.getLastName());
arrays[j][firstname].setValue(user.getFirstName());
arrays[j][email].setValue(user.getEmail());
arrays[j][tags].setValue(StringHelper.collectionToString(user.getRoles(), ","));
arrays[j][notes].setValue("Creation date:" + StringHelper.renderDate(user.getCreationDate()));
j++;
}
if (!exportedFile.exists()) {
exportedFile.getParentFile().mkdirs();
exportedFile.createNewFile();
}
FileOutputStream out = new FileOutputStream(exportedFile);
try {
XLSTools.writeXLSX(arrays, out);
} finally {
ResourceHelper.closeResource(out);
}
String resourceURL = URLHelper.createResourceURL(ctx, exportedFile);
NetHelper.sendRedirectTemporarily(ctx.getResponse(), resourceURL);
return null;
}
Aggregations