use of org.vcell.util.document.UserInfo in project vcell by virtualcell.
the class NewUserRestlet method handle.
@Override
public void handle(Request request, Response response) {
if (request.getMethod().equals(Method.POST)) {
Representation entity = request.getEntity();
if (entity.getMediaType().equals(MediaType.APPLICATION_JSON)) {
handleJsonRequest(request, response);
return;
}
String content = request.getEntityAsText();
System.out.println(content);
Form form = new Form(entity);
String userid = form.getFirstValue(VCellApiApplication.NEWUSERID_FORMNAME, "");
String password1 = form.getFirstValue(VCellApiApplication.NEWPASSWORD1_FORMNAME, "");
String password2 = form.getFirstValue(VCellApiApplication.NEWPASSWORD2_FORMNAME, "");
String email = form.getFirstValue(VCellApiApplication.NEWEMAIL_FORMNAME, "");
String firstName = form.getFirstValue(VCellApiApplication.NEWFIRSTNAME_FORMNAME, "");
String lastName = form.getFirstValue(VCellApiApplication.NEWLASTNAME_FORMNAME, "");
String institute = form.getFirstValue(VCellApiApplication.NEWINSTITUTE_FORMNAME, "");
String country = form.getFirstValue(VCellApiApplication.NEWCOUNTRY_FORMNAME, "");
String notify = form.getFirstValue(VCellApiApplication.NEWNOTIFY_FORMNAME, "on");
String formprocessing = form.getFirstValue(VCellApiApplication.NEWFORMPROCESSING_FORMNAME, null);
Status status = null;
String errorMessage = "";
// validate
if (!password1.equals(password2)) {
status = Status.CLIENT_ERROR_FORBIDDEN;
errorMessage = "passwords dont match";
}
int MIN_PASSWORD_LENGTH = 5;
if (password1.length() < MIN_PASSWORD_LENGTH || password1.contains(" ") || password1.contains("'") || password1.contains("\"") || password1.contains(",")) {
status = Status.CLIENT_ERROR_FORBIDDEN;
errorMessage = "password must be at least " + MIN_PASSWORD_LENGTH + " characters, and must not contains spaces, commas, or quotes";
}
if (email.length() < 4) {
status = Status.CLIENT_ERROR_FORBIDDEN;
errorMessage = "valid email required";
}
if (userid.length() < 4 || !userid.equals(org.vcell.util.TokenMangler.fixTokenStrict(userid))) {
status = Status.CLIENT_ERROR_FORBIDDEN;
errorMessage = "userid must be at least 4 characters and contain only alpha-numeric characters";
}
if (errorMessage.length() > 0 && formprocessing != null) {
Form newform = new Form();
newform.add(VCellApiApplication.NEWERRORMESSAGE_FORMNAME, errorMessage);
newform.add(VCellApiApplication.NEWUSERID_FORMNAME, userid);
newform.add(VCellApiApplication.NEWPASSWORD1_FORMNAME, password1);
newform.add(VCellApiApplication.NEWPASSWORD2_FORMNAME, password2);
newform.add(VCellApiApplication.NEWEMAIL_FORMNAME, email);
newform.add(VCellApiApplication.NEWFIRSTNAME_FORMNAME, firstName);
newform.add(VCellApiApplication.NEWLASTNAME_FORMNAME, lastName);
newform.add(VCellApiApplication.NEWINSTITUTE_FORMNAME, institute);
newform.add(VCellApiApplication.NEWCOUNTRY_FORMNAME, country);
newform.add(VCellApiApplication.NEWNOTIFY_FORMNAME, notify);
Reference redirectRef;
try {
redirectRef = new Reference(request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.REGISTRATIONFORM + "?" + newform.encode());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
response.redirectSeeOther(redirectRef);
return;
}
// form new UnverifiedUserInfo
UserInfo newUserInfo = new UserInfo();
newUserInfo.company = institute;
newUserInfo.country = country;
newUserInfo.digestedPassword0 = new DigestedPassword(password1);
newUserInfo.email = email;
newUserInfo.wholeName = firstName + " " + lastName;
newUserInfo.notify = notify.equals("on");
newUserInfo.title = " ";
newUserInfo.userid = userid;
Date submitDate = new Date();
// one hour
long timeExpiresMS = 1000 * 60 * 60 * 1;
Date expirationDate = new Date(System.currentTimeMillis() + timeExpiresMS);
DigestedPassword emailVerifyToken = new DigestedPassword(Long.toString(System.currentTimeMillis()));
UnverifiedUser unverifiedUser = new UnverifiedUser(newUserInfo, submitDate, expirationDate, emailVerifyToken.getString());
// add Unverified UserInfo and send email
VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
vcellApiApplication.getUserVerifier().addUnverifiedUser(unverifiedUser);
try {
// Send new password to user
PropertyLoader.loadProperties();
BeanUtils.sendSMTP(PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPHostName), new Integer(PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPPort)).intValue(), PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPEmailAddress), newUserInfo.email, "new VCell account verification", "You have received this email to verify that a Virtual Cell account has been associated " + "with this email address. To activate this account, please follow this link: " + request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.NEWUSER_VERIFY + "?" + VCellApiApplication.EMAILVERIFYTOKEN_FORMNAME + "=" + emailVerifyToken.getString());
} catch (Exception e) {
e.printStackTrace();
response.setStatus(Status.SERVER_ERROR_INTERNAL);
response.setEntity("we failed to send a verification email to " + newUserInfo.email, MediaType.TEXT_PLAIN);
}
response.setStatus(Status.SUCCESS_CREATED);
response.setEntity("we sent you a verification email at " + newUserInfo.email + ", please follow the link in that email", MediaType.TEXT_PLAIN);
}
}
use of org.vcell.util.document.UserInfo in project vcell by virtualcell.
the class ChangeEmail method unsubscribe.
private void unsubscribe() {
try {
LabelBuilder lb = new LabelBuilder();
for (UserInfo ui : userInfos) {
ui.notify = false;
dbDriver.updateUserInfo(getConnection(), ui);
lb.append(ui.userid + " notify off");
}
setStatus(true, lb.toString());
} catch (SQLException e) {
setStatus(e);
}
}
use of org.vcell.util.document.UserInfo in project vcell by virtualcell.
the class ChangeEmail method update.
private void update() {
try {
String n = newEmailField.getText();
LabelBuilder lb = new LabelBuilder();
for (UserInfo ui : userInfos) {
ui.email = n;
dbDriver.updateUserInfo(getConnection(), ui);
lb.append("set " + ui.userid + " email to " + n);
}
setStatus(true, lb.toString());
} catch (SQLException e) {
setStatus(e);
}
}
use of org.vcell.util.document.UserInfo in project vcell by virtualcell.
the class ChangeEmail method lookup.
private void lookup() {
try {
newEmailField.setText("");
String email = emailField.getText().toLowerCase();
Matcher m = regex.matcher(email);
if (m.matches()) {
email = m.group(1);
}
List<User> users = dbDriver.getUserFromEmail(getConnection(), email);
userInfos.clear();
if (users.size() > 0) {
LabelBuilder lb = new LabelBuilder();
for (User u : users) {
UserInfo ui = dbDriver.getUserInfo(dbConn, u.getID());
userInfos.add(ui);
lb.append(ui.toString());
}
userInfo.setText(lb.toString());
setStatus(true, "found " + users.size() + " users for " + email);
} else {
setStatus(true, "email " + email + " not found");
}
} catch (SQLException | DataAccessException e) {
setStatus(e);
}
setDynamic();
}
use of org.vcell.util.document.UserInfo in project vcell by virtualcell.
the class FunctionFileCrawler method scanAllUsers.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
*/
private void scanAllUsers() throws SQLException, DataAccessException, java.rmi.RemoteException {
File[] userDirs = dataRootDir.listFiles();
if (lg.isTraceEnabled())
lg.trace("Total user directories: " + userDirs.length);
UserInfo[] userInfos = adminDbServer.getUserInfos();
File userDir = null;
File outputDir = getOutputDirectory();
for (int i = 0; i < userDirs.length; i++) {
try {
userDir = userDirs[i];
if (lg.isTraceEnabled())
lg.trace("----------------------------------------------------------");
if (lg.isTraceEnabled())
lg.trace("USER: " + userDir.getName());
User user = null;
for (int j = 0; j < userInfos.length; j++) {
if (userDir.getName().equals(userInfos[j].userid)) {
user = new User(userInfos[j].userid, userInfos[j].id);
break;
}
}
if (user == null) {
if (lg.isWarnEnabled())
lg.warn("User " + user + " doesn't exit!!");
continue;
}
if (!userDir.exists() || !userDir.isDirectory()) {
if (lg.isWarnEnabled())
lg.warn("UserDir " + userDir + " doesn't exist or is not a directory");
continue;
}
// find all the user simulations
scan(userDir, outputDir);
if (lg.isTraceEnabled())
lg.trace(" Total NUM of files modified : " + totalNumOfFilesModified);
if (lg.isTraceEnabled())
lg.trace("----------------------------------------------------------");
} catch (Exception ex) {
lg.error(ex.getMessage(), ex);
}
if (lg.isTraceEnabled())
lg.trace(" Total NUM of files modified : " + totalNumOfFilesModified);
}
}
Aggregations