Commit 6c73ed51 authored by George Kalampokis's avatar George Kalampokis
Browse files

Fixed issue when trying to retrieve non-existing user during e-mail...

Fixed issue when trying to retrieve non-existing user during e-mail confirmation and when the e-mail is confirmed it will show proper message on the frontend (ref #233)
parent 8b1d285f
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -36,7 +36,11 @@ public class EmailConfirmation {
			return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
		} catch
		(HasConfirmedEmailException | TokenExpiredException ex) {
			if (ex instanceof  TokenExpiredException) {
				return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
			} else {
				return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
			}
		}
	}

@@ -48,6 +52,9 @@ public class EmailConfirmation {
			this.emailConfirmationManager.sendConfirmationEmail(email, principal);
			return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
		} catch (Exception ex) {
			if (ex instanceof HasConfirmedEmailException) {
				return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
			}
			return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
		}
	}
+6 −5
Original line number Diff line number Diff line
@@ -34,20 +34,21 @@ public class EmailConfirmationManager {
				.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
				.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();

		if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
			throw new TokenExpiredException("Token has expired.");

		UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
				.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();

		if (user.getEmail() != null)
			throw new HasConfirmedEmailException("User already has confirmed his Email.");

		if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
			throw new TokenExpiredException("Token has expired.");

		loginConfirmationEmail.setIsConfirmed(true);

		// Checks if mail is used by another user. If it is, merges the new the old.
		Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
		if (existingUsers > 0) {
			UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
		if (oldUser != null) {
			mergeNewUserToOld(user, oldUser);
			expireUserToken(user);
			databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
+5 −0
Original line number Diff line number Diff line
@@ -62,7 +62,12 @@ export class EmailConfirmation extends BaseComponent implements OnInit {
	}

	onCallbackError(error: any) {
		if (error.status === 302) {
			this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'), SnackBarNotificationLevel.Warning);
			this.router.navigate(['home']);
		} else {
		this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'), SnackBarNotificationLevel.Error);
		this.router.navigate(['login']);
		}
	}
}
+2 −1
Original line number Diff line number Diff line
@@ -146,7 +146,8 @@
		"REQUEST-EMAIL-HEADER": "We are almost done! Please fill your e-mail.",
		"REQUEST-EMAIL-TEXT": "You will need to confirm it to use the application.",
		"SUBMIT": "Submit",
		"SENT-EMAIL-HEADER": "Email was send!"
		"SENT-EMAIL-HEADER": "Email was send!",
		"EMAIL-FOUND": "Email is already confirmed"
	},
	"HOME": {
		"DMPS": "DMPs",