use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class Action method authenticateAndGetNominalUser.
protected AccountAttributes authenticateAndGetNominalUser(UserType loggedInUserType) {
String paramRequestedUserId = request.getParameter(Const.ParamsNames.USER_ID);
AccountAttributes account = null;
if (isMasqueradeModeRequested(loggedInUser, paramRequestedUserId)) {
if (loggedInUserType.isAdmin) {
// Allowing admin to masquerade as another user
account = logic.getAccount(paramRequestedUserId);
if (account == null) {
// Unregistered user
if (regkey == null) {
// since admin is masquerading, fabricate a regkey
regkey = "any-non-null-value";
}
account = AccountAttributes.builder().withGoogleId(paramRequestedUserId).build();
}
return account;
}
throw new UnauthorizedAccessException("User " + loggedInUserType.id + " is trying to masquerade as " + paramRequestedUserId + " without admin permission.");
}
account = loggedInUser;
if (isPersistenceIssue() && isHomePage()) {
// let the user go through as this is a persistence issue
} else if (doesUserNeedRegistration(account) && !loggedInUserType.isAdmin) {
if (regkey != null && student != null) {
// TODO: encrypt the email as currently anyone with the regkey can
// get the email because of this redirect:
String joinUrl = Config.getAppUrl(student.getRegistrationUrl()).withParam(Const.ParamsNames.NEXT_URL, requestUrl).toString();
setRedirectPage(joinUrl);
return null;
}
throw new UnauthorizedAccessException("Unregistered user for a page that needs registration");
}
boolean isUserLoggedIn = account.googleId != null;
if (isPageNotCourseJoinRelated() && doesRegkeyBelongToUnregisteredStudent() && isUserLoggedIn) {
String redirectUrl = Config.getAppUrl(student.getRegistrationUrl()).withParam(Const.ParamsNames.NEXT_URL, requestUrl).toString();
setRedirectPage(redirectUrl);
return null;
}
return account;
}
use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class Action method authenticateNotLoggedInUser.
protected AccountAttributes authenticateNotLoggedInUser(String email, String courseId) {
student = logic.getStudentForRegistrationKey(regkey);
boolean isUnknownKey = student == null;
boolean isARegisteredUser = !isUnknownKey && student.googleId != null && !student.googleId.isEmpty();
boolean isMissingAdditionalAuthenticationInfo = email == null || courseId == null;
boolean isAuthenticationFailure = !isUnknownKey && (!student.email.equals(email) || !student.course.equals(courseId));
AccountAttributes loggedInUser = null;
if (isUnknownKey) {
throw new UnauthorizedAccessException("Unknown Registration Key " + regkey);
} else if (isARegisteredUser) {
setRedirectPage(gateKeeper.getLoginUrl(requestUrl));
return null;
} else if (isNotLegacyLink() && isMissingAdditionalAuthenticationInfo) {
throw new UnauthorizedAccessException("Insufficient information to authenticate user");
} else if (isNotLegacyLink() && isAuthenticationFailure) {
throw new UnauthorizedAccessException("Invalid email/course for given Registration Key");
} else {
// Unregistered and not logged in access given to page
loggedInUser = AccountAttributes.builder().withEmail(student.email).build();
}
return loggedInUser;
}
use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class AdminAccountDetailsPageAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
String googleId = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_ID);
AccountAttributes accountInformation = logic.getAccount(googleId);
List<CourseDetailsBundle> instructorCourseList;
try {
instructorCourseList = new ArrayList<>(logic.getCourseSummariesForInstructor(googleId).values());
} catch (EntityDoesNotExistException e) {
// Not an instructor of any course
instructorCourseList = null;
}
List<CourseAttributes> studentCourseList;
try {
studentCourseList = logic.getCoursesForStudentAccount(googleId);
} catch (EntityDoesNotExistException e) {
// Not a student of any course
studentCourseList = null;
}
AdminAccountDetailsPageData data = new AdminAccountDetailsPageData(account, sessionToken, accountInformation, instructorCourseList, studentCourseList);
statusToAdmin = "adminAccountDetails Page Load<br>" + "Viewing details for " + data.getAccountInformation().name + "(" + googleId + ")";
return createShowPageResult(Const.ViewURIs.ADMIN_ACCOUNT_DETAILS, data);
}
use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class AdminAccountManagementPageAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
String instructorGoogleId = this.getRequestParamValue("googleId");
if (instructorGoogleId == null) {
instructorGoogleId = "";
}
Map<String, ArrayList<InstructorAttributes>> instructorCoursesTable = new HashMap<>();
Map<String, AccountAttributes> instructorAccountsTable = new HashMap<>();
List<InstructorAttributes> instructorsList = logic.getInstructorsForGoogleId(instructorGoogleId);
AccountAttributes instructorAccount = logic.getAccount(instructorGoogleId);
boolean isToShowAll = this.getRequestParamAsBoolean("all");
boolean isAccountExisting = instructorAccount != null;
if (isAccountExisting) {
instructorAccountsTable.put(instructorAccount.googleId, instructorAccount);
for (InstructorAttributes instructor : instructorsList) {
ArrayList<InstructorAttributes> courseList = instructorCoursesTable.get(instructor.googleId);
if (courseList == null) {
courseList = new ArrayList<>();
instructorCoursesTable.put(instructor.googleId, courseList);
}
courseList.add(instructor);
}
}
AdminAccountManagementPageData data = new AdminAccountManagementPageData(account, sessionToken, instructorAccountsTable, instructorCoursesTable, isToShowAll);
statusToAdmin = "Admin Account Management Page Load<br>" + "<span class=\"bold\">Total Instructors:</span> " + instructorAccountsTable.size();
return createShowPageResult(Const.ViewURIs.ADMIN_ACCOUNT_MANAGEMENT, data);
}
use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class AccountsDb method createEntitiesDeferred.
@Override
public List<Account> createEntitiesDeferred(Collection<AccountAttributes> accountsToAdd) throws InvalidParametersException {
List<StudentProfileAttributes> profilesToAdd = new LinkedList<>();
for (AccountAttributes accountToAdd : accountsToAdd) {
profilesToAdd.add(accountToAdd.studentProfile);
}
profilesDb.createEntitiesDeferred(profilesToAdd);
return super.createEntitiesDeferred(accountsToAdd);
}
Aggregations