本文整理汇总了Java中org.hibernate.validator.constraints.Email类的典型用法代码示例。如果您正苦于以下问题:Java Email类的具体用法?Java Email怎么用?Java Email使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Email类属于org.hibernate.validator.constraints包,在下文中一共展示了Email类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMailWithUsername
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Async
@Override
public void sendMailWithUsername(
@NotBlank @Email final String email,
@NotBlank final String username
) {
log.info("Called with e-mail {}, username {}", email, username);
try {
final JavaMailSenderImpl sender = new JavaMailSenderImpl();
final MimeMessage message = sender.createMimeMessage();
final MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo(email);
helper.setSubject("Recover username");
helper.setText("Your username: " + "<b>" + username + "</b>", true);
sendMail(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
示例2: sendMailWithNewPassword
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Async
@Override
public void sendMailWithNewPassword(
@NotBlank @Email final String email,
@NotBlank final String newPassword
) {
log.info("Called with e-mail {}, newPassword {}", email, newPassword);
try {
final JavaMailSenderImpl sender = new JavaMailSenderImpl();
final MimeMessage message = sender.createMimeMessage();
final MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo(email);
helper.setSubject("Recover password");
helper.setText("Your new password: " + "<b>" + newPassword + "</b>", true);
sendMail(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
示例3: create
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* Creates a new organisation. The email address and password of one Account are used
* to connect it with this organisation. So the email address and password are mandatory for
* authentication otherwise a warning with the hint for wrong credentials is returned.
* All further Accounts which should be associated to this organisation are added with the
* method addManager.
* In the response the account's password isn't returned because of security reasons.
*
* @param name
* The name of the developer or the manager of the account.
* @param email
* The required valid email address.
* @param password
* Required header parameter associated with the email address.
* @return A Response of Organisation in JSON.
*/
@POST
@Path("/")
@TypeHint(Organisation.class)
public Response create(@QueryParam("name") String name, @QueryParam("email") @NotNull @Email String email,
@HeaderParam("password") @NotNull String password) {
LOGGER.debug("create organisation requested");
String encryptedPassword = SecurityTools.encryptWithSHA512(password);
if (!accountDao.checkCredentials(email, encryptedPassword)) {
throw new CredentialException(email);
}
Organisation organisation = new Organisation(name);
organisation.addManager(accountDao.getAccount(email, encryptedPassword));
organisation.setApiKey(SecurityTools.generateApiKey());
LOGGER.debug("Organisation created");
organisationDao.insertOrganisation(organisation);
return ResponseSurrogate.created(organisation);
}
示例4: get
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* Returns a specific organisation which id is equal to the transfered path parameter.
* Additionally the email address and the associated password are mandatory and have to be
* correct otherwise an exception is returned that the given credentials are wrong.
* In the response the account's password isn't returned because of security reasons.
*
* @param id
* The path parameter of the organisation, that should be returned.
* @param email
* The valid email address.
* @param password
* Required header parameter to connect it with the given
* email address.
* @return A response of Organisation in JSON.
*/
@GET
@Path("/{id}")
@TypeHint(Organisation.class)
public Response get(@PathParam("id") @NotNull String id, @QueryParam("email") @NotNull @Email String email,
@HeaderParam("password") @NotNull String password) {
LOGGER.debug("get organisation requested");
if (!accountDao.checkCredentials(email, SecurityTools.encryptWithSHA512(password))) {
throw new CredentialException(email);
}
int intId = Integer.parseInt(id);
Organisation organisation = organisationDao.getOrganisation(intId);
return ResponseSurrogate.of(organisation);
}
示例5: generateApiKey
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* Generates an API key for the given organisation which matches the id, email address and the
* associated password. Otherwise an exception is returned that the given credentials are wrong.
* If the API key field is already set the method resets it and replaced it with the new generated
* API key.
* In the response the account's password isn't returned because of security reasons.
*
* @param id
* The path parameter of the organisation, for which the API key should be generated.
* @param email
* The valid email address.
* @param password
* Required header parameter to connect it with the given email address.
* @return A Response of Organisation in JSON.
*/
@PUT
@Path("/{id}/generateapikey")
@TypeHint(Organisation.class)
public Response generateApiKey(@PathParam("id") @NotNull String id, @QueryParam("email") @Email String email,
@HeaderParam("password") @NotNull String password) {
Notification notification = new Notification();
LOGGER.debug("generate api key requested");
if (!accountDao.checkCredentials(email, SecurityTools.encryptWithSHA512(password))) {
throw new CredentialException(email);
}
int intId = Integer.parseInt(id);
Organisation organisation = organisationDao.getOrganisation(intId);
organisation.setApiKey(SecurityTools.generateApiKey());
return ResponseSurrogate.updated(organisation, notification);
}
示例6: create
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* Creates a new account. For this an unique email address and a
* password are mandatory. By the creation of an organisation this
* email address is connected with it. Optionally the first and last
* name can also be set.
* In the response the password isn't returned because of security
* reasons.
*
* @param email
* A required valid email address.
* @param password
* Required query parameter to connect it with the given
* email address.
* @param firstName
* Optionally the first name of the Account's owner can be set.
* @param lastName
* Optionally the last name of the Account's owner can be set.
* @return A Response of Account in JSON.
*/
@POST
@Path("/")
@TypeHint(Account.class)
public Response create(@QueryParam("email") @NotNull @Email String email, @QueryParam("password") @NotNull String password,
@QueryParam("firstName") String firstName, @QueryParam("lastName") String lastName) {
LOGGER.debug("create account requested");
if(accountDao.getAccount(email)!=null){
throw new ApiError(Response.Status.FORBIDDEN, "This mail address is already used.");
}
Account account = new Account(email);
account.setPassword(SecurityTools.encryptWithSHA512(password));
account.setFirstName(firstName);
account.setLastName(lastName);
accountDao.persist(account);
LOGGER.debug("Persisted account: %s", account);
return ResponseSurrogate.created(account);
}
示例7: get
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* Returns an account corresponding to the given email address but only
* if the combination with password is correct. By the creation of an
* organisation this email address is connected with it.
* So the method requires valid credentials otherwise a warning with the
* hint for wrong credentials is returned.
* In the response the password isn't returned because of security
* reasons.
*
* @param email
* A required valid unique email address.
* @param password
* Required header parameter associated with the email address.
* @return A Response of Account in JSON.
*/
@GET
@Path("/")
@TypeHint(Account.class)
public Response get(@QueryParam("email") @NotNull @Email String email, @HeaderParam("password") @NotNull String password) {
LOGGER.debug("get account requested");
String encryptedPassword = SecurityTools.encryptWithSHA512(password);
if (!accountDao.checkCredentials(email, encryptedPassword)) {
LOGGER.warn("Account with wrong credentials (email:\"%s\", pass:\"%s\") requested", email, password);
throw new CredentialException(email);
}
Account account = accountDao.getAccount(email, encryptedPassword);
LOGGER.debug("Account requested: %s", account);
return ResponseSurrogate.of(account);
}
示例8: update
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* Updates the first and last name of an existing account. For this the
* specific email address and associated password are mandatory.
* Otherwise a warning with the hint for wrong credentials is returned.
* In the response the password isn't returned because of security
* reasons.
*
* @param email
* A required valid email address.
* @param password
* Required header parameter to connect it with the given
* email address.
* @param firstName
* Optionally the first name of the Account's owner can be set.
* @param lastName
* Optionally the last name of the Account's owner can be set.
*
* @return A Response of Account in JSON.
*/
@PUT
@Path("/")
@TypeHint(Account.class)
public Response update(@QueryParam("email") @NotNull @Email String email, @HeaderParam("password") @NotNull String password,
@QueryParam("firstName") String firstName, @QueryParam("lastName") String lastName) {
LOGGER.debug("update account requested");
String encryptedPassword = SecurityTools.encryptWithSHA512(password);
if (!accountDao.checkCredentials(email, encryptedPassword)) {
LOGGER.warn("Account with wrong credentials (email:\"%s\", pass:\"%s\") requested", email, password);
throw new CredentialException(email);
}
Account account = accountDao.getAccount(email, encryptedPassword);
Optional.ofNullable(encryptedPassword).ifPresent(account::setPassword);
Optional.ofNullable(firstName).ifPresent(account::setFirstName);
Optional.ofNullable(lastName).ifPresent(account::setLastName);
accountDao.persist(account);
LOGGER.debug("Updated account: %s", account);
return ResponseSurrogate.updated(account);
}
示例9: testEmail
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
@Test
public void testEmail() {
Set<ConstraintViolation<ObjectWithValidation>> violations = validator.validate(obj, Email.class);
assertNotNull(violations);
assertEquals(violations.size(), 1);
if (runPeformance) {
long time = System.currentTimeMillis();
for (int index = 0; index < 10000; index++) {
validator.validate(obj, Email.class);
}
long used = System.currentTimeMillis() - time;
System.out.println("Hibernate Validator [Email] check used " + used + "ms, avg. " + ((double) used) / 10000
+ "ms.");
}
}
示例10: getType
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
@Override
protected String getType() {
String type = javaToHtmlTypes.get(valueType);
if (type != null) {
return type;
}
type = "text";
if (annotations != null) {
if (annotations.containsKey(Email.class)) {
type = "email";
} else if (annotations.containsKey(URL.class)) {
type = "url";
} else if (annotations.containsKey(Max.class) || annotations.containsKey(Min.class)) {
type = "number";
}
}
return type;
}
示例11: getUserByEmail
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public User getUserByEmail(
@NotBlank @Email final String email
) throws ResourceNotFoundException {
log.info("Called with email {}", email);
return this.userRepository.findByEmailIgnoreCaseAndEnabledTrue(email)
.map(ServiceUtils::toUserDto)
.orElseThrow(() -> new ResourceNotFoundException("No user found with e-mail " + email));
}
示例12: existsUserByEmail
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean existsUserByEmail(
@NotBlank @Email final String email
) {
log.info("Called with email {}", email);
return this.userRepository.existsByEmailIgnoreCase(email);
}
示例13: sendMailWithActivationToken
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Async
@Override
public void sendMailWithActivationToken(
@NotBlank @Email final String email,
@NotBlank final String token
) {
log.info("Called with e-mail {}, token {}", email, token);
try {
final JavaMailSenderImpl sender = new JavaMailSenderImpl();
final MimeMessage message = sender.createMimeMessage();
final MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo(email);
helper.setSubject("Complete registration");
helper.setText("To activation your account, click the link below:<br />"
+ "<a href='" + "https://localhost:8443" + "/register/thanks?token=" + token + "'>" +
"Click here to complete your registration" +
"</a>", true);
sendMail(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
示例14: sendMailWithEmailChangeToken
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Async
@Override
public void sendMailWithEmailChangeToken(
@NotBlank @Email final String email,
@NotBlank final String token
) {
log.info("Called with e-mail {}, token {}", email, token);
try {
final JavaMailSenderImpl sender = new JavaMailSenderImpl();
final MimeMessage message = sender.createMimeMessage();
final MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo(email);
helper.setSubject("Change e-mail");
helper.setText("Change e-mail address, click the link below:<br />"
+ "<a href='" + "https://localhost:8443" + "/settings/changeEmail/thanks?token=" + token + "'>" +
"Click here to complete the change of your e-mail" +
"</a>", true);
sendMail(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
示例15: testEmail
import org.hibernate.validator.constraints.Email; //导入依赖的package包/类
@Test
public void testEmail() {
AssertAnnotations.assertField( User.class, "email", Column.class, Email.class);
Column c = ReflectTool.getFieldAnnotation(User.class, "email", Column.class);
assertEquals("column email: name is not equal", "email", c.name());
assertEquals("column email: unique is false", true, c.unique());
assertEquals("column email: nullable is true", false, c.nullable());
}