use of org.olat.registration.RegistrationManager in project OpenOLAT by OpenOLAT.
the class RegistrationWebService method register.
/**
* Register with the specified email
* @response.representation.200.doc Registration successful
* @response.representation.304.doc Already registered, HTTP-Header location set to redirect
* @response.representation.400.doc Email address not allowed
* @param email The email address
* @param request The HTTP Request
* @return
*/
@PUT
public Response register(@QueryParam("email") String email, @Context HttpServletRequest request) {
if (!CoreSpringFactory.getImpl(RegistrationModule.class).isSelfRegistrationEnabled()) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ResponseBuilder response;
Locale locale = getLocale(request);
Translator translator = getTranslator(locale);
MailManager mailM = CoreSpringFactory.getImpl(MailManager.class);
UserManager userManager = UserManager.getInstance();
RegistrationManager rm = CoreSpringFactory.getImpl(RegistrationManager.class);
boolean foundUser = userManager.findUniqueIdentityByEmail(email) != null;
boolean noNewUserWithEmail = !userManager.isEmailAllowed(email);
String serverpath = Settings.getServerContextPathURI();
if (foundUser && noNewUserWithEmail) {
// redirect
URI redirectUri = UriBuilder.fromUri(Settings.getServerContextPathURI()).build();
response = Response.ok().status(Status.NOT_MODIFIED).location(redirectUri);
} else if (userManager.isEmailAllowed(email)) {
String ip = request.getRemoteAddr();
TemporaryKey tk = null;
UserModule userModule = CoreSpringFactory.getImpl(UserModule.class);
if (userModule.isEmailUnique()) {
tk = rm.loadTemporaryKeyByEmail(email);
}
if (tk == null) {
tk = rm.loadOrCreateTemporaryKeyByEmail(email, ip, RegistrationManager.REGISTRATION);
}
String today = DateFormat.getDateInstance(DateFormat.LONG, locale).format(new Date());
String[] bodyAttrs = new String[] { serverpath, tk.getRegistrationKey(), CoreSpringFactory.getImpl(I18nModule.class).getLocaleKey(locale) };
String[] whereFromAttrs = new String[] { serverpath, today, ip };
String body = translator.translate("reg.body", bodyAttrs) + SEPARATOR + translator.translate("reg.wherefrom", whereFromAttrs);
try {
MailBundle bundle = new MailBundle();
bundle.setTo(email);
bundle.setContent(translator.translate("reg.subject"), body);
MailerResult result = mailM.sendExternMessage(bundle, null, true);
if (result.isSuccessful()) {
response = Response.ok();
} else {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
log.error("", e);
}
} else {
response = Response.serverError().status(Status.BAD_REQUEST);
}
return response.build();
}
use of org.olat.registration.RegistrationManager in project openolat by klemens.
the class ChangePasswordWebService method register.
/**
* @param identityKey
* @param request
* @return
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response register(@QueryParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
if (!isUserManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
Identity identity = securityManager.loadIdentityByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CoreSpringFactory.getImpl(UserModule.class).isPwdChangeAllowed(identity)) {
return Response.serverError().status(Status.FORBIDDEN).build();
}
RegistrationManager rm = CoreSpringFactory.getImpl(RegistrationManager.class);
String emailAdress = identity.getUser().getProperty(UserConstants.EMAIL, null);
String ip = request.getRemoteAddr();
TemporaryKey tk = rm.createAndDeleteOldTemporaryKey(identity.getKey(), emailAdress, ip, RegistrationManager.PW_CHANGE);
return Response.ok(new TemporaryKeyVO(tk)).build();
}
use of org.olat.registration.RegistrationManager in project openolat by klemens.
the class RegistrationWebService method register.
/**
* Register with the specified email
* @response.representation.200.doc Registration successful
* @response.representation.304.doc Already registered, HTTP-Header location set to redirect
* @response.representation.400.doc Email address not allowed
* @param email The email address
* @param request The HTTP Request
* @return
*/
@PUT
public Response register(@QueryParam("email") String email, @Context HttpServletRequest request) {
if (!CoreSpringFactory.getImpl(RegistrationModule.class).isSelfRegistrationEnabled()) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ResponseBuilder response;
Locale locale = getLocale(request);
Translator translator = getTranslator(locale);
MailManager mailM = CoreSpringFactory.getImpl(MailManager.class);
UserManager userManager = UserManager.getInstance();
RegistrationManager rm = CoreSpringFactory.getImpl(RegistrationManager.class);
boolean foundUser = userManager.findUniqueIdentityByEmail(email) != null;
boolean noNewUserWithEmail = !userManager.isEmailAllowed(email);
String serverpath = Settings.getServerContextPathURI();
if (foundUser && noNewUserWithEmail) {
// redirect
URI redirectUri = UriBuilder.fromUri(Settings.getServerContextPathURI()).build();
response = Response.ok().status(Status.NOT_MODIFIED).location(redirectUri);
} else if (userManager.isEmailAllowed(email)) {
String ip = request.getRemoteAddr();
TemporaryKey tk = null;
UserModule userModule = CoreSpringFactory.getImpl(UserModule.class);
if (userModule.isEmailUnique()) {
tk = rm.loadTemporaryKeyByEmail(email);
}
if (tk == null) {
tk = rm.loadOrCreateTemporaryKeyByEmail(email, ip, RegistrationManager.REGISTRATION);
}
String today = DateFormat.getDateInstance(DateFormat.LONG, locale).format(new Date());
String[] bodyAttrs = new String[] { serverpath, tk.getRegistrationKey(), CoreSpringFactory.getImpl(I18nModule.class).getLocaleKey(locale) };
String[] whereFromAttrs = new String[] { serverpath, today, ip };
String body = translator.translate("reg.body", bodyAttrs) + SEPARATOR + translator.translate("reg.wherefrom", whereFromAttrs);
try {
MailBundle bundle = new MailBundle();
bundle.setTo(email);
bundle.setContent(translator.translate("reg.subject"), body);
MailerResult result = mailM.sendExternMessage(bundle, null, true);
if (result.isSuccessful()) {
response = Response.ok();
} else {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
log.error("", e);
}
} else {
response = Response.serverError().status(Status.BAD_REQUEST);
}
return response.build();
}
use of org.olat.registration.RegistrationManager in project OpenOLAT by OpenOLAT.
the class ChangePasswordWebService method register.
/**
* @param identityKey
* @param request
* @return
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response register(@QueryParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
if (!isUserManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
Identity identity = securityManager.loadIdentityByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CoreSpringFactory.getImpl(UserModule.class).isPwdChangeAllowed(identity)) {
return Response.serverError().status(Status.FORBIDDEN).build();
}
RegistrationManager rm = CoreSpringFactory.getImpl(RegistrationManager.class);
String emailAdress = identity.getUser().getProperty(UserConstants.EMAIL, null);
String ip = request.getRemoteAddr();
TemporaryKey tk = rm.createAndDeleteOldTemporaryKey(identity.getKey(), emailAdress, ip, RegistrationManager.PW_CHANGE);
return Response.ok(new TemporaryKeyVO(tk)).build();
}
Aggregations